1

我在 OpenCV 中编写了一个简单的程序,它检测给定图像中的 SURF 特征,并在命名窗口中显示检测到的特征。

#include <iostream>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\features2d\features2d.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;
}

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

4

1 回答 1

0

It doesn't crash for me... but in order for me to compile your code, I had to add

#include <opencv2/nonfree/features2d.hpp>

because SURF was moved to the nonfree module at some point.

So, I would have to recommend trying the newest version (2.4.6 as of today).

于 2013-09-26T23:50:05.720 回答