replaced KeyPoint::overlap implementation by faster version (thanks to Suat Gedikli)

pull/13383/head
Maria Dimashova 15 years ago
parent 8f8aba9c88
commit 5e84ab0222
  1. 61
      modules/features2d/src/keypoint.cpp

@ -111,48 +111,41 @@ void KeyPoint::convert( const std::vector<Point2f>& points2f, std::vector<KeyPoi
float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 ) float KeyPoint::overlap( const KeyPoint& kp1, const KeyPoint& kp2 )
{ {
const int seedsPerDim = 50; float a = kp1.size * 0.5f;
float b = kp2.size * 0.5f;
float a_2 = a * a;
float b_2 = b * b;
float radius1 = kp1.size/2; Point2f p1 = kp1.pt;
float radius2 = kp2.size/2; Point2f p2 = kp2.pt;
float radius1_2 = radius1*radius1, float c = norm( p1 - p2 );
radius2_2 = radius2*radius2;
Point2f p1 = kp1.pt, p2 = kp2.pt;
float dist = norm(p1-p2);
float ovrl = 0.f; float ovrl = 0.f;
if( dist < radius1+radius2 ) // circles are intersected
{
float minx = min( p1.x - radius1, p2.x - radius2 );
float maxx = max( p1.x + radius1, p2.x + radius2 );
float miny = min( p1.y - radius1, p2.y - radius2 );
float maxy = max( p1.y + radius1, p2.y + radius2 );
float mina = (maxx-minx) < (maxy-miny) ? (maxx-minx) : (maxy-miny); // one circle is completely encovered by the other => no intersection points!
float step = mina/seedsPerDim; if( min( a, b ) + c <= max( a, b ) )
float bua = 0, bna = 0; return min( a_2, b_2 ) / max( a_2, b_2 );
//compute the areas if( c < a + b ) // circles intersect
for( float x = minx; x <= maxx; x+=step )
{ {
for( float y = miny; y <= maxy; y+=step ) float c_2 = c * c;
{ float cosAlpha = ( b_2 + c_2 - a_2 ) / ( kp2.size * c );
float rx1 = x-p1.x; float cosBeta = ( a_2 + c_2 - b_2 ) / ( kp1.size * c );
float ry1 = y-p1.y; float alpha = acos( cosAlpha );
float rx2 = x-p2.x; float beta = acos( cosBeta );
float ry2 = y-p2.y; float sinAlpha = sin(alpha);
float sinBeta = sin(beta);
//substitution in the equation of a circle float segmentAreaA = a_2 * beta;
float c1 = rx1*rx1+ry1*ry1; float segmentAreaB = b_2 * alpha;
float c2 = rx2*rx2+ry2*ry2;
if( c1<radius1_2 && c2<radius2_2 ) bna++; float triangleAreaA = a_2 * sinBeta * cosBeta;
if( c1<radius1_2 || c2<radius2_2 ) bua++; float triangleAreaB = b_2 * sinAlpha * cosAlpha;
}
} float intersectionArea = segmentAreaA + segmentAreaB - triangleAreaA - triangleAreaB;
if( bna > 0) float unionArea = (a_2 + b_2) * M_PI - intersectionArea;
ovrl = bna/bua;
ovrl = intersectionArea / unionArea;
} }
return ovrl; return ovrl;

Loading…
Cancel
Save