Keshavarzi.Amin
Keshavarzi.Amin

Reputation: 45

how to compare size of kepoints matching in opencv

I'm going compare images with SURF detector in opencv. for this work,I need size and Orientation of keypoints that must be compare them. for example, I have to extract keypoints matching of second image larger than keypoints matching of first image. (keypoint 1.size > keypoint 2.size).

question: how to extract size of keypoints matching in opencv?

Upvotes: 0

Views: 1299

Answers (1)

zedv
zedv

Reputation: 1469

I'm not sure if I quite understand your question.

What I understood was that:

  1. You will compare images using keypoints
  2. You want to compare the size of matched keypoints

First u want at least 2 images:

Mat image1; //imread stuff here
Mat image2; //imread stuff here

Then detect keypoints in the two images using SURF:

vector<KeyPoint> keypoints1, keypoints2; //store the keypoints
Ptr<FeatureDetector> detector = new SURF();
detector->detect(image1, keypoints1); //detect keypoints in 'image1' and store them in 'keypoints1'
detector->detect(image2, keypoints2); //detect keypoints in 'image2' and store them in 'keypoints2'

After that compute the descriptors for detected keypoints:

Mat descriptors1, descriptors2;
Ptr<DescriptorExtractor> extractor = new SURF();
extractor->compute(image1, keypoints1, descriptors1);
extractor->compute(image2, keypoints2, descriptors2);

Then match the descriptors of keypoints using for example BruteForce with L2 norm:

BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

After these steps matched keypoints were stored in the vector 'matches'

You can get the index of matched keypoints as follows:

//being idx any number between '0' and 'matches.size()'   
int keypoint1idx = matches[idx].query; //keypoint of the first image 'image1'
int keypoint2idx = matches[idx].train; //keypoint of the second image 'image2'

Read this for further information: http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html

Finally, to know the size of the matched keypoints u can do the following:

int size1 = keypoints1[ keypoint1idx ].size; //size of keypoint in the image1
int size2 = keypoints2[ keypoint2idx ].size; //size of keypoint in the image2

Further info: http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html

And that's it! Hope this helps

Upvotes: 2

Related Questions