Java OPENCV 模板匹配给出错误的坐标?

标签 java opencv coordinates template-matching

所以基本上我使用 Opencv 模板匹配,它在主图像中找到正确的匹配,但给定的匹配坐标是错误的。

主图

mainimage

子图像

subimage

结果

result

正如您在第三张图片中看到的,算法找到了正确的匹配。我还写了一个 print 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)

关于Java OPENCV 模板匹配给出错误的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56236412/

相关文章:

mysql - 如何确定坐标是否在多边形内?

java - 如何用值声明一个 ArrayList?

opencv cmake 没有找到最新的 ffmpeg 库

python - 如何使用带有 NumPy 数组的矢量化来使用 Geopy 库为大型数据集计算测地线距离?

android - 旋转 Canvas 会影响 TouchEvents

python-2.7 - 使用 OpenCV 查找连通分量

java - 为什么 IntelliJ 告诉我在这种情况下引用不能为空?

java - 在 Android 中检查 SMS 中的多个关键字

java - Maven 中的 Jena schemagen 处理多个本体

opencv - 在 Windows7 上为 C/C++ 开发人员使用 Eclipse IDE 配置 OpenCV