Ask Your Question
9

How to get good matches from the ORB feature detection algorithm?

asked 2012-06-26 06:27:28 -0600

Rui Marques gravatar image

updated 2012-06-26 08:36:33 -0600

In the context of matching features from a live camera with features from an image of an object, how do you filter the detected features and/or the matches?

I prefer answers for OpenCV4Android, but answers for the desktop version are also acceptable!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
19

answered 2012-06-28 12:57:10 -0600

AlexanderShishkov gravatar image

updated 2012-06-29 02:11:10 -0600

There are some common methods for filering keypont matches for any descriptor calculating method.

Simple filters, for example Ratio test (See Lowe paper about SIFT), cross-check matching, ...

Ratio: "Therefore, for each feature point, we have two candidate matches in the other view. These are the two best ones based on the distance between their descriptors. If this measured distance is very low for the best match, and much larger for the second best match, we can safely accept the first match as a good one since it is unambiguously the best choice. Reciprocally, if the two best matches are relatively close in distance, then there exists a possibility that we make an error if we select one or the other. In this case, we should reject both matches."

Cross-check:

BruteForceMatcher<L2<float> > descriptorMatcher;
vector<DMatch> filteredMatches12, matches12, matches21;
descriptorMatcher.match( descriptors1, descriptors2, matches12 );
descriptorMatcher.match( descriptors2, descriptors1, matches21 );
for( size_t i = 0; i < matches12.size(); i++ )
{ 
    DMatch forward = matches12[i]; 
    DMatch backward = matches21[forward.trainIdx]; 
    if( backward.trainIdx == forward.queryIdx ) 
        filteredMatches12.push_back( forward ); 
}

Also you can use geometry validation. For example, if you consider matches between image of a planar object and some scene, you know that there is a homograhy between two images of a planar object. So you can try to find homography with RANSAC scheme and filter matches using this homography.

edit flag offensive delete link more

Comments

how to write the code for ratio test?

Yiyi gravatar imageYiyi ( 2012-10-17 12:15:24 -0600 )edit
2

void RatioCheck::filter(std::vector<vector<DMatch> > &nmatches, double RatioT=0.8) { vector<vector<DMatch>> knmatches; for(int i=0; i<nmatches.size(); i++) { if((nmatches[i].size()==1)||(nmatches[i][0].distance/nmatches[i][1].distance<RatioT)) { knmatches.push_back(nmatches[i]); } } nmatches = knmatches; }

For matching you should use knnMatch(...) method, because you need get 2 corresponding descriptors for each test descriptor.

AlexanderShishkov gravatar imageAlexanderShishkov ( 2012-10-18 08:08:34 -0600 )edit

@Alexander Shishkov Can you answer my question http://answers.opencv.org/question/18436/what-to-do-with-dmatch-value/ how can i compare two images and say if ther are equal or not ?

newBee gravatar imagenewBee ( 2013-08-14 01:16:39 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2012-06-26 06:27:28 -0600

Seen: 16,485 times

Last updated: Jun 29 '12