Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Many times about. See this and this for more information.

Short answer:

  1. using TM_CCOEFF_NORMED result will be between 0..1 (1=perfect match)
  2. remove normalize(result, result, 0, ... otherwise you will see always a perfect match
  3. use a threshold on matching result to accept or reject the matching. You could start with 0.9

Many times about. See this and this for more information.

Short answer:

  1. using TM_CCOEFF_NORMED result will be between 0..1 (1=perfect match)
  2. remove normalize(result, result, 0, ... otherwise you will see always a perfect match
  3. use a threshold on matching result to accept or reject the matching. You could start with 0.9

EDIT as requested...

matchTemplate result is an image map. result(x,y) is the result of matching formula calculated in (x,y)... is a score, a matching quality indicator for the point!

minMaxLoc is needed to get the value and the location for the highest score, so you have maxValue and maxLoc. But highest score means the highest of the scores you got for your image, it could be the least worst.

Using normalize(result, result, 0, 1,... you will lost information about the quality without counterpart. normalize is useless here!! (use it just for imshow!!!!)

Question 1) is your highest score good enough to accept the matching ? Answer: If it's too low means that matching quality is poor!?!? Question 2) how to define too low ?

Using non _NORMED version (like is TM_CCOEFF) you don't know the value for perfect match than you can't set numeric value for too low. You can use some empiric value valid just for a given image and a given template.

Using _NORMED version (like TM_CCOEFF_NORMED) you know that perfect match is 1.0. If your maxValue is 0.99 you had almost a perfect match. If it's 0.9 you had a good match, if 0.7 may be you had a mismatch !

at the end you can write:

Imgproc.matchTemplate(image, template, result, TM_CCOEFF_NORMED);
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
double minMatchQuality = 0.9 // with CV_TM_SQDIFF_NORMED you could use 0.1
if mmr.maxValue > minMatchQuality // with CV_TM_SQDIFF_NORMED use maxValue < minMatchQuality
  accept the match
else
  rejecty the match

Many times about. See this and this for more information.

Short answer:

  1. using TM_CCOEFF_NORMED result will be between 0..1 (1=perfect match)
  2. remove normalize(result, result, 0, ... otherwise you will see always a perfect match
  3. use a threshold on matching result to accept or reject the matching. You could start with 0.9

EDIT as requested...

matchTemplate result is an image map. result(x,y) is the result of matching formula calculated in (x,y)... is a score, a matching quality indicator for the point!

minMaxLoc is needed to get the value and the location for the highest score, so you have maxValue and maxLoc. But highest score means the highest of the scores you got for your image, it could be the least worst.

Using normalize(result, result, 0, 1,... you will lost information about the quality without counterpart. normalize is useless here!! (use it just for imshow!!!!)

Question 1) is your highest score good enough to accept the matching ? Answer: If it's too low means that matching quality is poor!?!? Question 2) how to define too low ?

Using non _NORMED version (like is TM_CCOEFF) you don't know the value for perfect match than you can't set numeric value for too low. You can use some empiric value valid just for a given image and a given template.

Using _NORMED version (like TM_CCOEFF_NORMED) you know that perfect match is 1.0. If your maxValue is 0.99 you had almost a perfect match. If it's 0.9 you had a good match, if 0.7 may be you had a mismatch !

at the end you can write:

Imgproc.matchTemplate(image, template, result, TM_CCOEFF_NORMED);
Core.MinMaxLocResult mmr = Core.minMaxLoc(result);
double minMatchQuality = 0.9 // with CV_TM_SQDIFF_NORMED you could use 0.1
if mmr.maxValue > minMatchQuality // with CV_TM_SQDIFF_NORMED use maxValue minValue < minMatchQuality
  accept the match
else
  rejecty the match