How can I get an absolute value that tells me how much the template matched in the place it matched the best? I know about minMaxLoc() but that only tells me what the biggest value is, but I have no idea what the MAXIMUM value is so that I can get some kind of idea about how good a match it is.
I've seen people saying that you can get a percentage using normalization, but that doesn't really help me since the biggest value will always be 100%. Am I missing something?
The OpenCV documentation describes the different formulas available for calculating the template match score at each xy offset position.
If you want an easy metric, use the normalized cross-correlation by passing CV_TM_CCORR_NORMED
, to matchTemplate
then make sure you don't do the often-used normalization on the result before calling minMaxLoc
. The maximum value will be one for a perfect match.
Don't be confused by the word "normalized" in "normalized cross-correlation", this refers to the normalization of brightness/contrast differences between the search image and the template, not to the resulting score.