2013-11-23 36 views
0

我試圖使用opencvOpenCV的 - 程序停止運行@檢測圖像步驟關鍵點

我開始通過測試關鍵點檢測功能開發C++實現視覺關鍵詞袋的,但是當我插入該指令

detector->detect(img, keypoints);,程序停止不引發任何異常運行@第一張圖像。

任何一個可以幫助我如何解決這個問題?

感謝

void extractTrainingVocabulary(const path& basepath) { 
for (directory_iterator iter = directory_iterator(basepath); iter 
     != directory_iterator(); iter++) { 
    directory_entry entry = *iter; 

    if (is_directory(entry.path())) { 

     cout << "Processing directory " << entry.path().string() << endl; 
     extractTrainingVocabulary(entry.path()); 

    } else { 

     path entryPath = entry.path(); 
     if (entryPath.extension() == ".jpg") { 

      cout << "Processing file " << entryPath.string() << endl; 

      Mat img = imread(entryPath.string()); 
      if (!img.empty()) 
      { 

       cout << "not empty"<< endl; 


       try{ 
        // ... 
        vector<KeyPoint> keypoints; 
        cout << "not empty"<< keypoints.empty()<<endl; 
        //detector->detect(img, keypoints); 
       } catch (const std::exception& ex) { 
       } 



      } 
      else 
      { 
       cout << " empty"<< endl; 

      } 
     } 
    } 
} 
} 

回答

1

要假定detector->檢測()的代碼功能實際上是不是在你實現註釋掉。我唯一的猜測就是img.empty()函數沒有返回正確的值。檢查以查看是否有圖像加載正確使用image.data數據成員,作爲這樣的OpenCV的方法:

if(! image.data) // Check for invalid input 
{ 
    cout << "Could not open or find the image" << std::endl ; 
    return -1; 
}