【问题标题】:FLANN error in OpenCV 3OpenCV 3 中的 FLANN 错误
【发布时间】:2018-05-21 17:02:24
【问题描述】:

我正在运行 Ubuntu 14.04。我正在尝试使用 openCV 3 运行 FLANN,但出现错误。

使用 AKAZE 和 ORB 尝试了以下所有内容,但代码来自我尝试使用 ORB 时的代码。

我使用 ORB 来查找描述符和关键点。

  Ptr<ORB> detector = ORB::create();

  std::vector<KeyPoint> keypoints_1, keypoints_2;
  Mat descriptors_1, descriptors_2;

  detector->detectAndCompute( img_1, noArray(), keypoints_1, descriptors_1 );
  detector->detectAndCompute( img_2, noArray(), keypoints_2, descriptors_2 );

使用 ORB 后,我使用以下代码查找匹配项:

  FlannBasedMatcher matcher;
  std::vector<DMatch> matches;
  matcher.match(descriptors_1, descriptors_2, matches);

代码构建良好,一切正常。当我运行代码时出现此错误:

OpenCV Error: Unsupported format or combination of formats (type=0
) in buildIndex_, file /home/jim/opencv/modules/flann/src/miniflann.cpp, line 315
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/jim/opencv/modules/flann/src/miniflann.cpp:315: error: (-210) type=0
 in function buildIndex_

Aborted (core dumped)

谁能告诉我为什么? OpenCV 3 是否处于 BETA 状态?有没有 FLANN 的替代品(BFMatcher 除外)

【问题讨论】:

  • 您能否提供更多有关您如何制作描述符的信息?一些匹配器不接受 float / int 中的描述符
  • @RafaFirenze 刚刚添加(在我上面的帖子中)我用来查找描述符的代码。
  • 查看同一问题的答案here

标签: c++ opencv orb flann


【解决方案1】:

所以我说的是:

要使用FlannBasedMatcher,您需要将描述符转换为CV_32F

if(descriptors_1.type()!=CV_32F) {
    descriptors_1.convertTo(descriptors_1, CV_32F);
}

if(descriptors_2.type()!=CV_32F) {
    descriptors_2.convertTo(descriptors_2, CV_32F);
}

你可以去this similar question看看:

【讨论】:

  • 成功了!非常感谢你的帮助。我已经看过那个帖子(你链接到的那个),但是因为接受的答案说这只是一个错误,所以我忽略了它。再次感谢您的帮助:)
  • 没问题!我想当它发生在我身上时,我也是这么做的! ;)
  • 嗨,我也在唱 ORB 并得到同样的错误。我尝试使用提供的解决方案,但我又遇到了同样的错误。你能帮忙吗?
  • 您需要描述错误并显示代码@Anirudh
  • ORB 和 AKAZE 的描述符是 binary,而 SIFT 和 SURF 的描述符是 floats。要比较 ORB / AKAZE 描述符,请使用 FLANN + LSH 索引或蛮力 + 汉明距离。 [answers.opencv.org/question/59996/flann-error-in-opencv-3/]
【解决方案2】:

Rafael Ruiz Muñoz 的回答是错误的。

将描述符转换为 CV_32F 消除了断言错误。但是,匹配器会以错误的方式运行。

ORB 是汉明描述符。默认情况下,FlannBasedMatcher 创建 L2 euclid KDTreeIndexParams()。

尝试以流动的方式初始化匹配器,

cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20, 10, 2));

【讨论】:

  • 你好。我的回答没有错,它适用于不同的场景。就是这样:)
【解决方案3】:

如果无法计算描述符,也会抛出Unsupported format or combination of formats

您可以在detectAndCompute 之后使用empty() 检查是否是这种情况,因此:

  detector->detectAndCompute( img_1, noArray(), keypoints_1, descriptors_1 );
  detector->detectAndCompute( img_2, noArray(), keypoints_2, descriptors_2 ); 

  if ( descriptors_1.empty() ) {
     cvError(0,"MatchFinder","descriptors_1 descriptor empty",__FILE__,__LINE__);
  }
  if ( descriptors_2.empty() ) {
     cvError(0,"MatchFinder","descriptors_2 empty",__FILE__,__LINE__);
  }

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 2017-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多