2016-05-31 81 views
0

我是使用HOG檢測器在路上檢測人類的新手段,我已經編寫了代碼並嘗試運行它,但它總是在這一行上有錯誤:「豬.setSVMDetector(HOGDescriptor :: getDefaultPeopleDetector());」這一行,任何人都可以告訴我我的代碼有什麼問題嗎?使用HOG描述符進行人體檢測

#include < stdio.h> 
    #include < iostream> 
    #include < opencv2\opencv.hpp> 
    #include < opencv2/core/core.hpp> 
    #include < opencv2/highgui/highgui.hpp> 
    #include < opencv2/video/background_segm.hpp> 
    #include <opencv2/imgproc.hpp> 
    #include <opencv2/objdetect.hpp> 
    #include <peopledetect.cpp> 

    using namespace cv; 
    using namespace std; 

    int main(int argc, const char * argv[]) 
    { 
     VideoCapture cap(0); 
     cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); 
     cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); 

     if (!cap.isOpened()) 
      return -1; 

     Mat img; 
     namedWindow("opencv", CV_WINDOW_AUTOSIZE); 
     HOGDescriptor hog; 
     hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); 

     while (true) 
     { 
      cap >> img; 
      if (img.empty()) 
       continue; 

      vector<Rect> found, found_filtered; 
      hog.detectMultiScale(img, found, 0, Size(8, 8), Size(32, 32), 1.05, 2); 
      size_t i, j; 
      for (i = 0; i<found.size(); i++) 
      { 
       Rect r = found[i]; 
       for (j = 0; j<found.size(); j++) 
        if (j != i && (r & found[j]) == r) 
         break; 
       if (j == found.size()) 
        found_filtered.push_back(r); 
      } 

      for (i = 0; i<found_filtered.size(); i++) 
      { 
       Rect r = found_filtered[i]; 
       r.x += cvRound(r.width*0.1); 
       r.width = cvRound(r.width*0.8); 
       r.y += cvRound(r.height*0.07); 
       r.height = cvRound(r.height*0.8); 
       rectangle(img, r.tl(), r.br(), Scalar(0, 255, 0), 3); 
      } 

      imshow("opencv", img); 
      waitKey(1); 
     } 
     return 0; 
    } 
+0

它說:「異常情況:0xC0000005:讀取0xFFFFFFFFFFFF違規」 – HenryChen

+0

我不知道是否有任何進一步的步驟我需要做,如「getDefaultPeopleDetector()」需要初始化或什麼? – HenryChen

回答

1

一般來說,你不應該在C++程序中包含.cpp文件。有.h和.hpp標題。

現在,對於您的特定問題,如果我們討論的是相同的peopledetect.cpp,那麼您所需要的函數沒有在那裏定義,而是包含在其中的頭文件中...您可能已經有了正確的頭文件(objdetect。 hpp)所以只需刪除#include <peopledetect.cpp>

+0

但刪除cpp文件後,錯誤仍然存​​在,我的輸入格式有什麼問題嗎? – HenryChen

+0

@HenryChen仍然在同一行上的錯誤? – Sunreef

+0

是的,它與使用getDefaultPeopleDetector()完全相同 – HenryChen