mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
Add check for all zero moments. If one of the shapes is empty, the match would return zero distance between the shapes even when the other one had content. It now returns DBL_MAX if no moments had value.
This commit is contained in:
parent
9be630466f
commit
d33d37ffd9
@ -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 anyResults = false;
|
||||
|
||||
HuMoments( moments(contour1), ma );
|
||||
HuMoments( moments(contour2), mb );
|
||||
@ -80,6 +81,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
ama = 1. / (sma * log10( ama ));
|
||||
amb = 1. / (smb * log10( amb ));
|
||||
result += fabs( -ama + amb );
|
||||
anyResults = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -108,6 +110,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
ama = sma * log10( ama );
|
||||
amb = smb * log10( amb );
|
||||
result += fabs( -ama + amb );
|
||||
anyResults = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -138,6 +141,7 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
mmm = fabs( (ama - amb) / ama );
|
||||
if( result < mmm )
|
||||
result = mmm;
|
||||
anyResults = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -145,6 +149,9 @@ double cv::matchShapes(InputArray contour1, InputArray contour2, int method, dou
|
||||
CV_Error( CV_StsBadArg, "Unknown comparison method" );
|
||||
}
|
||||
|
||||
if (!anyResults)
|
||||
result = DBL_MAX;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user