0

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;

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 cases:

Image 1 matched: www.dropbox.com/s/41thn6wdiutsjbb/case1.jpg?dl=0

Image 2 matched: enter image description here

McMa
  • 1,568
  • 7
  • 22
kim
  • 73
  • 2
  • 7
  • sample 2 is completely fine with the computed hompgraphy concerning ransac and will have many inliers. Problem is just the homography itself. You should check for some homography constraints e.g. it does not transform all your points to a single position ;) – Micka Jan 23 '15 at 12:22
  • do you know where to set the constraints? – kim Jan 24 '15 at 14:04
  • You cant set them. Google about how to check a homography quality. Afair there is a method that uses its determinant or sth similar – Micka Jan 24 '15 at 16:24
  • E.g. try http://stackoverflow.com/questions/14954220/how-to-check-if-obtained-homography-matrix-is-good – Micka Jan 24 '15 at 16:27
  • @Roman Shapovalov any suggestions? – kim Jan 28 '15 at 08:48
  • another thing you see in both of your images is, that maaaaany keypoints are matched to a single keypoint in the other image. You can easily detect those multiple-matchings and remove them (only keep the best). – Micka Jan 28 '15 at 08:50
  • ```if( matches[i].distance < max_dist)``` this does not seem correct. it should be something like ```if( matches[i].distance < 3*min_dist)```. Another way to make it more reliable is to apply cross-check matching. You can do another feature matching all the way around from the second set to the first and only those pairs with the same matches in both directions are valid. This can be done by using ```cv::BFMatcher```. Check this out and let me post the answer if this is the case. – Hamid Bazargani Apr 16 '15 at 17:30

1 Answers1

0

I think the issue is that you might not be drawing the matched features after they have gone through ransac. I can see that you used ransac to extract the homography H but it's not clear what you do with H to draw the refined sample of points.

Hayley
  • 29
  • 4