2013-09-26 73 views
1

我在OpenCV中编写了一个简单的程序,用于检测给定图像中的SURF特征,并将检测到的特征插入到namedWindow中。SURF检测后OpenCV崩溃

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

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

回答

0

它不会崩溃,我......但我为了编译代码,我不得不添加

#include <opencv2/nonfree/features2d.hpp> 

因为SURF被转移到在某些时候的非免费模块。

所以,我不得不推荐尝试最新的版本(截至今日2.4.6)。