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.