so basically I am using Opencv Template Matching and it finds the correct match in the mainimage but the given coords of the match are wrong.
mainimage
subimage
result
As you can see in the third picture, the algorithm found the right match. Also i wrote a print x, y to see the coords of the match and this gives me the following coords: 330, 1006. The value of x is right but the value of y is not right? how is this possible?
Code of the template matching method:
public void FindImageInFOE() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat source = null;
Mat template = null;
String filePath = "C:\\Users\\Gerrit\\Desktop\\";
//Load image file
source = Imgcodecs.imread(filePath + "jpgbeeld.jpg");
template = Imgcodecs.imread(filePath + "jpghelpen.jpg");
Mat outputImage = new Mat();
int machMethod = Imgproc.TM_CCOEFF;
//Template matching method
Imgproc.matchTemplate(source, template, outputImage, machMethod);
Core.MinMaxLocResult mmr = Core.minMaxLoc(outputImage);
Point matchLoc = mmr.maxLoc;
//Draw rectangle on result image
Imgproc.rectangle(source, matchLoc, new Point(matchLoc.x + template.cols(),
matchLoc.y + template.rows()), new Scalar(255, 255, 255));
x = matchLoc.x;
y = matchLoc.y;
Imgcodecs.imwrite(filePath + "succes.png", source);
System.out.println("Complated.");
}
The Y coordinate is correct, it's counted from the top of the screen.
Top left is (0,0), bottom right is (1920,1080) on fullHD
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.