0

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

mainimage

subimage

subimage

result

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.");
}
luator
  • 4,769
  • 3
  • 30
  • 51
Gerrit
  • 29
  • 8

1 Answers1

1

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

J.D.
  • 4,511
  • 2
  • 7
  • 20
  • Well something is going wrong in that case, because I am using util.java.robot to click on the x, y coords and it clicks way under the match? It clicks on the right x but way under the right y coord? – Gerrit May 21 '19 at 11:14
  • I'm not sure, but possibly you need to account for the offset created by the window bar at the top - depending on the implementation of your robot. If not, you can open a new question concerning the robot not clicking on specified coordinates. – J.D. May 21 '19 at 11:24
  • thanks i found the solution, https://i.imgur.com/RcJXlia.jpg, i had this shit on 125% and now on 100% and works fine... – Gerrit May 21 '19 at 11:34