简体   繁体   English

使用openCv和Java进行图像处理的排名算法

[英]Ranking algorithm for image processing using openCv and java

The below Algorithm returns image comparison percentage using openCv Java. 下面的算法使用openCv Java返回图像比较百分比。

private double compare(Mat hist1, String f2) {
        double compare = 0;

        ArrayList<Mat> bgr_planes2 = new ArrayList<Mat>();
        boolean accumulate = false;
        MatOfInt histSize = new MatOfInt(180);
        MatOfInt channels = new MatOfInt(0);
        MatOfFloat histRanges = new MatOfFloat(0f, 180f);

        // Mat img2 = Imgcodecs.imread(f2);
        // img2 = resize(img2);

        Mat img2 = ContourUtils.findContour(f2, false);

        Imgproc.cvtColor(img2, img2, Imgproc.COLOR_RGBA2GRAY);
        img2.convertTo(img2, CvType.CV_32F);
        Mat hist2 = new Mat();
        Core.split(img2, bgr_planes2);
        Imgproc.calcHist(bgr_planes2, channels, new Mat(), hist2, histSize,
                histRanges, accumulate);
        Core.normalize(hist2, hist2, 0, hist2.rows(), Core.NORM_MINMAX, -1,
                new Mat());
        // img2.convertTo(img2, CvType.CV_32F);
        hist2.convertTo(hist2, CvType.CV_32F);

        compare = Imgproc.compareHist(hist1, hist2, Imgproc.CV_COMP_CORREL);
        img2.release();
        hist2.release();
        channels.release();
        histRanges.release();
        histSize.release();

        for (Mat m : bgr_planes2) {
            if (m != null) {
                m.release();
            }
        }

        return compare;
    }

Same way i want to find the ranking instead of percentage that how well the images are matched. 我想以同样的方式查找排名,而不是找到图像匹配程度的百分比。 Please suggest me an idea for ranking algorithm. 请给我建议一个排序算法的想法。 Thanks. 谢谢。

I understand that your algorithm is comparing an image to a reference image. 我了解您的算法会将图片与参考图片进行比较。 If you want a ranking of the best math, apply the function to your collection of input image, then sorting the results (descending order) provide you the ranking. 如果要对最佳数学进行排名,请将函数应用于输入图像的集合,然后对结果进行排序(降序)即可获得排名。

Store the result as key and the list of names of input image (expecting many inputs could have the same result value) as value of a Map. 将结果存储为键,并将输入图像的名称列表(期望许多输入可能具有相同的结果值)存储为Map的值。 For example: 例如:

Map<double, List<String>> ranking 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM