static double match(const vector<KeyPoint>& /*kpts_train*/, const vector<KeyPoint>& /*kpts_query*/, DescriptorMatcher& matcher, const Mat& train, const Mat& query, vector<DMatch>& matches) { double t = (double)getTickCount(); matcher.match(query, train, matches); //Using features2d return ((double)getTickCount() - t) / getTickFrequency(); }
string exec_match(Mat testDesc, int match_method) { vector<vector<DMatch> > knnMatches; vector<DMatch> annMatches; vector<int> bestMatches(imgNames.size(), 0); // apply the required matching method switch(match_method) { case 1: { int knn = 1; matcher->knnMatch(testDesc, knnMatches, knn); // Filter results for(vector<vector<DMatch> >::const_iterator it = knnMatches.begin(); it != knnMatches.end(); ++it) { for(vector<DMatch>::const_iterator it2 = it->begin(); it2 != it->end(); ++it2) { ++bestMatches[(*it2).imgIdx]; } } } break; case 2: { matcher->match(testDesc, annMatches); for(vector<DMatch>::const_iterator iter = annMatches.begin(); iter != annMatches.end(); ++iter) { ++bestMatches[(*iter).imgIdx]; } } break; } // Filter results /* for(vector<vector<DMatch> >::const_iterator it = knnMatches.begin(); it != knnMatches.end(); ++it){ for(vector<DMatch>::const_iterator it2 = it->begin(); it2 != it->end(); ++it2){ ++bestMatches[(*it2).imgIdx]; } } */ // Find best match int bestScore = 0; int bestIdx = -1; for(int i = 0; i < bestMatches.size(); ++i){ if(bestMatches[i] >= bestScore){ bestScore = bestMatches[i]; bestIdx = i; } } string imgBaseName = string(fs::basename(imgNames.at(bestIdx))); boost::replace_all(imgBaseName, "-", " "); return imgBaseName; }