c++ - 汉明距离目标检测

标签 c++ algorithm opencv image-recognition hamming-distance

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

  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 检测图像中的对象,你也许应该尝试 Cascade Classification . This link将解释如何训练分类器。

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

关于c++ - 汉明距离目标检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17296425/

相关文章:

c++ - 从 Boost C++ 数组的元素中减去最大值

arrays - 通过连接两个递增子数组构成的最大长度递增 super 数组

opencv - 查找带有边界框的对象

image-processing - 二维点集匹配

c++ - 在 C++ 项目中使用 libjson

c++ - 如何通过 Code::Blocks 中的静态链接创建独立程序

c++ - 制作 boost http 客户端

.net - 如何自动生成体育联赛赛程

algorithm - 尝试使用实时游戏的 Alpha-Beta 搜索?

c++ - FeatureDetector OpenCV 2.4.5 中的访问违规读取