OpenCV 在 SURF 检测后崩溃

OpenCV crash after SURF Detection

本文关键字:崩溃 检测 SURF OpenCV      更新时间:2023-10-16

我在OpenCV中编写了一个简单的程序,该程序可以检测给定图像中的SURF特征,并在namedWindow中播放检测到的特征。

#include <iostream>
#include <opencv2corecore.hpp>
#include <opencv2highguihighgui.hpp>
#include <opencv2features2dfeatures2d.hpp>
using namespace cv;
int main(int argc,char** argv)
{
    if(argc!=3)//Check cmd number of argumets
    {
        std::cout<<"Usage: "<<argv[0]<<" <image-file> <method>"<<std::endl;
        return -1;
    }
    //LOAD THE SOURCE IMAGE
    Mat Img = imread(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
    if(!Img.data)//Check correct image load
    {
        std::cout<<"Cannot read image file. Check file path!"<<std::endl;
        return -1;
    }
    //COMPUTE FEATURES
    SurfFeatureDetector detector;
    std::vector<KeyPoint> features;
    detector.detect(Img,features);
    //SHOW RESULT
    Mat ImgF;
    drawKeypoints(Img,features,ImgF);
    namedWindow("Features", CV_GUI_NORMAL);
    imshow("Features",ImgF);

    waitKey();
    return 0;
}

一切都很好,程序做它必须做的事情。问题是当按下某个键终止程序时,会发生崩溃错误。

不会崩溃对我来说...但是为了让我编译你的代码,我不得不添加

#include <opencv2/nonfree/features2d.hpp>

因为 SURF 在某个时候被移到了非自由模块。

因此,我必须建议尝试最新版本(截至今天的2.4.6)。