OpenCV错误的解决方案:不支持的格式或格式组合 - 将ORB功能与FlannBasedMatcher

时间:2017-07-11 06:05:28

标签: c++ opencv3.0 orb

我试图使用ORB找到好的匹配。我的代码如下:

Ptr<FeatureDetector> detector = ORB::create();
Mat descriptors_img1, descriptors_img2;


//-- Step 2: Calculate descriptors (feature vectors)
detector->detect(img1, kp1,descriptors_img1);
detector->detect(img2, kp2,descriptors_img2);


Ptr<DescriptorExtractor> extractor = ORB::create();
extractor->compute(img1, kp1, descriptors_img1 );
extractor->compute(img2, kp2, descriptors_img2 );
//-- Step 3: Matching descriptor vectors using FLANN matcher
descriptors_img1.convertTo(descriptors_img1, CV_32F);
descriptors_img2.convertTo(descriptors_img2, CV_32F);
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_img1,descriptors_img2,matches);
double max_dist = 0; double min_dist = 100;

//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_img1.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 );

//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;

for( int i = 0; i < descriptors_img1.rows; i++ )
{
    if( matches[i].distance < 3*min_dist )
    {
        good_matches.push_back( matches[i]);
    }
}

Mat img_matches;
drawMatches(img1,kp1,img2,kp2,good_matches,img_matches,Scalar::all(-1),
        Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Show detected matches
imshow( "Good Matches", img_matches );

但是当我运行它时,我得到错误说:

  

OpenCV错误:不支持的格式或格式组合(type = 0   )在buildIndex_,file /home/opencv-3.2.0/modules/flann/src/miniflann.cpp,第315行   在抛出&#39; cv :: Exception&#39;的实例后终止调用     what():/ home / opencv-3.2.0/modules/flann/src/miniflann.cpp:315:错误:(-210)type = 0 in function buildIndex _

我查看了类似的问题,但我没有找到答案。调试后我才知道错误发生在

matcher.match(....);

请帮我解决这个问题。谢谢你提前

1 个答案:

答案 0 :(得分:0)

我解决了这个错误。 你只需修改代码

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

而不是

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

然后它对我有用。