如何跟踪 YOLOv3 产生的输出?

How to track output produced by YOLOv3?

美好的一天,

我使用 YOLOv3 模型只检测场景中出现的人体物体。基本上,YOLO 模型试图在每一帧中检测人体对象,尽管它看起来像跟踪,因为边界框不断移动。

我正在寻找一种可行的方法来跟踪每个检测到的人体物体,方法是为每个人体物体分配一个标识符。 (请参阅提供的图片)

以下代码用于根据左、上、右、下绘制边界框,即x、宽度、y、高度。我可以为每个检测到的人体对象分配一个标识符吗?

例如将 ID_1 分配给检测到的 "person:0.73",同时将 ID_2 分配给 "person:1.00"

非常感谢您的帮助和时间,谢谢。

正在尝试为每个检测到的人分配一个标识符

def drawPred(classId, conf, left, top, right, bottom):
    # Draw a bounding box.
    cv2.rectangle(resized_frame, (left, top), (right, bottom), (255,0,255), 5)

label = '%.2f' % conf # Get the label for the class name and its confidence if classes: assert(classId < len(classes)) label = '%s:%s' % (classes[classId], label) #Display the label at the top of the bounding box labelSize, baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 1) top = max(top, labelSize[1]) - 5 cv2.putText(resized_frame, label, (left, top), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,255), 2)

如果 C++ 实现没问题,您可能想使用这个流行的 github 存储库 https://github.com/AlexeyAB/darknet

如果您阅读文档,它有 C++ API,您可以将 darknet 用作库(因此您可以使用您的 yolo 模型)并将其加载到您的 C++ 程序中。在此处查看使用 darknet 库的 C++ 程序示例 https://github.com/AlexeyAB/darknet/blob/master/src/yolo_console_dll.cpp .

在该 C++ 代码中,作者提供了 3 个选项来进行对象跟踪:

  1. Track Optical Flow算法,但只对活体检测有效,对视频无效。您可以通过取消注释此行 //#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. 卡尔曼滤波器,不推荐使用,因为它不是很准确,但可能适用于闭路电视或固定摄像机。要使用卡尔曼滤波器,请将此值更改为真 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. Custom Object Tracker,我使用了这个自定义函数,在我的例子中它比卡尔曼滤波器表现更好,它会给你每个对象的跟踪 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);
                        }