Displaying matched Features

asked 2016-06-06 01:59:15 -0600

kevgeo gravatar image

updated 2016-06-06 04:18:51 -0600

I'm trying to create a showMatchedFeatures function similar to that of MATLAB, using OpenCV library in C++.

A matchFeatures function has already been made which takes as parameters two features f1 & f2 which are matrices of type double containing the computed feature vector by SURF. This function manually computes the descriptors i.e the feature vectors. So there was no need of using the extractor method of SurfDescriptorExtractor class which is used in the FlannBasedMatcher tutorial.

After that it computes the matches using FLANN Based approach and and returns the matches which are used as parameters in the showMatchedFeatures function.

Now the showMatchedFeatures function only has to draw the matches using drawMatches function of OpenCv but the problem is even though lines are drawn, it doesn't match the same feature points. Only 1 or 2 points get matched properly but the rest are completely wrong.

So I was wondering whether the feature vector computed was wrong and that's why maybe I'm getting the error since I didn't use OpenCV extractor method of SurfDescriptorExtractor class ?

Code- matchFeatures function(lines 376-461 does the feature vector computation) -The function can't return a Dmatch(OpenCV) object but can return pointers of double datatype, so I took the important members of the object like queryIdx,trainIDx and distance and stored it in a double array and as 3 parameters are passed to showMatchedFeatures function where they are combined to create a new Dmatch object and with this, drawMatches function is used.

showMatchedFeatures function(lines 146 - 190 )- Contains the creation of Dmatch object and drawing the good matches.

Link to code-code link

edit retag flag offensive close merge delete

Comments

"Only 1 or 2 points get matched properly but the rest are completely wrong." -- this is not a drawing problem, but simply bad matches. you need a ratio test (and maybe a homography backprojection) to remove outliers.

berak gravatar imageberak ( 2016-06-06 02:03:56 -0600 )edit

Thanks berak for the input but I don't understand why am I getting bad matches? I have used a limit of <= 2*max_distance to select the good matches which also have been used in the tutorial. Yet I'm getting bad matches, so it because of how the feature descriptor was computed?

Also what exactly is homography backprojection? Do you have any link to this topic?

kevgeo gravatar imagekevgeo ( 2016-06-06 04:13:51 -0600 )edit