首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Java OPENCV模板匹配给出了错误的坐标?

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

Stack Overflow用户
提问于 2019-05-21 18:34:27
回答 1查看 215关注 0票数 0

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

主映像

子图像

结果

正如你在第三张图片中看到的,算法找到了正确的匹配。我还写了一个打印x,y来查看匹配的坐标,这给出了下面的坐标: 330,1006。X的值是正确的,但是y的值是不正确的?这怎麽可能?

模板匹配方法代码:

代码语言:javascript
运行
复制
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.");
}
EN

Stack Overflow用户

回答已采纳

发布于 2019-05-21 19:09:56

Y坐标是正确的,它是从屏幕顶部开始计算的。

在fullHD上,左上角是(0,0),右下角是(1920,1080

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56236412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档