Answer the question
In order to leave comments, you need to log in
How to compare 2 OpenCV images?
Hello.
Using Opencv, I find the coordinates of the picture in the screenshot.
Mat screen = Highgui.imread(image1, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
Mat image = Highgui.imread(image2, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
Mat result = new Mat(screen.cols()- image.cols() + 1, screen.rows()- screen.rows() + 1, CvType.CV_32FC1);
Imgproc.matchTemplate(screen, image, result, Imgproc.TM_SQDIFF_NORMED);
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
MinMaxLocResult mmr = Core.minMaxLoc(result);
Point matchLoc = mmr.minLoc;
Mat search_result = new Mat(screen, new Rect((int) matchLoc.x, (int) matchLoc.y, image.cols(), image.rows()));
Answer the question
In order to leave comments, you need to log in
Hello, I have a similar problem and question.
If you found the answer, I will be grateful for its description.
There is an image - a screenshot, and a small piece of this image, which must be found in the screenshot.
With the help of ROI, I limit the area where it is necessary to search, after that I use the same functions as you, but how to determine whether my pattern is found in this ROI or not? Especially if the area has different dimensions in relation to the template.
As far as I understand, it was also necessary to filter the comparison result above a certain threshold.
The result of matchTemplate must be placed in a variable and then filtered.Imgproc.matchTemplate(screen, image, result, Imgproc.TM_SQDIFF_NORMED);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question