mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
Merge pull request #7966 from Tetragramm:Issue#4235
This commit is contained in:
commit
10e639cdb9
@ -50,6 +50,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
double eps = 1.e-5;
|
||||
double mmm;
|
||||
double result = 0;
|
||||
bool anyA = false, anyB = false;
|
||||
|
||||
HuMoments( moments(contour1), ma );
|
||||
HuMoments( moments(contour2), mb );
|
||||
@ -62,6 +63,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
double ama = fabs( ma[i] );
|
||||
double amb = fabs( mb[i] );
|
||||
|
||||
if (ama > 0)
|
||||
anyA = true;
|
||||
if (amb > 0)
|
||||
anyB = true;
|
||||
|
||||
if( ma[i] > 0 )
|
||||
sma = 1;
|
||||
else if( ma[i] < 0 )
|
||||
@ -90,6 +96,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
double ama = fabs( ma[i] );
|
||||
double amb = fabs( mb[i] );
|
||||
|
||||
if (ama > 0)
|
||||
anyA = true;
|
||||
if (amb > 0)
|
||||
anyB = true;
|
||||
|
||||
if( ma[i] > 0 )
|
||||
sma = 1;
|
||||
else if( ma[i] < 0 )
|
||||
@ -118,6 +129,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
double ama = fabs( ma[i] );
|
||||
double amb = fabs( mb[i] );
|
||||
|
||||
if (ama > 0)
|
||||
anyA = true;
|
||||
if (amb > 0)
|
||||
anyB = true;
|
||||
|
||||
if( ma[i] > 0 )
|
||||
sma = 1;
|
||||
else if( ma[i] < 0 )
|
||||
@ -145,6 +161,12 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
CV_Error( CV_StsBadArg, "Unknown comparison method" );
|
||||
}
|
||||
|
||||
//If anyA and anyB are both true, the result is correct.
|
||||
//If anyA and anyB are both false, the distance is 0, perfect match.
|
||||
//If only one is true, then it's a false 0 and return large error.
|
||||
if (anyA != anyB)
|
||||
result = DBL_MAX;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user