Ask Your Question

How to constrain RANSAC when using findHomography? object detection

asked 2015-01-27 02:29:49 -0500

Fiong gravatar image

I want to do the matching between images, I have used SIFT as the feature and use RANSAC for improve the matching. Some results are good, but some failed. Can anyone tell me how to improve it? I think my implementation should be right as I got some good results.

The steps I do the experiment are:

Step1: Extract SIFT feature;

Step2: Use FlannBasedMatcher to do the matching;

Step3: Use RANSAC to correct the matching; // but I found too many points are matched to a single point

Below are the core code for my experiment:

 FlannBasedMatcher matcher; 

 std::vector< DMatch > matches;  

 matcher.match( descriptors_1, descriptors_2, matches );  

 double max_dist = 0;   
 double min_dist = 100;  

 for( int i = 0; i < descriptors_1.rows; i++ )  
    double dist = matches[i].distance;  
    if( dist < min_dist ) min_dist = dist;  
    if( dist > max_dist ) max_dist = dist;  
for( int i = 0; i < descriptors_1.rows; i++ )  
    if( matches[i].distance < max_dist)
        good_matches.push_back( matches[i]);   //keep all the matches

H = findHomography( tmp_obj, tmp_scene, CV_RANSAC, 3.0, Mask); 

    for (int i = 0; i< good_matches.size(); i ++)

        if (<uchar>(i) != 0)  // RANSAC selection

            obj.push_back( keypoints_object[ good_matches[i].queryIdx ].pt );  
            scene.push_back( keypoints_scene[ good_matches[i].trainIdx ].pt );   


            numGood = numGood + 1;



some failed case:

image description

image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-01-27 06:18:48 -0500

JohannesZ gravatar image

You need two additional steps between the matching stage via FLANN and RANSAC: cross-Matching and NNDR (Nearst Neighbor Distance Ratio).

You can have a look at the delivered openCV examples or try to find them on the web. You can also find working code in the various openCV books.

edit flag offensive delete link more

Question Tools



Asked: 2015-01-27 02:29:49 -0500

Seen: 806 times

Last updated: Jan 27 '15