Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FLANN error in OpenCV 3

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)

like image 776
Jim Avatar asked Apr 17 '15 08:04

Jim


3 Answers

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:

like image 78
Rafael Ruiz Muñoz Avatar answered Nov 05 '22 08:11

Rafael Ruiz Muñoz


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));
like image 26
Yang Kui Avatar answered Nov 05 '22 09:11

Yang Kui


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__);
  }
like image 3
davetapley Avatar answered Nov 05 '22 09:11

davetapley