所以基本上我使用Opencv模板匹配,它在主图像中找到正确的匹配,但给定的匹配坐标是错误的。
主映像
子图像
结果
正如你在第三张图片中看到的,算法找到了正确的匹配。我还写了一个打印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.");
}
发布于 2019-05-21 19:09:56
Y坐标是正确的,它是从屏幕顶部开始计算的。
在fullHD上,左上角是(0,0),右下角是(1920,1080
https://stackoverflow.com/questions/56236412
复制相似问题