Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV, feature matching with code from the tutorial

Tags:

c++

opencv

I copied the code of the Feature Matching with FLANN from the OpenCV tutorial page, and made the following changes:

  • I used the SIFT features, instead of SURF;
  • I modified the check for a 'good match'. Instead of

    if( matches[i].distance < 2*min_dist )
    

I used

    if( matches[i].distance <= 2*min_dist )

otherwise I would get zero good matches when comparing an image with itself.

  • Modified parameter in drawing the keypoints:

    drawMatches( img1, k1, img2, k2,
                     good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
                     vector<char>(), DrawMatchesFlags::DEFAULT);
    

I extracted the SIFT from all the images in the folder Ireland of the INRIA-Holidays dataset. Then I compared each image to all the others and draw the matches.

However there is a strange problem I have never experienced with any other SIFT/Matcher implementation I used in the past:

  • the matches for an image I matched against itself are good. Each keypoint is mapped onto itself except for some. See image above. Image matched against itselft
  • When I match I against another image J (with J not equal to I), many points are mapped onto the same one. Some examples are below. MatchesMatchesMatches

Is there anyone who used the same code from the OpenCV tutorial and can report a different experience from mine?

like image 975
Antonio Sesto Avatar asked Jan 29 '13 18:01

Antonio Sesto


People also ask

What is feature matching in OpenCV?

OpenCV is available for both Python and C++, making it a popular choice for cross-platform development. Now that you know that feature matching is comparing the features of two images which may be different in orientations, perspective, lightening, or even differ in sizes and colors.

What version of OpenCV is used with Flann?

OpenCV: Feature Matching with FLANN OpenCV  3.4.16-dev Open Source Computer Vision OpenCV Tutorials 2D Features framework (feature2d module) Feature Matching with FLANN

What is OpenCV used for in Python?

OpenCV is a library of computer vision algorithms that can be used to perform a wide variety of tasks, including feature matching. OpenCV is available for both Python and C++, making it a popular choice for cross-platform development.

How to match features in one image with others?

We will see how to match features in one image with others. Brute-Force matcher is simple. It takes the descriptor of one feature in first set and is matched with all other features in second set using some distance calculation.


Video Answer


1 Answers

Checkout the matcher_simple.cpp example. It uses a brute force matcher that seems to work pretty well. Here is the code:

// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);

// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);

// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
like image 98
Radford Parker Avatar answered Oct 15 '22 09:10

Radford Parker