windows - 如何将卡尔曼滤波器添加到 YOLO v2
问题描述
我想通过将卡尔曼滤波器添加到 YOLO 来使人员检测变得顺畅。
在另一篇文章中,我注意到*(请参见下面 image.c 文件中的代码)如何在 YOLO 中获取边界框的坐标。
if(bot > im.h-1) bot = im.h-1;
// Print bounding box values
printf("Bounding Box: Left=%d, Top=%d, Right=%d, Bottom=%d\n", left, top, right, bot);
draw_box_width(im, left, top, right, bot, width, red, green, blue);
解决方案
使用卡尔曼滤波器的目的是用于对象跟踪(不确定用于平滑)。如果 C++ 实现没问题,您可能想使用这个流行的 github 存储库https://github.com/AlexeyAB/darknet
如果您阅读文档,它有 C++ API,您可以将暗网用作库(因此您可以使用您的 yolo 模型)并将其加载到您的 C++ 程序中。在此处查看使用暗网库的 C++ 程序示例https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp。
在那个 C++ 代码中,作者提供了 3 个选项来进行对象跟踪,其中 1 个是使用卡尔曼滤波器:
- 跟踪光流算法,但它仅适用于实时检测,不适用于视频。您可以通过取消注释此行来使用该算法
//#define TRACK_OPTFLOW
。看看508~522行
#ifdef TRACK_OPTFLOW
if (detection_data.new_detection) {
tracker_flow.update_tracking_flow(detection_data.cap_frame, detection_data.result_vec);
while (track_optflow_queue.size() > 0) {
draw_frame = track_optflow_queue.back();
result_vec = tracker_flow.tracking_flow(track_optflow_queue.front(), false);
track_optflow_queue.pop();
}
}
else {
track_optflow_queue.push(cap_frame);
result_vec = tracker_flow.tracking_flow(cap_frame, false);
}
detection_data.new_detection = true; // to correct kalman filter
#endif //TRACK_OPTFLOW
- 卡尔曼滤波器,不是很推荐,因为它不是很准确,但可能适用于闭路电视或固定摄像机。要使用卡尔曼滤波器,请将此值更改为 true
bool const use_kalman_filter = false;
。看看524~532行
// track ID by using kalman filter
if (use_kalman_filter) {
if (detection_data.new_detection) {
result_vec = track_kalman.correct(result_vec);
}
else {
result_vec = track_kalman.predict();
}
}
- 自定义对象跟踪器,我使用了这个自定义函数,在我的例子中它比卡尔曼滤波器执行得更好,它会为你提供每个对象的跟踪 ID。
// track ID by using custom function
else {
int frame_story = std::max(5, current_fps_cap.load());
result_vec = detector.tracking_id(result_vec, true, frame_story, 40);
}
推荐阅读
- postgresql - 如何优化一个依赖列是时间戳的 postgresql 查询
- c# - 是否可以使用 OR 条件(如角色)进行索赔授权?
- java - 启用 SSL 的 kafka 配置:错误:在创建地图/配置时找不到合适的方法
- excel - 单变量类型数组给出转录错误?
- android - 如何将 3 个数据库合并为一个并在 ListView 上显示;
- java - 对 DITA OT 进行并发 ant 调用的 Isuee
- json - 当我从 json 打印一些数据时出现此错误:列表
' 不是类型 'Map 的子类型 - angular - Angular7 child1 到 parent - parent 到 child2 通信错误
- angular - 角度 + IIS + 国际化刷新/缓存问题
- ios - UITextField 不可编辑,只有触摸事件,没有编辑事件