How to get percentage of similarity of two images from MatOfDMatch?

asked 2013-09-12 02:13:02 -0600

surodip gravatar image

Hi, I am doing a project where I have to compare two images in JAVA. Whatever I have found from internet searching that SIFT is a good way to do that. I have extracted features and find the matches. Now I have the MatOfDMatch. I want to calculate the percentage of similarity from it. Can anyone help me in this?

Below is my code:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    MatOfKeyPoint vector1 = new MatOfKeyPoint();
    MatOfKeyPoint vector2 = new MatOfKeyPoint();

    Mat img1 = Highgui.imread("D:\\TestImages\\shape1.jpg");
    Mat img2 = Highgui.imread("D:\\TestImages\\shape2.jpg");

    FeatureDetector surfDetector = FeatureDetector.create(FeatureDetector.FAST);
    surfDetector.detect(img1, vector1);
    surfDetector.detect(img2, vector2);

    Mat descriptors1 = new Mat();
    Mat descriptors2 = new Mat();

    DescriptorExtractor siftDescriptor =DescriptorExtractor.create(DescriptorExtractor.SURF);

    siftDescriptor.compute(img1, vector1, descriptors1);
    siftDescriptor.compute(img2, vector2, descriptors2);

    MatOfDMatch matches = new MatOfDMatch();

    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);

    matcher.match(descriptors1, descriptors2, matches);

    Mat outImg = new Mat();
    Features2d.drawMatches(img1, vector1, img2, vector2, matches, outImg);

Thanks, Surodip

edit retag flag offensive close merge delete