OpenCV 3中的FLANN错误

Dim*_*lis 12 c++ opencv orb flann

我正在运行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 );
Run Code Online (Sandbox Code Playgroud)

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

  FlannBasedMatcher matcher;
  std::vector<DMatch> matches;
  matcher.match(descriptors_1, descriptors_2, matches);
Run Code Online (Sandbox Code Playgroud)

代码构建良好和一切.当我运行代码时,我收到此错误:

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)
Run Code Online (Sandbox Code Playgroud)

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

Raf*_*ñoz 15

所以我说的话:

为了使用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);
}
Run Code Online (Sandbox Code Playgroud)

你可以看看这个类似的问题:

  • ORB 和 AKAZE 的描述符是 **binary**,与 SIFT 和 SURF 的 **floats** 不同。要比较 ORB / AKAZE 描述符,请使用 FLANN + LSH 指数或蛮力 + 汉明距离。[http://answers.opencv.org/question/59996/flann-error-in-opencv-3/] (2认同)

Yan*_*Kui 7

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

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

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

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

cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20, 10, 2));
Run Code Online (Sandbox Code Playgroud)