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

Java openCV-使用Imgproc.matchTemplate方法后,如何检查结果?,java,image-processing,opencv,template-matching,Java,Image Processing,Opencv,Template Matching,我打电话: Imgproc.matchTemplate(image, templ, result, 0); 匹配的结果在Mat实例中。 我找不到此类的任何文档。 如果我理解正确,结果包含一个概率矩阵。 我怎样才能找到概率的最大值?我甚至无法理解Mat实例的外观以及它包含的内容 谢谢 Eyal为了测试结果,应该使用位于类核心内部的函数minMaxLoc。 该方法返回MinMaxLocResult的实例,其中包含许多选项。lena.png: pattern.png: class Matching

我打电话:

Imgproc.matchTemplate(image, templ, result, 0);
匹配的结果在Mat实例中。 我找不到此类的任何文档。 如果我理解正确,结果包含一个概率矩阵。 我怎样才能找到概率的最大值?我甚至无法理解Mat实例的外观以及它包含的内容

谢谢
Eyal

为了测试结果,应该使用位于类核心内部的函数minMaxLoc。 该方法返回MinMaxLocResult的实例,其中包含许多选项。

lena.png:

pattern.png:

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);
    }
}


我想这就是你要找的文件:。这里是一些C++的示例代码:。是的,我看过这个文档,我只是想知道如何在结果中找到最大值(这是一个Mat实例)。快速找到最大值的方法是使用cv::minMaxLoc函数,我相信您可以找到JAVA等效函数。即使找不到搜索最大值的Java函数,编写一个查找最大值的函数也没什么大不了的。