0

I would like to use an OpenCV function called matchTemplate to match a template picture with my current screen. My current screen and template picture are saved in files. I am using the code below to match my template with the screen:

Mat screen = imread("screen.bmp", IMREAD_COLOR);
Mat template = imread("template.png", IMREAD_COLOR);
int cols = screen.cols - template.cols + 1;
int rows = screen.rows - template.rows + 1;
Mat result(rows , cols , CV_8UC3);
matchTemplate(screen, template, result, TM_SQDIFF_NORMED);
double min;
minMaxLoc(result, &min, nullptr, nullptr);

It comes out that value of min is equaled to about 0.003 when the template really matches to the screen, but sometimes it is also equaled to about 0.0045 when template does not match to the screen (it happens when I use another picture with a similar screen).

I would like to get to know a solution which might be a special function that would check it more precisely. My template picture (template.png) is just a cropped picture of the main screen (screen.bmp), so the best one solution would be an OpenCV function that can match pixel by pixel, perchance with a small deviation. I would like to match it perfectly instead of finding a similarity.

Michal
  • 627
  • 3
  • 13

1 Answers1

0

From a tutorial page,

For the first two methods ( CV_SQDIFF and CV_SQDIFF_NORMED ) the best match are the lowest values. For all the others, higher values represent better matches.

This is also mentioned in their documentation.

Warpstar22
  • 567
  • 4
  • 19
  • So what value is the best for comparing pixel by pixel? – Michal May 16 '20 at 10:38
  • I'm not sure what you're asking. That's what template matching does. The resulting matrix is a matching score based on each pixel that was matched. – Warpstar22 May 17 '20 at 23:09