如何跟踪YOLOv3产生的输出?

时间:2019-06-27 20:09:51

标签: python opencv yolo

美好的一天

我已经使用YOLOv3模型检测到只有人类物体出现在场景中。基本上,YOLO模型会尝试检测每一帧中的人体对象,尽管由于边界框不断移动,所以它看起来像是在跟踪。

我正在寻找一种可行的方法,通过为每个人类对象分配一个标识符来跟踪每个人类对象。 (请参阅提供的图像)

以下代码用于根据左侧,顶部,右侧,底部绘制边框,这表示x,宽度,y,高度。我可以为每个检测到的人体分配一个标识符吗?

例如将ID_1分配给检测到的“人员:0.73”,将ID_2分配给“人员:1.00”

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

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

Trying to assign an identifier to each detected person

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)

1 个答案:

答案 0 :(得分:0)

如果可以使用C ++实现,则可能要使用这个流行的github存储库https://github.com/AlexeyAB/darknet

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

在该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
  1. 卡尔曼滤镜,不建议使用,因为它并不十分准确,但可能适用于CCTV或固定摄像机。要使用卡尔曼滤波器,请将此值更改为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);
                        }
相关问题