gpt4 book ai didi

c++ - OpenCV HOGDescriptor 错误

转载 作者:IT老高 更新时间:2023-10-28 23:01:00 24 4
gpt4 key购买 nike

我在 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

出了什么问题?我似乎无法从 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

最佳答案

我无法追查到底为什么会发生此错误。但是它与 XML HOG 级联文件如何加载到内存中有关。

我已将此问题报告为 OpenCV 问题跟踪器中的一个错误,正在等待开发人员的回复。

暂时,我对这个问题的解决方法是像这样直接在cv::HOGDescriptor类中设置SVM参数

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

这似乎适用于 Mac OSX 和 OpenCV 2.4.3 的 linux 版本

关于c++ - OpenCV HOGDescriptor 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14305971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com