opencv中两个图像之间的相似度

时间:2015-04-27 22:52:06

标签: android opencv orb

我正在尝试计算两个图像之间的相似程度,但它每次都给我0。

这是我的代码:

public class  TemplateMatching{
static void analyze(Mat image, MatOfKeyPoint keypoints, Mat descriptors){
    detector.detect(image, keypoints);
    extractor.compute(image, keypoints, descriptors);
}
static FeatureDetector detector= FeatureDetector.create(FeatureDetector.ORB);
static DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);           
final static DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
static void ana(Mat image, MatOfKeyPoint keypoints, Mat descriptors){
    detector.detect(image, keypoints);
    extractor.compute(image, keypoints, descriptors);
}
static MatOfDMatch filterMatchesByDistance(MatOfDMatch matches){
    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;
}
public int  comparer(Mat frame,Mat test) {
    // Info to store analysis stats
    int distance=0;
    MatOfKeyPoint keypoints_o = new MatOfKeyPoint();
    MatOfKeyPoint keypoints_t = new MatOfKeyPoint();
    Mat descriptors_o = new Mat();
    Mat descriptors_t = new Mat();
    // Detect key points and compute descriptors for inputFrame


    ana(frame, keypoints_o, descriptors_o);
    ana(test, keypoints_t, descriptors_t);
    // Compute matches
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors_o, descriptors_t, matches);
    // Filter matches by distance
    MatOfDMatch filtered = filterMatchesByDistance(matches);
    // If count of matches is OK, apply homography check
    distance = (int) filtered.size().height;

        return (distance);

}

每次距离为0。如果我给出相同的图像,它也给我0的距离。

0 个答案:

没有答案