2
$\begingroup$

I'm trying to match SURF points between 2 images using SURF with opencv. One is the rotation of the other. The problem is that the few matching it can found are wrong.

image of matching points

I mainly took my code from opencv http://docs.opencv.org/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html#feature-flann-matcher

Here is the code:

string imageName1="test_right_rotate.jpg";
string imageName2="test_right.jpg";
Mat image1 = imread( imageName1, 1 );
Mat image2 = imread( imageName2, 1 );
int minHessian = 500;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;

detector->detect( image1, keypoints_1 );
detector->detect( image2, keypoints_2 );

SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;

extractor.compute( image1, keypoints_1, descriptors_1 );
extractor.compute( image2, keypoints_2, descriptors_2 );

FlannBasedMatcher matcher;
std::vector<vector<DMatch > > matches;
matcher.knnMatch(descriptors_1,descriptors_2, matches, 2);
std::vector< DMatch > good_matches;
for(int i = 0; i < min(descriptors_1.rows-1,(int) matches.size()); i++) //THIS LOOP IS SENSITIVE TO SEGFAULTS
{
    if((matches[i][0].distance < 0.6*(matches[i][1].distance)) && ((int) matches[i].size()<=2 && (int) matches[i].size()>0))
    {
        good_matches.push_back(matches[i][0]);
    }
}
Mat img_matches;
drawMatches( image1, keypoints_1, image2, keypoints_2, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );

It works well for scaled images and translated images but fails for rotated images.

EDIT:

I don't know what is wrong but instead of using SURF, I used ORB as detector and FREAK as extractor and it works a lot better. You can find the code on this SO : https://stackoverflow.com/questions/12491022/opencv-freak-fast-retina-keypoint-descriptor

$\endgroup$
2
  • $\begingroup$ As the code from opencv didn't work, I took a part from here robocv.blogspot.jp/2012/02/… but the result is exactly the same. $\endgroup$
    – Seltymar
    Dec 12, 2012 at 4:54
  • $\begingroup$ SURF isn't completely rotation invariant. $\endgroup$
    – Naresh
    Dec 12, 2012 at 9:29

1 Answer 1

2
$\begingroup$

SURF Features are not completely rotation invariant.

In the paper, they try to make SURF more robust to rotations by following the following methodology.

In order to improve the performance for rotation, the descriptors are based on multi-orientations. The many-to-many tentative correspondences are determined with a maximum distance. Hough transform is used to reject the mismatches and the affine parameters are computed with a least-squares solution.

The image matching algorithm shows a better performance for image rotation than the standard SURF and it succeeds in matching the image including repetitive patterns which will deteriorate the distinctiveness of feature descriptors.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.