所以基本上我使用的是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.");
}
答案 0 :(得分:0)
Y坐标是正确的,它是从屏幕顶部算起的。
在FullHD上,左上角是(0,0),右下角是(1920,1080)