Question

I wrote a simple program in OpenCV that detects SURF feature in a given image and diplays the detected features in a namedWindow.

#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;
}

Everything is OK, the programs do what it have to do. The problem is when pressing a key to terminate the program a crash error occurs.

Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top