0

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.

Lakshmi Narayanan
  • 5,220
  • 13
  • 50
  • 92
  • Did i understand your question right? You are asking why you have 163 matches. -> So i think this is because of your number of keypoints. You have 163 keypoints and the matcher try to look for an keypoint in the other picture and if he can find someone he will take it. So your number of matches depands on your amount of keypoints. If you have 163 Keypoints you will get 163 matches. And if you have allways the same test image you will allways get the same number of matches because he will find the same keypoints (hopefully ;) ). – retinotop Oct 29 '13 at 15:49
  • @retinotop yes, I noticed that. But correspondence matching of dexcriptors doesn't work that way right? It is not possible for all the 163 to have a match always. Which means, this implementation of matching is wrong in Opencv – Lakshmi Narayanan Oct 31 '13 at 10:10

1 Answers1

1

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.

devrobf
  • 6,973
  • 2
  • 32
  • 46