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. :-
- 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.