Ask Your Question
1

What happens if there's not enough key points to match?

asked 2015-04-07 19:48:11 -0600

davidshen gravatar image

Given two mat: mat1 and mat2, I extracted SIFT key points: kps1 and kps2, then I computed the descriptors: desc1 and desc2.

I want to know if I do a Flann match against these two descriptors, what will happen if they have different number of descriptors in them?

For what I experienced, it seems the number of matches will always be the same as the number of descriptors in desc1, the query descriptor.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-08 02:47:02 -0600

updated 2015-04-11 07:07:30 -0600

Flann finds the most similar descriptor in the training set for each descriptor in the query set. If the training set is smaller, then several query descriptors will be matched to the same training descriptor.

You have several possibilities to deal with that:

a) use something like RANSAC to select your true inliers

b) perform the inverse search (swap training with query) and only select pairs that get assigned to each other in both directions

c) decrease the number of matches by using new constraints. e.g. search for the two next neighbours and only create a match if the distance to the first neighbour is less than 60% of the distance to the second neighbour. This will help with repetitive structures in your image

edit flag offensive delete link more

Comments

@FooBar, can you please explain more about your c options? It sounds good for me. I looked at FlannBasedMatcher but I could not find a way to add constraints.

davidshen gravatar imagedavidshen ( 2015-04-08 22:34:17 -0600 )edit

To use this option, you don't use the FlannBasedMatcher directly (I've never used it, so I'm not sure how it works exactly), but you use the underlying flann-class directly:

http://docs.opencv.org/modules/flann/...

You insert all of your training descriptors into the flann-structure and then you call knnsearch for each query descriptor with k=2 so that flann gives you the two most similiar descriptors. Here is a piece of code that could guide you a bit:

http://find-object.googlecode.com/svn... (but be careful, this is old c-Api code, so just get the idea and don't use the old iplImage and cv* functions)

FooBar gravatar imageFooBar ( 2015-04-11 07:12:25 -0600 )edit

To complete the previous answer, to retrieve the k-best matches for a query keypoints, you could either use a brute force approach or the Flann method in OpenCV. The Flann approach compared to the brute foce method will be significantly faster wehn dealing with big training / query sets (it uses an efficient structure to store the data) but it is an approximation. The two approaches:

cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce"); //or FlannBased
std::vector<std::vector<cv::DMatch> > matches;
matcher->knnMatch(queryDescriptors, trainDescriptors, matches, 2);
Eduardo gravatar imageEduardo ( 2015-04-11 11:39:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-04-07 19:48:11 -0600

Seen: 541 times

Last updated: Apr 11 '15