This forum is disabled, please visit https://forum.opencv.org

1 | initial version |

Asking about different matching methods is a frequent question... I can integrate my old answer with this

- TM_SQDIFF is Sum of Square Difference (SSD). It's fast but results depend on overall intensity
- TM_CCORR (sometimes called Cross Correlation) is SSD under the circumstance that the sum of portion of the image under matching is constant when the template moves over the image or simply the image is almost constant. I look at this like worst method at all because it depends too much on overall intensity... you can have false detection also using a perfect template, if image has big variation in intensity.ref
- TM_CCOEFF (often called Normalized Cross Correlation) is correlation coefficient. It consider the mean of template and the mean of the image so that the matching is most robust to local variation ref. I think this is the best method. Downside: is slower.

All of above give results that can't be used for comparison because, matching value depends from image,template, size and intensity. If you want just to find where your template best matches over the image, you can used one of above (I think TM_CCOEFF has more sense)

If you want a good matching (to accept or discard the matching), you have to use the NORMED version of methods because they scale the result with image,template,size and intensity and provide output in a fixed range 0..1 where 1 means perfect matching (with SQDIFF 0 means perfect)

Be careful because **many examples uses to normalize (again)** the result of the matching. **If you do this you will see always a perfect matching** because of normalization on result !

2 | No.2 Revision |

Asking about different matching methods is a frequent question... I can integrate my old answer with ~~this~~

Before all, formulas in the doc explain exactly what happens for each pixel right. Here is an attempt to explicate them. All contributions are welcome.

- TM_SQDIFF is Sum of Square Difference (SSD). It's fast but results depend on overall intensity
- TM_CCORR (sometimes called Cross Correlation) is SSD under the circumstance that the sum of portion of the image under matching is constant when the template moves over the image or simply the image is almost constant. I look at this like worst method at all because it depends too much on overall intensity... you can have false detection also using a perfect template, if image has big variation in intensity.ref
- TM_CCOEFF (often called Normalized Cross Correlation) is correlation coefficient. It consider the mean of template and the mean of the image so that the matching is most robust to local variation ref. I think this is the best method. Downside: is slower.

All of above give results that can't be used for comparison because, matching value depends from image,template, size and intensity. If you want just to find where your template best matches over the image, you can used one of above (I think TM_CCOEFF has more sense)

If you want a good matching (to accept or discard the matching), you have to use the NORMED version of methods because they scale the result with image,template,size and intensity and provide output in a fixed range 0..1 where 1 means perfect matching (with SQDIFF 0 means perfect)

Be careful because **many examples uses to normalize (again)** the result of the matching. **If you do this you will see always a perfect matching** because of normalization on result !

3 | No.3 Revision |

Asking about different matching methods is a frequent question... I can integrate my old answer with this.

Before all, formulas in the doc explain exactly what happens for each pixel right. Here is an attempt to explicate them. All contributions are welcome.

- TM_SQDIFF is Sum of Square Difference (SSD). It's fast but results depend on overall intensity
- TM_CCORR (sometimes called Cross Correlation) is SSD under the circumstance that the sum of portion of the image under matching is constant when the template moves over the image or simply the image is almost constant. I look at this like worst method at all because it depends too much on overall intensity... you can have false detection also using a perfect template, if image has big variation in intensity.ref
- TM_CCOEFF (often called Normalized Cross Correlation) is correlation coefficient. It consider the mean of template and the mean of the image so that the matching is most robust to local variation ref. I think this is the best method. Downside: is slower.

All of above give results that can't be used for comparison because, matching value depends from image,template, size and intensity.
If you want just to find where your template best matches over the image, you can ~~used ~~use one of above (I think TM_CCOEFF has more sense)

If you want a good matching (to accept or discard the matching), you have to use the NORMED version of methods because they scale the result with image,template,size and intensity and provide output in a fixed range 0..1 where 1 means perfect matching (with SQDIFF 0 means perfect)

Be careful because **many examples uses to normalize (again)** the result of the matching. **If you do this you will see always a perfect matching** because of normalization on result !

4 | No.4 Revision |

Asking about different matching methods is a frequent question... I can integrate my old answer with this.

Before all, formulas in the doc explain exactly what happens for each pixel right. Here is an attempt to explicate them. All contributions are welcome.

- TM_SQDIFF is Sum of Square Difference (SSD). It's fast but results depend on overall intensity
- TM_CCOEFF (often called
~~Normalized~~Cross Correlation) is correlation coefficient. It consider the mean of template and the mean of the image so that the matching is most robust to local variation ref. I think this is the best method. Downside: is slower.

All of above give results that can't be used for comparison because, matching value depends from image,template, size and intensity. If you want just to find where your template best matches over the image, you can use one of above (I think TM_CCOEFF has more sense)

**many examples uses to normalize (again)** the result of the matching. **If you do this you will see always a perfect matching** because of normalization on result !

5 | No.5 Revision |

Asking about different matching methods is a frequent question... I can integrate my old answer with this.

~~TM_SQDIFF~~`TM_SQDIFF`

is Sum of Square Difference (SSD). It's fast but results depend on overall intensity~~TM_CCORR~~`TM_CCORR`

(sometimes called Cross Correlation) is SSD under the circumstance that the sum of portion of the image under matching is constant when the template moves over the image or simply the image is almost constant. I look at this like worst method at all because it depends too much on overall intensity... you can have false detection also using a perfect template, if image has big variation in intensity.ref~~TM_CCOEFF~~`TM_CCOEFF`

(often called Cross Correlation) is correlation coefficient. It consider the mean of template and the mean of the image so that the matching is most robust to local variation ref. I think this is the best method. Downside: is slower.

All of above give results that can't be used for comparison because, matching value depends from image,template, size and intensity. If you want just to find where your template best matches over the image, you can use one of above (I think TM_CCOEFF has more sense)

If you want a good matching (to accept or discard the matching), you have to use the ~~NORMED ~~`_NORMED`

version of methods because they scale the result with image,template,size and intensity and provide output in a fixed range 0..1 where 1 means perfect ~~matching ~~match (with SQDIFF 0 means ~~perfect) ~~perfect)

**many examples uses to normalize (again)** the result of the matching. **If you do this you will see always a perfect matching** because of normalization on result !

here some examples. Green rectangles show the best match found. As you can see non _NORMED methods give useless score.

Template has been brighten
Results show **bad false positive** for SQDIFF and CCORR both standard and normed. while COEFF_NORMED is ~1

Template with noise and brlur Again CCORR_NORMED has bad false positive with a score of 0.9. COEFF_NORMED is coherent with score 0.6

Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.