c++ - OpenCV - 匹配 SURF 点运行时错误

标签 c++ opencv feature-detection surf

我有一个程序可以将模板图像中找到的特征点与视频源中显示的特征点相匹配。当我运行该程序时,出现以下错误:

OpenCV Error: Assertion failed (i1 >= 0 && i1 < static_cast<int>(keypoints1.size())) in drawMatches, file bin/opencv-2.4.7/modules/features2d/src/draw.cpp, line 207
terminate called after throwing an instance of 'cv::Exception'
  what():  bin/opencv-2.4.7/modules/features2d/src/draw.cpp:207: error: (-215) i1 >= 0 && i1 < static_cast<int>(keypoints1.size()) in function drawMatches

Aborted

这就是上面提到的函数drawMatches:

drawMatches(img_1, templateKeypoints, frames, keypoints_1, good_matches, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1), std::vector<char>(), cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

根据我的阅读,我认为问题在于如果视频中发现的特征点与模板图像中的特征点不匹配,那么程序就会中止。

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

我正在寻找即使不存在匹配项也能持续运行的视频源。

编辑:

我注意到,如果我反复尝试运行该程序,我有时会收到一条替代错误消息:

OpenCV Error: Assertion failed (npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type()) in findHomography, file /home/colin/bin/opencv-2.4.7/modules/calib3d/src/fundam.cpp, line 1074
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/colin/bin/opencv-2.4.7/modules/calib3d/src/fundam.cpp:1074: error: (-215) npoints >= 0 && points2.checkVector(2) == npoints && points1.type() == points2.type() in function findHomography

Aborted

最佳答案

紧接以下内容:

extractor.compute(img_1, keypoints_1, descriptors_1);
extractor.compute(frame, keypoints_2, descriptors_2);

请添加:

if ((descriptors_1.empty()) || (descriptors_2.empty()))
continue;

由于在特定帧中没有找到关键点,它应该进入下一次迭代并检查新帧。 这解决了我的问题。

关于c++ - OpenCV - 匹配 SURF 点运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27943568/

相关文章:

java - 清除内存时,Cocos2dx 会导致应用程序崩溃

opencv - 执行 Opencv 程序时系统崩溃

c++ - 如何使用 Scalar 类指定颜色

c++ - 主函数跳过线程并且不加入以显示所需的输出

c++ - DLIB : Training Shape_predictor for 194 landmarks (helen dataset)

matlab - OpenCV 中是否有与 Matlab Vision.blobAnalysis() 功能相同的函数?

c++ - SQLite查询进度条

c++ - 如何将 "\327\220\327\250\327\225\327\236"转换为希伯来语?

C++模板,使用std迭代器的错误

python - 从特征点检测返回图像中的匹配值