Question

I am trying to compute correspondence between 2 images and am actually interested in the number of correspondence points, rather than the correspondence themselves, so that I can sue it to get the best match image. This is my following code :

     #include<iostream>
     #include<vector>
     #include<string>
     #include "cv.h"
     #include "highgui.h"
     #include "opencv2/imgproc/imgproc.hpp"
     #include "opencv2/highgui/highgui.hpp"
     #include "opencv2/legacy/legacy.hpp"
     #include "opencv2/objdetect/objdetect.hpp"
     #include "opencv2/nonfree/nonfree.hpp"
     #include "opencv2/nonfree/features2d.hpp"
     #include<stdio.h>

     using namespace cv;
     using namespace std;

     int main(int argc, char **argv)
     {
       Mat A = imread("/home/itachi/iTaggproj/frame6.jpg",CV_LOAD_IMAGE_COLOR);
       Mat src = imread("/home/itachi/iTaggproj/dataformatch/frame0.jpg",CV_LOAD_IMAGE_COLOR);

       SiftFeatureDetector detector( 0.05, 5.0 );
           SiftDescriptorExtractor extractor( 3.0 );

       vector<KeyPoint>keypoints1,keypoints2;
           detector.detect( A, keypoints1 );
           detector.detect( src, keypoints2 );

       int key1 = keypoints1.size();
           int key2 = keypoints2.size();
           printf("Keypoint1=%d \nKeypoint2=%d", key1, key2);

       // Feature descriptor computation
       Mat descriptor1,descriptor2;
       extractor.compute( A, keypoints1, descriptor1 );
       extractor.compute( src, keypoints2, descriptor2 );

       //match points to get correspondence
 //        BFMatcher matcher(NORM_L2);
       FlannBasedMatcher matcher;
       vector<DMatch>matches;
       matcher.match( descriptor1, descriptor2, matches );
       cout<<endl<<matches.size()<<endl;

       return 0;
     }

I have obtained my code from link1 and link2. All my images are 320X240. I took one test image and tried to run it over a database of images one by one. But everytime I do, my matches size is always 163. Note that the keypoints in test image is also 163. I am trying to find the best match for the test image, but I am not getting the idea as to why this is happening. All the correspondence matches with the database give the result of 163.

These are my questions and doubts please help me. :-

  1. how can I obtain the number of matches if the method above am using is wrong?

Apologies if the quesiton is pretty rudimentary but your help is much appreicated.

Was it helpful?

Solution

The FlannBasedMatcher.match() method does not do what you think it does; it will return the best match for every keypoint. As such, you will always have 163 matches because there will always be a best match, even if it is not a very good one.

What usually happens when matching features is that a threshold is then applied to the descriptor distances; so for example, if any of the matches have a distance greater than threshold t, then they are rejected. The number of good matches, after thresholding, is usually used to measure the similarity between images. I think this is the number you were expecting to get.

Your code basically forms the first part of the tutorial here. If you read the tutorial you will see exactly what I have described, where the matches are thresholded according to their distance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top