2013-09-26 71 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)。