mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Add case including both moments empty.
This commit is contained in:
parent
d33d37ffd9
commit
7cc0b0f93e
@ -50,7 +50,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
double eps = 1.e-5;
|
double eps = 1.e-5;
|
||||||
double mmm;
|
double mmm;
|
||||||
double result = 0;
|
double result = 0;
|
||||||
bool anyResults = false;
|
bool anyA = false, anyB = false;
|
||||||
|
|
||||||
HuMoments( moments(contour1), ma );
|
HuMoments( moments(contour1), ma );
|
||||||
HuMoments( moments(contour2), mb );
|
HuMoments( moments(contour2), mb );
|
||||||
@ -63,6 +63,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
double ama = fabs( ma[i] );
|
double ama = fabs( ma[i] );
|
||||||
double amb = fabs( mb[i] );
|
double amb = fabs( mb[i] );
|
||||||
|
|
||||||
|
if (ama > 0)
|
||||||
|
anyA = true;
|
||||||
|
if (amb > 0)
|
||||||
|
anyB = true;
|
||||||
|
|
||||||
if( ma[i] > 0 )
|
if( ma[i] > 0 )
|
||||||
sma = 1;
|
sma = 1;
|
||||||
else if( ma[i] < 0 )
|
else if( ma[i] < 0 )
|
||||||
@ -81,7 +86,6 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
ama = 1. / (sma * log10( ama ));
|
ama = 1. / (sma * log10( ama ));
|
||||||
amb = 1. / (smb * log10( amb ));
|
amb = 1. / (smb * log10( amb ));
|
||||||
result += fabs( -ama + amb );
|
result += fabs( -ama + amb );
|
||||||
anyResults = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -92,6 +96,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
double ama = fabs( ma[i] );
|
double ama = fabs( ma[i] );
|
||||||
double amb = fabs( mb[i] );
|
double amb = fabs( mb[i] );
|
||||||
|
|
||||||
|
if (ama > 0)
|
||||||
|
anyA = true;
|
||||||
|
if (amb > 0)
|
||||||
|
anyB = true;
|
||||||
|
|
||||||
if( ma[i] > 0 )
|
if( ma[i] > 0 )
|
||||||
sma = 1;
|
sma = 1;
|
||||||
else if( ma[i] < 0 )
|
else if( ma[i] < 0 )
|
||||||
@ -110,7 +119,6 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
ama = sma * log10( ama );
|
ama = sma * log10( ama );
|
||||||
amb = smb * log10( amb );
|
amb = smb * log10( amb );
|
||||||
result += fabs( -ama + amb );
|
result += fabs( -ama + amb );
|
||||||
anyResults = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -121,6 +129,11 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
double ama = fabs( ma[i] );
|
double ama = fabs( ma[i] );
|
||||||
double amb = fabs( mb[i] );
|
double amb = fabs( mb[i] );
|
||||||
|
|
||||||
|
if (ama > 0)
|
||||||
|
anyA = true;
|
||||||
|
if (amb > 0)
|
||||||
|
anyB = true;
|
||||||
|
|
||||||
if( ma[i] > 0 )
|
if( ma[i] > 0 )
|
||||||
sma = 1;
|
sma = 1;
|
||||||
else if( ma[i] < 0 )
|
else if( ma[i] < 0 )
|
||||||
@ -141,7 +154,6 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
mmm = fabs( (ama - amb) / ama );
|
mmm = fabs( (ama - amb) / ama );
|
||||||
if( result < mmm )
|
if( result < mmm )
|
||||||
result = mmm;
|
result = mmm;
|
||||||
anyResults = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -149,7 +161,10 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
|||||||
CV_Error( CV_StsBadArg, "Unknown comparison method" );
|
CV_Error( CV_StsBadArg, "Unknown comparison method" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!anyResults)
|
//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;
|
result = DBL_MAX;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user