2013-01-13 124 views
13

我在Mac OS X 10.8上運行OpenCV 2.4.3。 我正在嘗試使用cv :: HOGDescriptor來獲取視頻序列中的行人。OpenCV HOGDescriptor錯誤

這是我用來做檢測和繪製邊界框的代碼。

cv::VideoCapture input("file.avi"); 
    assert(input.isOpened()); 
    cv::HOGDescriptor body; 
    assert(body.load("hogcascade_pedestrians.xml")); 
    cv::Mat frame, gray; 
    cv::namedWindow("video"); 

    while (input.read(frame)) { 
    vector<cv::Rect> rects; 
    cv::cvtColor(frame, gray, cv::COLOR_RGB2GRAY); 
    cv::equalizeHist(gray, gray); 

    body.detectMultiScale(gray, rects); 
    for (unsigned int i=0;i<rects.size();i++) { 
     cv::rectangle(frame, cv::Point(rects[i].x, rects[i].y), 
      cv::Point(rects[i].x+rects[i].width, rects[i].y+rects[i].height), 
      cv::Scalar(255, 0, 255)); 
    } 
    cv::imshow("video", frame); 
    } 

然而,當執行到達行body.detectMultiScale(gray, rects);,我得到了一個錯誤,整個應用程序崩潰

libc++abi.dylib: terminate called throwing an exception 
[1] 92156 abort  ../bin/DetectPedestrians 

到底哪裏出問題了?我似乎無法從gdblldb輸出中獲得任何新信息。我正在用CMake編譯代碼進行編譯,所以我想這不是連接問題。

下面是從崩潰的線程堆棧跟蹤 -

Thread 0 Crashed:: Dispatch queue: com.apple.root.default-priority 
0 libsystem_kernel.dylib   0x00007fff8c001212 __pthread_kill + 10 
1 libsystem_c.dylib    0x00007fff8e7afaf4 pthread_kill + 90 
2 libsystem_c.dylib    0x00007fff8e7f3dce abort + 143 
3 libc++abi.dylib     0x00007fff94096a17 abort_message + 257 
4 libc++abi.dylib     0x00007fff940943c6 default_terminate() + 28 
5 libobjc.A.dylib     0x00007fff8e11f887 _objc_terminate() + 111 
6 libc++.1.dylib     0x00007fff96b0b8fe std::terminate() + 20 
7 libobjc.A.dylib     0x00007fff8e11f5de objc_terminate + 9 
8 libdispatch.dylib    0x00007fff8c4ecfa0 _dispatch_client_callout2 + 28 
9 libdispatch.dylib    0x00007fff8c4ed686 _dispatch_apply_serial + 28 
10 libdispatch.dylib    0x00007fff8c4e80b6 _dispatch_client_callout + 8 
11 libdispatch.dylib    0x00007fff8c4ebae8 _dispatch_sync_f_invoke + 39 
12 libopencv_core.2.4.3.dylib  0x0000000101d5d900 cv::parallel_for_(cv::Range const&, cv::ParallelLoopBody const&, double) + 116 
13 libopencv_objdetect.2.4.3.dylib 0x000000010257fa21 cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, std::vector<double, std::allocator<double> >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const + 559 
14 libopencv_objdetect.2.4.3.dylib 0x000000010257fdc2 cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const + 80 
15 DetectPedestrians    0x0000000101a7886c main + 2572 (detect.cpp:41) 
16 libdyld.dylib     0x00007fff8d89f7e1 start + 1 

在Linux系統上,同樣的代碼給了我一個錯誤說 -

OpenCV Error: Assertion failed (dsize.area() || (inv_scale_x > 0 && inv_scale_y > 0)) in resize, file /home/subho/OpenCV/OpenCV-2.4.3/modules/imgproc/src/imgwarp.cpp, line 1726 
terminate called after throwing an instance of 'tbb::captured_exception' 
    what(): /home/subho/OpenCV/OpenCV-2.4.3/modules/imgproc/src/imgwarp.cpp:1726: error: (-215) dsize.area() || (inv_scale_x > 0 && inv_scale_y > 0) in function resize 

回答

7

我還沒有能夠追查爲什麼確切發生此錯誤。但是,它與XML HOG級聯文件如何加載到內存中有關。

我已經報告過這是OpenCV問題跟蹤器中的一個錯誤,我正在等待開發人員回覆。

暫時,我對這個問題的解決方法是直接設置SVM參數在cv::HOGDescriptor類,像這樣

cv::HOGDescriptor human; 
human.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector()); 

這似乎是工作在Mac OSX和OpenCV 2.4.3的Linux版本都

4

我不是這方面的專家區域,但我認爲你得到斷言失敗的錯誤造成大小錯配問題的原因。我會建議用一些預先確定的大小來啓動rects,看看你是否得到相同的錯誤。 希望這有助於

-1

我有同樣的問題,像你在這裏:HOGDescriptor Error and Assertion Failed

,但嘗試了這一點!

改變你的...

cv::HOGDescriptor body; 

到...

cv::CascadeClassifier body; 

它就像一個魅力!它可以檢測到行人! :)

但還有另一個問題,這個程序運行緩慢!很厲害! :))

+0

但他們是算法非常不同的事情正確嗎? – subzero

+0

是,請查看以獲取更多關於HOGDescriptor的信息:http://docs.opencv.org/modules/gpu/doc/object_detection.html我認爲您需要將您的所有代碼更改爲使用HOGDescriptor。 :) – Shabanzo

+0

這甚至不是相同的算法。 OP要求使用HOGDescriptor。 –