Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Template matching with the CV_TM_CCOEFF algorithm

I can't figure out the CV_TM_CCOEFF algorithm. (I get the CCORR & Least squares)

The O'Reilly book explains that "These methods match a template relative to its mean against the image relative to its mean, so a perfect match will be 1 and a perfect mismatch will be -1; a value of 0 simply means that there is no correlation". However, the equation given for CV_TM_CCOEFF doesn't subtract the mean from each pixel value but instead subtracts the reciprocal of the pixel value sum TIMES the number of pixels (shouldn't it be a division?). Plus, all the simple examples I work out on paper (with small, one dimensional signals) usually don't give me 1, 0, or -1. I also Googled Correlation Coefficient and found variations of this: Pearson Correlation Coefficient, which has all kinds of covariant and squared terms I can't reconcile with the OpenCV equation.