在基于检测的跟踪框架(tracking-by-detection)下,为了方便研究者对比多目标跟踪方法的性能,多目标跟踪标准平台不仅提供了统一的验证视频,有时还提供某类检测方法在标准视频上检测结果。本文主要介绍了如何将多目标跟踪基准平台(Multiple Object Tracking Benchmark,https://motchallenge.net/)提供的DPM, Faster-RCNN, and SDP.检测结果可视化实时显示到对应的视频上,并提供相应代码。 首先介绍了用于行人多目标跟踪的MOT-17数据集提供的DPM, Faster-RCNN, and SDP三种方法对应的论文出处,以及用于车辆跟踪的UA-DETRAC 数据集提供的DPM, ACF, RCNN, and ComACT三种方法的论文出处。 然后下载MOT-17提供的检测结果和相应的视频,读取检测结果,解析后实时显示在视频上。具体过程下图所示:
MOT-17 提供 DPM, Faster-RCNN, and SDP.检测器在其数据集上的结果。
- DPM: Object detection with discriminatively trained part-based models. In TPAMI, 2010.【博客中文翻译】
- FRCNN:faster r-cnn: Towards Real-Time Object Detection with Region Proposal Networks. In NIPS, 2015
- SDP:Exploit All the Layers: Fast and Accurate CNN Object Detector With Scale Dependent Pooling and Cascaded Rejection Classifiers, In CVPR, 2016.
UA-DETRAC 提供以下检测方法在其数据集上的检测结果。
- DPM: Object detection with discriminatively trained part-based models. In TPAMI, 2010.【博客中文翻译】
- ACF: Fast feature pyramids for object detection. In TPAMI, 2014.
- R-CNN::Rich feature hierarchies for accurate object detection and semantic segmentation. In CVPR, 2014.
- CompACT: Learning complexity-aware cascades for deep pedestrian detection. In ICCV, 2015
【备用-论文网盘链接 提取码:eho6 】
Get detections and labels only (9.7 MB)
本文以下载 MOT17-04-SDP.mp4为例 :https://motchallenge.net/vis/MOT17-04-SDP。。也可下载整个MOT-17数据集
下载后,视频参数发生变化,与3.1中结果不相同,后续可视化需要修改代码:
#2019-04-29 Xingyu Zeng
import cv2
import numpy as np
def main():
video_path="MOT17-04-SDP.mp4"
vid=cv2.VideoCapture(video_path)
dets=load_mot("mot17/train/MOT17-04-SDP/det/det.txt")
for frame_num, detections_frame in enumerate(dets, start=1):
#读取视频
return_value,frame=vid.read()
for a in range(len(detections_frame)):
bbox=detections_frame[a]["bbox"]
print(frame_num,"bbox:x1, y1, x2, y2", bbox)
# rectangle(img, pt1, pt2, color, thickness=None, lineType=None, shift=None):
#将解析处理的矩形框,绘制在视频上,实时显示
cv2.rectangle(frame,bbox[:2],bbox[2:],(255,0,0),2)
cv2.imshow("frame", frame)
# 键盘控制视频播放 waitKey(x)控制视频显示速度
key=cv2.waitKey(100)& 0xFF
if key == ord(' '):
cv2.waitKey(0)
if key == ord('q'):
break
if __name__ == '__main__':
main()
其中解析函数load_mot,来自于AVSS2017多目标跟踪方法冠军【IOU-tracker】中ultil.py
def load_mot(detections):
"""
Loads detections stored in a mot-challenge like formatted CSV or numpy array (fieldNames = ['frame', 'id', 'x', 'y',
'w', 'h', 'score']).
Args:
detections
Returns:
list: list containing the detections for each frame.
"""
data = []
if type(detections) is str:
raw = np.genfromtxt(detections, delimiter=',', dtype=np.float32)
else:
# assume it is an array
assert isinstance(detections, np.ndarray), "only numpy arrays or *.csv paths are supported as detections."
raw = detections.astype(np.float32)
end_frame = int(np.max(raw[:, 0]))
for i in range(1, end_frame+1):
idx = raw[:, 0] == i
# print(i,idx)
bbox = raw[idx, 2:6]
bbox[:, 2:4] += bbox[:, 0:2] # x1, y1, w, h -> x1, y1, x2, y2
scores = raw[idx, 6]
dets = []
for bb, s in zip(bbox, scores):
#源代码没有除以2 由于下载的视频相较与标签分辨率缩小了一半,所以除以2
dets.append({'bbox': (int(bb[0]/2), int(bb[1]/2), int(bb[2]/2), int(bb[3]/2)), 'score': s})
data.append(dets)
return data