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 other 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<FeatureDetector> orb = ORB::create(300, 2.0, 3, 31, 0, 2, 0, 31, 15);
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<FeatureDetector> orb2 = ORB::create(300, 2.0, 3, 31, 0, 2, 0, 31, 15);
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.