0

I am using FAST and FREAK to get the descriptors of a couple of images and then I apply knnMatch with a BruteForceMatcher matcher and next I am using a loop to separate the good matches:

  float nndrRatio = 0.7f;
  std::vector<KeyPoint> keypointsA, keypointsB;
  Mat descriptorsA, descriptorsB;
  std::vector< vector< DMatch >  > matches; 

  int threshold=9;
       // detect keypoints:
  FAST(objectMat,keypointsA,threshold,true);
  FAST(sceneMat,keypointsB,threshold,true);

  FREAK extractor;
       // extract descriptors:
  extractor.compute( objectMat, keypointsA, descriptorsA );
  extractor.compute( sceneMat, keypointsB, descriptorsB );

  BruteForceMatcher<Hamming> matcher;
       // match
  matcher.knnMatch(descriptorsA, descriptorsB, matches, 2);


       // good matches search: 
  vector< DMatch > good_matches;

  for (size_t i = 0; i < matches.size(); ++i)
  { 
        if (matches[i].size() < 2)      
              continue;

        const DMatch &m1 = matches[i][0];   
        const DMatch &m2 = matches[i][1];

        if(m1.distance <= nndrRatio * m2.distance)        
        good_matches.push_back(m1);   
  }

       //If there are at least 7 good matches, then object has been found
  if ( (good_matches.size() >=7))
  { 
  cout << "OBJECT FOUND!" << endl;
  }

I think the problem could be the good matches search method, because using it with the FlannBasedMatcher works fine but with the BruteForceMatcher very weirdly. I'm suspecting that I may be doing a nonsense with this method because the Hamming distance uses binary descriptors, but I can't think of a way to adapt it!

Any links, snippets, ideas,... please?

4

1 回答 1

1

您的代码还不错,但我认为这不是您想要做的。你为什么选择这种方法?

如果您想使用 OpenCV 检测图像中的对象,您应该尝试Cascade Classification此链接将解释如何训练分类器。

编辑:如果您认为它太复杂并且您想要检测的对象是平面的,您可以尝试本教程(它基本上通过尝试找到对象和图像之间的单应变换来计算内点)。但是级联分类对于目标检测更通用。

于 2013-06-26T14:07:29.613 回答