MatchTemplate and get matching score or confidence hint

asked 2019-10-20 06:12:20 -0500

essamzaky gravatar image

I read the matchtemplate tutorial in the documenation ,

when i try to find the confidence or matching score , it always return the confidence as 1 , i trace the sample code and found the reason is normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); after commenting the previous line the result is fine . so i think we may need to update the documentation and comment the previouse line of code

and here it's my code to get the score or confidence from matchtemplate

bool method_accepts_mask = (TM_SQDIFF == match_method || match_method == TM_CCORR_NORMED);
if (use_mask && method_accepts_mask)
    matchTemplate(img, templ, result, match_method, mask);
    matchTemplate(img, templ, result, match_method);
//normalize(result, result, 0, 1, NORM_MINMAX, -1, Mat());//new added check
double minVal; double maxVal; Point minLoc; Point maxLoc;
Point matchLoc;
minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, Mat());
double dConfidence;
if (match_method == TM_SQDIFF || match_method == TM_SQDIFF_NORMED)
    matchLoc = minLoc;
    dConfidence = 1 - minVal;
    matchLoc = maxLoc;
    dConfidence = maxVal;
edit retag flag offensive close merge delete



when normalize is uncommented i receive value of the dConfidence equal to 1 for all objects , but when comment normalize the value is returned correctly

essamzaky gravatar imageessamzaky ( 2019-10-20 06:33:37 -0500 )edit