利用汉明距离进行目标检测

Object Detection with Hamming distance

本文关键字:目标 检测 汉明距离      更新时间:2023-10-16

我使用FAST和FREAK来获得几个图像的描述符,然后我使用BruteForceMatcher匹配器应用knnMatch,接下来我使用循环来分离好的匹配:

  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;
  }

我认为问题可能是好的匹配搜索方法,因为将其与FlannBasedMatcher一起使用效果很好,但与BruteForceMatcher一起使用则非常奇怪。我怀疑我可能在用这种方法胡说八道,因为汉明距离使用了二进制描述符,但我想不出适应它的方法!

任何链接、片段、想法,。。。请

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

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

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