簡體   English   中英

Java OPENCV模板匹配給出錯誤的坐標?

[英]Java OPENCV Template Matching gives wrong coordinates?

所以我基本上使用Opencv模板匹配,它在主圖像中找到正確的匹配,但匹配的給定坐標是錯誤的。

mainimage

mainimage

子圖像

子圖像

結果

結果

正如您在第三張圖片中看到的那樣,該算法找到了正確的匹配。 另外我寫了一個打印x,y來看比賽的坐標,這給了我以下的坐標:330,1006。x的值是正確的,但y的值是不對的? 這怎么可能?

模板匹配方法的代碼:

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.");
}

Y坐標是正確的,它是從屏幕頂部開始計算的。

全高清左上角是(0,0),右下角是(1920,1080)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM