-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracker_dev.py
executable file
·118 lines (92 loc) · 4.15 KB
/
tracker_dev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import glob
import time
import numpy as np
import cv2
import pickle
from tqdm import tqdm
import motmetrics as mm
from mvt.utils import draw_motion_vectors, draw_boxes, draw_box_ids, draw_shifts
from mvt.tracker import MotionVectorTracker
from config import Config
output_graphics = True
if __name__ == "__main__":
acc = mm.MOTAccumulator(auto_id=True)
tracker = MotionVectorTracker(iou_threshold=Config.TRACKER_IOU_THRES)
step_wise = False
# box colors
color_detection = (0, 0, 150)
color_tracker = (0, 0, 255)
color_gt = (0, 255, 0)
#color_previous = (150, 255, 0)
if output_graphics:
cv2.namedWindow("Frame", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Frame", 640, 360)
dev_outputs = sorted(glob.glob("dev_output/*.pkl"))
with tqdm(total=len(dev_outputs)) as pbar:
for frame_idx, dev_output in enumerate(dev_outputs):
data = pickle.load(open(dev_output, "rb"))
frame = data["frame"]
frame_type = data["frame_type"]
det_boxes = data["det_boxes"]
gt_boxes = data["gt_boxes"]
gt_ids = data["gt_ids"]
motion_vectors = data["motion_vectors"]
if output_graphics:
# draw entire field of motion vectors
frame = draw_motion_vectors(frame, motion_vectors, color=(0, 0, 255))
# draw info
frame = cv2.putText(frame, "Frame Type: {}".format(frame_type), (1000, 25), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), 2, cv2.LINE_AA)
frame = cv2.putText(frame, "Step: {}".format(frame_idx), (1000, 60), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (255, 255, 255), 2, cv2.LINE_AA)
# draw color legend
frame = cv2.putText(frame, "Last Detection", (15, 25), cv2.FONT_HERSHEY_SIMPLEX, 1.0, color_detection, 2, cv2.LINE_AA)
frame = cv2.putText(frame, "Tracker Prediction", (15, 60), cv2.FONT_HERSHEY_SIMPLEX, 1.0, color_tracker, 2, cv2.LINE_AA)
frame = cv2.putText(frame, "Groundtruth", (15, 95), cv2.FONT_HERSHEY_SIMPLEX, 1.0, color_gt, 2, cv2.LINE_AA)
# update with detections
if frame_idx % Config.DETECTOR_INTERVAL == 0:
tracker.update(motion_vectors, frame_type, det_boxes)
# prediction by tracker
else:
tracker.predict(motion_vectors, frame_type)
track_boxes = tracker.get_boxes()
track_ids = tracker.get_box_ids()
shifts = tracker.get_shifts()
dist = mm.distances.iou_matrix(gt_boxes, track_boxes, max_iou=0.5)
acc.update(gt_ids, track_ids, dist)
frame_idx += 1
if output_graphics:
frame = draw_boxes(frame, det_boxes, color=color_detection)
frame = draw_boxes(frame, track_boxes, color=color_tracker)
frame = draw_boxes(frame, gt_boxes, color=color_gt)
frame = draw_shifts(frame, shifts, track_boxes)
frame = draw_box_ids(frame, track_boxes, track_ids)
frame = draw_box_ids(frame, det_boxes, range(len(det_boxes)))
cv2.imshow("Frame", frame)
# handle key presses
# 'q' - Quit the running program
# 's' - enter stepwise mode
# 'a' - exit stepwise mode
key = cv2.waitKey(1)
if not step_wise and key == ord('s'):
step_wise = True
if key == ord('q'):
break
if step_wise:
while True:
key = cv2.waitKey(1)
if key == ord('s'):
break
elif key == ord('a'):
step_wise = False
break
pbar.update()
if output_graphics:
cv2.destroyAllWindows()
mh = mm.metrics.create()
summary = mh.compute(acc, metrics=mm.metrics.motchallenge_metrics)
strsummary = mm.io.render_summary(
summary,
formatters=mh.formatters,
namemap=mm.io.motchallenge_metric_names
)
print(strsummary)