Ask Your Question

Revision history [back]

Based on the [Template Matching] (http://docs.opencv.org/master/de/da9/tutorial_template_matching.html) tutorial in opencv doc, After template matching, you need to normalized the result mat between 0 and 1:

cv::normalize( res, res, 0, 1, cv::NORM_MINMAX, -1, cv::Mat() );

After normalization, you need to find the maximum value inside the res matrix. (Because cross correlation try to maximize the product (or cross-correlation) of the two aligned images and so the maximum value inside the res matrix is you answer). For this purpose you can apply cv::minMaxLoc function:

double minVal; double maxVal; Point minLoc; Point maxLoc;
Point matchLoc;
cv::minMaxLoc( res, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() );

The maxLoc and maxVal represent the location and the value of best match in the second image (imgJ).

Based on the [Template Matching] (http://docs.opencv.org/master/de/da9/tutorial_template_matching.html) Template Matching tutorial in opencv doc, After template matching, you need to normalized the result mat between 0 and 1:

cv::normalize( res, res, 0, 1, cv::NORM_MINMAX, -1, cv::Mat() );

After normalization, you need to find the maximum value inside the res matrix. (Because cross correlation try to maximize the product (or cross-correlation) of the two aligned images and so the maximum value inside the res matrix is you answer). For this purpose you can apply cv::minMaxLoc function:

double minVal; double maxVal; Point minLoc; Point maxLoc;
Point matchLoc;
cv::minMaxLoc( res, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() );

The maxLoc and maxVal represent the location and the value of best match in the second image (imgJ).