Ask Your Question
0

knnMatch in version 2.4.10

asked Jan 28 '15

Fiong gravatar image

Anyone know how to call knnMatch in version 2.4.10?

I used it in this way, but it doesn't work and met errors. Anyone know how to use it?

std::vector< DMatch > matches;  
BFMatcher matcher(NORM_L2, true); 
Mat mask;
matcher.knnMatch(descriptors_1, descriptors_2, matches, 2, mask, false);  // Find two nearest matches
Preview: (hide)

2 answers

Sort by » oldest newest most voted
2

answered Feb 9 '15

Fiong gravatar image

Finally, I solved the problem by changing the declaration of matches :

to be:

  vector<vector<DMatch>> matches;
Preview: (hide)

Comments

Well, for knnmatch you effectively need a vector of vector of knn match, since first you have the best Dmatch for a specific keypoint pair, then you have a vector for all Dmatchs of the image, then a second vector allowing you to store the second best matches with the same structure

This said, beside the change you show in this answer, is the code present in the question works correctly now?

Doombot gravatar imageDoombot (Feb 12 '15)edit
0

answered Jan 28 '15

updated Jan 29 '15

Taking a look at the current knnMatch documentation I guess the matcher interface was changed.

It seems that since 2.4.10 you need to use the pointer interface. Something like this should work

Ptr<DescriptorMatcher> matcher; 
matcher->create("BruteForce");
Mat mask;
matcher -> knnMatch(descriptors_1, descriptors_2, matches, 2, mask, false);  // Find two nearest matches

Can you check the result?

Preview: (hide)

Comments

The first line cannot work. Maybe sth w. create? Haven't had a look so far...

Guanta gravatar imageGuanta (Jan 28 '15)edit

The edit should work according to documentation :)

StevenPuttemans gravatar imageStevenPuttemans (Jan 29 '15)edit

Hi, I have tried you code, but it still doesn't work. Have you tested it? Thanks!

Fiong gravatar imageFiong (Feb 5 '15)edit

Nope, It was a suggestion. Can you give us the error that was generated by this code?

StevenPuttemans gravatar imageStevenPuttemans (Feb 5 '15)edit

The error is: no instance of overloaded function "cv::DescriptorMatcher::knnMatch" matches the argument list

Fiong gravatar imageFiong (Feb 6 '15)edit

Line of code please, where is this error generated.

StevenPuttemans gravatar imageStevenPuttemans (Feb 9 '15)edit

Question Tools

1 follower

Stats

Asked: Jan 28 '15

Seen: 640 times

Last updated: Feb 09 '15