我在 Mac OS X 10.8 上运行 OpenCV 2.4.3。我正在尝试使用 cv::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
出了什么问题?我似乎无法从gdb
orlldb
输出中获得任何新信息。我正在使用 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