minMaxLoc() always returns values even template doesn't exist in image

asked 2017-07-28 07:03:32 -0600

CVLearner17 gravatar image
matchTemplate(Image, Template, ResImage, CV_TM_CCOEFF);
double Min, Max;
Point MinLoc, MaxLoc;
minMaxLoc(ResImage, &Min, &Max, &MinLoc, &MaxLoc, Mat());

minMaxLoc() always returns values even "Template" doesn't exist in "Image".
How do we know if it really exists or not?

The documentation says that if CV_TM_CCOEFF is used, the best match is MaxLoc.
But MaxLoc always contains values.

edit retag flag offensive close merge delete

Comments

1

minMaxLoc return min and max location and minum and maximum. It always exists

LBerger gravatar imageLBerger ( 2017-07-28 07:21:16 -0600 )edit

you'll have to find an experimental threshold value, e.g. if Max < 0.6 - it did not find it.

berak gravatar imageberak ( 2017-07-28 07:55:18 -0600 )edit

You should use TM_CCOEFF_NORMED

LBerger gravatar imageLBerger ( 2017-07-28 08:19:21 -0600 )edit

@LBerger, be careful with that suggestion. By using normalized output, even matches with very low scores wil be stretched over the whole 0-1 spectrum. This will screw up matches in my opinion. I always prefer looking for a threshold value for your specific case :)

StevenPuttemans gravatar imageStevenPuttemans ( 2017-07-29 08:04:52 -0600 )edit
1

@StevenPuttemans I'm not so sure. _NORMED versions normalize result respect to lightness and template size. This is completely different from range normalization such as normalize() that for sure screw up matches. I'm wrong ?

pklab gravatar imagepklab ( 2017-07-30 02:12:22 -0600 )edit

yesI'm agree with @pklab see statistics

LBerger gravatar imageLBerger ( 2017-07-30 02:44:51 -0600 )edit

you proved me wrong :D

StevenPuttemans gravatar imageStevenPuttemans ( 2017-07-31 08:12:24 -0600 )edit
1

@StevenPuttemans you are so perfect that I was thinking I lost something :-)

pklab gravatar imagepklab ( 2017-07-31 10:47:24 -0600 )edit