【问题标题】:Opencv DMatch distance out of rangeOpencv DMatch距离超出范围
【发布时间】:2012-02-09 07:52:08
【问题描述】:

我正在根据 http://opencv.itseez.com/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography 使用 FlannBasedMatcher。每次运行此行“double dist = matches[i].distance;”时,我都会收到错误“vector subscript out of range”,有人可以帮忙吗?我被困在这里很长一段时间了..

int minHessian = 400;

  SurfFeatureDetector detector( minHessian );

  std::vector<KeyPoint> keypoints_object, keypoints_scene;

  detector.detect( img_object, keypoints_object );
  detector.detect( img_scene, keypoints_scene );

  //-- Step 2: Calculate descriptors (feature vectors)
  SurfDescriptorExtractor extractor;

  Mat descriptors_object, descriptors_scene;

  extractor.compute( img_object, keypoints_object, descriptors_object );
  extractor.compute( img_scene, keypoints_scene, descriptors_scene );

  //-- Step 3: Matching descriptor vectors using FLANN matcher
  FlannBasedMatcher matcher;
  std::vector< DMatch > matches;
  matcher.match( descriptors_object, descriptors_scene, matches );

  double max_dist = 0; double min_dist = 100;

  //-- Quick calculation of max and min distances between keypoints
  for( int i = 0; i < descriptors_object.rows; i++ )
  { double dist = matches[i].distance;
    if( dist < min_dist ) min_dist = dist;
    if( dist > max_dist ) max_dist = dist;
  }

  printf("-- Max dist : %f \n", max_dist );
  printf("-- Min dist : %f \n", min_dist );

【问题讨论】:

    标签: c++ opencv vector range out


    【解决方案1】:

    你想用这个:

    vector< vector<DMatch> > matches;
    

    它是 DMatch 的向量!

    【讨论】:

    • 然后,FlannBasedMatcher::match 将声明没有匹配参数列表的实例
    • 这很奇怪......如果你看一下拼接模块中的文件matchers.cpp:169,这正是他们所做的!
    【解决方案2】:

    也许您无法从图像中获得足够的功能?检查关键点的大小。

    【讨论】:

    • 即使两个图像相同,匹配器似乎也没有找到并匹配。匹配项仍然为空。
    • 所以“计算关键点之间的最大和最小距离”毫无意义,检查它们之前的匹配长度
    • 你这是什么意思?我打印出matches [0] .distances,它仍然表示超限。似乎比赛中什么都没有......
    • 但是如果我比较两张相同的图像,它应该有 100% 的特征匹配,对吧?
    【解决方案3】:

    如果您从未解决过这个问题,请确保您使用的向量类型正确,第一个向量应该是 std::vector,而第二个向量应该是 cv::vector。所以如果你没有使用任何命名空间,它应该是这样的:

    std::vector&lt;cv::vector&lt;cv::DMatch&gt;&gt; matches;

    【讨论】:

      猜你喜欢
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2023-02-01
      相关资源
      最近更新 更多