16

I am running Ubuntu 14.04. I am trying to run FLANN with openCV 3 but I get an error.

Everything bellow was tried by using AKAZE and ORB but the code if from my attempt to use ORB.

I use ORB to find the descriptors and key-points.

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

After I use ORB, I use the following code to find matches:

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

The code builds fine and everything. When I run the code I get this error:

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)

Can anybody tell me why? Is it something with OpenCV 3 being in BETA state? Is there an alternative to FLANN (except BFMatcher)

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
Metalzero2
  • 531
  • 2
  • 6
  • 17

3 Answers3

24

So what I said:

in order to use FlannBasedMatcher you need to convert your descriptors to 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);
}

you can take a look to this similar question:

Community
  • 1
  • 1
Rafael Ruiz Muñoz
  • 5,333
  • 6
  • 46
  • 92
  • It worked! Thanks a lot for your help. I had already seen that post (that you linked to) but because the accepted answer said it was just a bug, I ignored it. Thanks again for you help :) – Metalzero2 Apr 17 '15 at 09:47
  • No problem!. I think when it happened to me, I did the same! ;) – Rafael Ruiz Muñoz Apr 17 '15 at 09:49
  • Hi,I am also sing ORB and getting same error. I tried to use the solution provided,But I'm getting same error again.Can u help this out. – Anirudh Jul 11 '17 at 05:47
  • You'd need to describe the error and show the code @Anirudh – Rafael Ruiz Muñoz Jul 11 '17 at 11:29
  • 2
    The descriptors for ORB and AKAZE are **binary** unlike those of SIFT and SURF which are **floats**. For comparing ORB / AKAZE descriptors, use FLANN + LSH index or Brute Force + Hamming distance. [http://answers.opencv.org/question/59996/flann-error-in-opencv-3/] – Nirmal Oct 24 '18 at 11:59
8

The answer by Rafael Ruiz Muñoz is wrong.

Convert the descriptors to CV_32F elimilated the assertion error. But, the matcher will behavior in the wrong way.

ORB is hamming descriptor. By default, the FlannBasedMatcher creates L2 euclid KDTreeIndexParams().

Try to init the matcher in the flowing way,

cv::FlannBasedMatcher matcher(new cv::flann::LshIndexParams(20, 10, 2));
Yang Kui
  • 548
  • 5
  • 11
3

Unsupported format or combination of formats is also thrown if no descriptors could be computed.

You can check if that's the case using empty() after detectAndCompute, thus:

  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__);
  }
davetapley
  • 17,000
  • 12
  • 60
  • 86