【发布时间】:2019-09-04 05:31:24
【问题描述】:
我已经使用 dlib 编写了一个 python 代码,但是由于项目规范,我需要用 C++ 重写相同的代码。几乎都完成了,但最重要的是我在 C++ 中找不到完全等价的。
python版本是:
[boxes, confidences, detector_idxs] = dlib.fhog_object_detector.run_multiple(detectors, image, upsample_num_times=1, adjust_threshold=0.0)
我尝试过的 C++ 是:
vector<rectangle> detection = evaluate_detectors(detectors, img, adjust_threshold);
我仍然没有运行代码,但我不确定我在 C++ 中使用的这个函数是否会像在 python 中一样返回三个信息(框、置信度、检测器 IDX),据我所见,我认为它只会返回盒子。
你知道我的做法是否正确吗?如何获取我需要的这三个信息?
编辑 01: 使用函数的错误:
tuple<std::vector<dlib::rectangle>, list<T> confidences>, list<T> detector_idxs> = run_multiple_rect_detectors(detectores, img, upsampling_amount, adjust_threshold);
error C2065: 'T': undeclared identifier
error C2923: 'std::list': 'T' is not a valid template type argument for parameter '_Ty'
error C2903: 'allocator': symbol is neither a class template nor a function template
error C3203: 'allocator': unspecialized class template can't be used as a template argument for template parameter '_Alloc', expected a real type
error C2146: syntax error: missing '>' before identifier 'confidences'
error C2059: syntax error: ','
编辑 01-1:
error C2872: 'rectangle': ambiguous symbol
note: could be 'dlib::rectangle'
note: or 'rectangle'
error C2146: syntax error: missing '>' before identifier 'rectangles'
error C2653: 'pybind11': is not a class or namespace name
error C3861: 'run_multiple_rect_detectors': identifier not found
修复VS显示的语法错误后:
error C3861: 'run_multiple_rect_detectors': identifier not found
编辑 02:
Error C2027 use of undefined type 'dlib::image_traits<image_type>'
Error C2146 syntax error: missing ';' before identifier 'pixel_type'
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int
【问题讨论】:
-
您可以检查 Python 绑定的源代码并查看它委托给什么。
-
你应该看看C++ HOG object detector example。对于 C++ 标准,它非常简单。
-
为什么要重写有效的代码?从 C++ 调用 python 代码。
-
我也在尝试在 C++ 中使用 FHOG,但是我在变量类型方面遇到了一些问题,它不像在 python 中那么容易
-
@NicolasZ。 DLib 是一个高度模板化的库。我建议先看看 C++ 模板。 C++ 与 Python 大不相同。