gpt4 book ai didi

Java openCV - 使用 Imgproc.matchTemplate 方法后,如何检查结果?

转载 作者:搜寻专家 更新时间:2023-10-31 08:28:45 25 4
gpt4 key购买 nike

我正在打电话:

Imgproc.matchTemplate(image, templ, result, 0);

并且匹配的结果在一个 Mat 实例中。我找不到此类的任何文档。如果我理解正确,结果包含一个概率矩阵。我怎样才能找到概率的最大值?我什至无法理解 Mat 实例的外观及其包含的内容。

谢谢埃亚尔

最佳答案

莉娜.png:

enter image description here

图案.png:

enter image description here

class MatchingDemo {
public void run(String inFile, String templateFile, String outFile,
int match_method) {
System.out.println("\nRunning Template Matching");

Mat img = Highgui.imread(inFile);
Mat templ = Highgui.imread(templateFile);

// / Create the result matrix
int result_cols = img.cols() - templ.cols() + 1;
int result_rows = img.rows() - templ.rows() + 1;
Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);

// / Do the Matching and Normalize
Imgproc.matchTemplate(img, templ, result, match_method);
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
Highgui.imwrite("out2.png", result);

// / Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(result);

Point matchLoc;
if (match_method == Imgproc.TM_SQDIFF
|| match_method == Imgproc.TM_SQDIFF_NORMED) {
matchLoc = mmr.minLoc;
System.out.println(mmr.minVal);
} else {
matchLoc = mmr.maxLoc;
System.out.println(mmr.maxVal);
}

// / Show me what you got
Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
matchLoc.y + templ.rows()), new Scalar(0, 255, 0));

// Save the visualized detection.
System.out.println("Writing " + outFile);
Highgui.imwrite(outFile, img);

}
}

public class TemplateMatching {
public static void main(String[] args) {
System.loadLibrary("opencv_java249");
new MatchingDemo().run("lena.png", "pattern.png", "output.png", Imgproc.TM_CCOEFF);
}
}

关于Java openCV - 使用 Imgproc.matchTemplate 方法后,如何检查结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9666998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com