【问题标题】:image comparison in Android by OpenCVOpenCV在Android中的图像比较
【发布时间】:2016-09-19 06:21:26
【问题描述】:

我设计了一些用于图像比较的代码。匹配的部分仍然有点缺陷,我希望得到一些帮助。该项目可以在 -Github 找到。

我有这两张图片 img1 和 img2 。

这些是同一个人的图像。当我想比较这两个图像时,以下代码返回 false。

bmpimg1 = Bitmap.createScaledBitmap(bmpimg1, 100, 100, true);
                    bmpimg2 = Bitmap.createScaledBitmap(bmpimg2, 100, 100, true);
                    Mat img1 = new Mat();
                    Utils.bitmapToMat(bmpimg1, img1);
                    Mat img2 = new Mat();
                    Utils.bitmapToMat(bmpimg2, img2);
                    Imgproc.cvtColor(img1, img1, Imgproc.COLOR_RGBA2GRAY); 
                    Imgproc.cvtColor(img2, img2, Imgproc.COLOR_RGBA2GRAY); 
                    img1.convertTo(img1, CvType.CV_32F);
                    img2.convertTo(img2, CvType.CV_32F);
                    //Log.d("ImageComparator", "img1:"+img1.rows()+"x"+img1.cols()+" img2:"+img2.rows()+"x"+img2.cols());
                    Mat hist1 = new Mat();
                    Mat hist2 = new Mat();
                    MatOfInt histSize = new MatOfInt(180);
                    MatOfInt channels = new MatOfInt(0);
                    ArrayList<Mat> bgr_planes1= new ArrayList<Mat>();
                    ArrayList<Mat> bgr_planes2= new ArrayList<Mat>();
                    Core.split(img1, bgr_planes1);
                    Core.split(img2, bgr_planes2);
                    MatOfFloat histRanges = new MatOfFloat (0f, 180f);              
                    boolean accumulate = false;
                    Imgproc.calcHist(bgr_planes1, channels, new Mat(), hist1, histSize, histRanges, accumulate);
                    Core.normalize(hist1, hist1, 0, hist1.rows(), Core.NORM_MINMAX, -1, new Mat());
                    Imgproc.calcHist(bgr_planes2, channels, new Mat(), hist2, histSize, histRanges, accumulate);
                    Core.normalize(hist2, hist2, 0, hist2.rows(), Core.NORM_MINMAX, -1, new Mat());
                        img1.convertTo(img1, CvType.CV_32F);
                        img2.convertTo(img2, CvType.CV_32F);
                        hist1.convertTo(hist1, CvType.CV_32F);
                        hist2.convertTo(hist2, CvType.CV_32F);

                        double compare = Imgproc.compareHist(hist1, hist2, Imgproc.CV_COMP_CHISQR);
                        Log.d("ImageComparator", "compare: "+compare);
                        if(compare>0 && compare<1500) {
                            Toast.makeText(MainActivity.this, "Images may be possible duplicates, verifying", Toast.LENGTH_LONG).show();
                            new asyncTask(MainActivity.this).execute();
                        }
                        else if(compare==0)
                            Toast.makeText(MainActivity.this, "Images are exact duplicates", Toast.LENGTH_LONG).show();
                        else
                            Toast.makeText(MainActivity.this, "Images are not duplicates", Toast.LENGTH_LONG).show();

                    startTime = System.currentTimeMillis();

如何更改我的代码,以便在比较这两个图像时返回 true ?任何建议都有很大帮助。

【问题讨论】:

    标签: android opencv


    【解决方案1】:

    您似乎只比较有限的feature vectors,在这种情况下它只是图像的直方图。 您使用的算法不适合面部识别,因为它只在图像色谱上进行识别。

    请参阅this 可能的重复项,了解如何执行面部识别。

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多