OpenCV错误:使用Bag of Words(BOW)断言失败

时间:2017-03-24 21:05:52

标签: c++ opencv feature-detection surf

我正在尝试在c ++中使用带有Bag Of Words的SURF,但是OpenCV正在抛出一个我不知道如何解决它的异常。

  

OpenCV错误:getLocalIdx中的断言失败((globalDescIdx> = 0)&&(globalDescIdx< size())),文件/build/buildd/opencv-2.4.8+dfsg1/modules/features2d/src /matchers.cpp,第163行   在抛出'cv :: Exception'的实例后终止调用     what():/build/buildd/opencv-2.4.8+dfsg1/modules/features2d/src/matchers.cpp:163:错误:(-215)(globalDescIdx> = 0)&&函数getLocalIdx中的(globalDescIdx< size())

如果我只读取一个图像,如下面的代码:

,代码就可以工作
    cv::Mat img=imread("/home/cecilia/catkin_ws/src/self_driven_car/src/src/object_detection/images/Belgium/Training/0/images/image12.jpg",0);
    vector<KeyPoint> keypoints;        
    detector->detect(img,keypoints);
    cv::Mat bowDescriptor;        
    bowDE.compute(img,keypoints,bowDescriptor);

但是,如果我尝试读取数据集中的所有图像,则会抛出Assertion失败的异常。

vector<KeyPoint> keypoints;
Mat bowDescriptor;
Mat trainingData(0, 61, CV_32FC1);
for(unsigned int i=0;i<files.size();i++){
    for(unsigned int j=0;j<files[i].size();j++){
        cv::Mat img = cv::imread(files[i][j], 0);
            if (img.empty()){
                std::cerr << "WARNING: Could not read image." << std::endl;
                std::cerr << files[i][j] << std::endl;
                continue;
            }
            else {
                vector<KeyPoint> keypoints;
                detector->detect(img,keypoints);
                cv::Mat bowDescriptor;
                bowDE.compute(img,keypoints,bowDescriptor);
            }

0 个答案:

没有答案