如何使用基于Flann的匹配器进行精确匹配?如果未找到匹配项,则应将输出显示为No Match Found

时间:2016-08-24 06:29:37

标签: c++

  1. 如何使用基于Flann的匹配器进行精确匹配?
  2. 如果未找到匹配项,则应将输出设为“未找到匹配项”。
  3. 也可以显示准确度百分比。
  4. 以下是正在进行匹配的代码:

    // Match 
      vector<vector<DMatch> > knnMatches;
        Mat testDesc;
        int knn = 1;
        vector<int> bestMatches;
        FeatureDetector *detector = new SurfFeatureDetector();
        DescriptorExtractor *extractor = new SurfDescriptorExtractor();
        DescriptorMatcher *matcher = new FlannBasedMatcher();  // ANN
    
            trainDesc.push_back(desc);    
            trainImgs.push_back(img_name);
            int temp = 0;
            bestMatches.push_back(temp);        
    
          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];
            }
          }
    
          // Find best match
          int bestScore = 0;
          int bestIdx = -1;
          for (int i = 0; i < bestMatches.size(); ++i) {
            if (bestMatches[i] >= bestScore) {
              bestScore = bestMatches[i];
              cout << "best Score inside if  is:" << bestScore << endl;
               cout << "best Matches inside if  is:" << bestMatches[i] << endl;
              bestIdx = i;
            }
          }
    
          if (debug > 0)
            cout << "Best match: " << trainImgs[bestIdx] << " Score: " << bestScore
                 << "bestidx: " << bestIdx << endl;
          cout << trainImgs[bestIdx] << endl;
    

0 个答案:

没有答案