找到两个手势图像OpenCv的相似性

时间:2018-04-15 07:06:28

标签: java android image-processing opencv4android

我正在为Handy People开发Sign Translator应用程序。在我的应用程序中,用户将从相机或图库中提供一个符号图像,将与数据库图像进行比较,并使用字母符号显示结果。

但我的问题是我在两张图片之间没有得到很好的相似性。某些时间结果是准确的,有些时候没有。 请参考我的一些想法或源代码。 提前谢谢。

 Scalar lowerThreshold =  new Scalar(0, 48, 80); // Blue color – lower hsv values
    Scalar upperThreshold = new Scalar(20, 255, 255); // Blue color – higher hsv values

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.PYRAMID_FAST);
    DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);

    //orb orb bruteforce with filter method
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    //crash on surf flanbased


    Mat img1 = new Mat();
    Mat img2 = new Mat();


    Utils.bitmapToMat(defaultImage,img1);
    Utils.bitmapToMat(databaseImage,img2);



    Mat descriptors1 = new Mat();
    MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
    detector.detect(img1, keypoints1);
    extractor.compute(img1, keypoints1, descriptors1);


    //second image

    Mat descriptors2 = new Mat();
    MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
    detector.detect(img2, keypoints2);
    extractor.compute(img2, keypoints2, descriptors2);


    //matcher image descriptors
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors1,descriptors2,matches);

    //Filter matches by distance
    MatOfDMatch filtered = filterMatchesByDistance(matches);

    int total = (int) matches.size().height;
    int Match= (int) filtered.size().height;
    Log.d("LOG", "total:" + total + " Match:"+Match);

    int percent = (int)((Match * 100.0f) / total);
    if(percent>max){
        max=percent;
        maximumPercentage.setMaximum(percent);
        maximumPercentage.setImageId(id);
        imageId=id;
        Log.d("Maximum Percentage: ",String.valueOf(max)+"%");
        Log.d("MaxId: ",String.valueOf(imageId));
    }
    id++;
    Log.d("matchingOImages: ",String.valueOf(percent)+"%");

过滤器匹配结果方法

 List<DMatch> matches_original = matches.toList();
    List<DMatch> matches_filtered = new ArrayList<DMatch>();

    int DIST_LIMIT = 30;
    // Check all the matches distance and if it passes add to list of filtered matches
    Log.d("DISTFILTER", "ORG SIZE:" + matches_original.size() + "");
    for (int i = 0; i < matches_original.size(); i++) {
        DMatch d = matches_original.get(i);
        if (Math.abs(d.distance) <= DIST_LIMIT) {
            matches_filtered.add(d);
        }
    }
    Log.d("DISTFILTER", "FIL SIZE:" + matches_filtered.size() + "");

    MatOfDMatch mat = new MatOfDMatch();
    mat.fromList(matches_filtered);
    return mat;

1 个答案:

答案 0 :(得分:0)

好吧,我想你刚刚进入神经网络的现代时代。 由于这些东西的工作原理可能很难,并且经常需要多年的学习,因此可以通过一些捷径来完成工作。

为了获得最快的结果,我想你可以从这里开始:  (假设你不想深入研究神经网络的内部工作,而是使用现有的软件或服务)https://cloud.google.com/automl/