OpenCV错误:断言失败(query.type()== type&& indices.type()== CV_32S&& dists.type()== dtype)

时间:2014-12-22 12:21:32

标签: c++ opencv

我试图用OpenCV创建一个词袋,我稍后会用它来训练SVM。不幸的是我的程序不起作用。

这是我的代码:

#include <stdio.h>
#include <stdlib.h>

#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include <string>

#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    int check_num = 0;

    Mat featuresUnclustered;

    Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
    Ptr<DescriptorExtractor> extractor = DescriptorExtractor::create("BRIEF");
    Ptr<FeatureDetector> detector = FeatureDetector::create("FAST");


    Mat img = imread("./positive_images/1.jpg");

    vector<KeyPoint> keypoints;
    detector->detect(img,keypoints);

    extractor->compute(img, keypoints, featuresUnclustered);
    featuresUnclustered.convertTo(featuresUnclustered, CV_32F);

    int dictionarySize = 1000;
    TermCriteria tc(CV_TERMCRIT_ITER,100,0.001);
    int retries = 1;
    int flags = KMEANS_PP_CENTERS;

    BOWKMeansTrainer bowTrainer(dictionarySize,tc,retries,flags);

    cout << "check: " << check_num << endl;
    check_num++;

    Mat dictionary = bowTrainer.cluster(featuresUnclustered);

    cout << "check: " << check_num << endl;
    check_num++;

    BOWImgDescriptorExtractor bowDE(extractor,matcher);
    bowDE.setVocabulary(dictionary);

    cout << "check: " << check_num << endl;
    check_num++;

    Mat bowDescriptor;
    bowDE.compute(img,keypoints,bowDescriptor);

    cout << "check: " << check_num << endl;
    check_num++;

    return 0;
}

最后一次检查没有打印,所以这意味着问题在于bowDE.compute();但我不知道它是由什么引起的。这是给出的错误:

OpenCV Error: Assertion failed (query.type() == type && indices.type() == CV_32S && dists.type() == dtype) in runKnnSearch_, file /build/buildd/opencv-2.4.8+dfsg1/modules/flann/src/miniflann.cpp, line 469
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/flann/src/miniflann.cpp:469: error: (-215) query.type() == type && indices.type() == CV_32S && dists.type() == dtype in function runKnnSearch_

Aborted (core dumped)

我是第一次这样做,所以我很难解决它。你能说出问题是什么吗?提前谢谢!

0 个答案:

没有答案