Ask Your Question
0

How to constrain RANSAC when using findHomography? object detection

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

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 (Mask.at<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 );   

            good_matches2.push_back(good_matches[i]);

            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
1

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

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

2 followers

Stats

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

Seen: 1,110 times

Last updated: Jan 27 '15