首页 > 解决方案 > 如何将卡尔曼滤波器添加到 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);

标签: windowsvisual-studio-2017kalman-filteryolo

解决方案


使用卡尔曼滤波器的目的是用于对象跟踪(不确定用于平滑)。如果 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 个是使用卡尔曼滤波器:

  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
  1. 卡尔曼滤波器,不是很推荐,因为它不是很准确,但可能适用于闭路电视或固定摄像机。要使用卡尔曼滤波器,请将此值更改为 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();
                            }
                        }
  1. 自定义对象跟踪器,我使用了这个自定义函数,在我的例子中它比卡尔曼滤波器执行得更好,它会为你提供每个对象的跟踪 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);
                        }

推荐阅读