knnMatch giving different results with Flann

asked 2018-09-17 09:38:12 -0600

Roysorus gravatar image

updated 2018-09-20 12:04:52 -0600

Hello,

I'm trying to use knnMatch to get matches between two sets of descriptors to track through each frame of a video.

I wanted to do another knnMatch on another part of the code to track something else. The problem is by adding that, the result of the first knnmatch were affected even when I used a different matcher.

So I tried a simple test, for 2 sets of descriptors (cv::Mat)

std::vector<std::vector<cv::DMatch> > matches, matches2;

//First Matcher
Ptr<flann::IndexParams> indexParams = makePtr<flann::LshIndexParams>(6, 12, 1);
Ptr<flann::SearchParams> searchParams = makePtr<flann::SearchParams>(50);
Ptr<DescriptorMatcher> matcher = makePtr<FlannBasedMatcher>(indexParams, searchParams);

//Second Matcher
Ptr<flann::IndexParams> indexParams2 = makePtr<flann::LshIndexParams>(6, 12, 1);
Ptr<flann::SearchParams> searchParams2 = makePtr<flann::SearchParams>(50); 
Ptr<DescriptorMatcher> matcher2 = makePtr<FlannBasedMatcher>(indexParams2, searchParams2);

//Matching
matcher->knnMatch(desc1, desc2, matches, 2);
matcher2->knnMatch(desc1, desc2, matches2, 2);

The results of the test is that for the same execution knnMatch gives different results in "matches" and "matches2". However, when I rerun the code I get the same "matches" and the same "matches2" as in the first execution.

I'm confused and I want to understand how does it work. I want to know if there is some kind of shared memory or static variable used in the knnmatch that affects my results in the second call of the function.

edit retag flag offensive close merge delete