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: