9 from application_util
import visualization
12 DEFAULT_UPDATE_MS = 20
15 def run(sequence_dir, result_file, show_false_alarms=False, detection_file=None,
16 update_ms=
None, video_filename=
None):
17 """Run tracking result visualization. 22 Path to the MOTChallenge sequence directory. 24 Path to the tracking output file in MOTChallenge ground truth format. 25 show_false_alarms : Optional[bool] 26 If True, false alarms are highlighted as red boxes. 27 detection_file : Optional[str] 28 Path to the detection file. 29 update_ms : Optional[int] 30 Number of milliseconds between cosecutive frames. Defaults to (a) the 31 frame rate specifid in the seqinfo.ini file or DEFAULT_UDPATE_MS ms if 32 seqinfo.ini is not available. 33 video_filename : Optional[Str] 34 If not None, a video of the tracking results is written to this file. 38 results = np.loadtxt(result_file, delimiter=
',')
40 if show_false_alarms
and seq_info[
"groundtruth"]
is None:
41 raise ValueError(
"No groundtruth available. Cannot show false alarms.")
43 def frame_callback(vis, frame_idx):
44 print(
"Frame idx", frame_idx)
46 seq_info[
"image_filenames"][frame_idx], cv2.IMREAD_COLOR)
48 vis.set_image(image.copy())
50 if seq_info[
"detections"]
is not None:
52 seq_info[
"detections"], frame_idx)
53 vis.draw_detections(detections)
55 mask = results[:, 0].astype(np.int) == frame_idx
56 track_ids = results[mask, 1].astype(np.int)
57 boxes = results[mask, 2:6]
58 vis.draw_groundtruth(track_ids, boxes)
61 groundtruth = seq_info[
"groundtruth"]
62 mask = groundtruth[:, 0].astype(np.int) == frame_idx
63 gt_boxes = groundtruth[mask, 2:6]
68 if iou(box, gt_boxes).max() < min_iou_overlap:
69 vis.viewer.color = 0, 0, 255
70 vis.viewer.thickness = 4
71 vis.viewer.rectangle(*box.astype(np.int))
74 update_ms = seq_info[
"update_ms"]
76 update_ms = DEFAULT_UPDATE_MS
77 visualizer = visualization.Visualization(seq_info, update_ms)
78 if video_filename
is not None:
79 visualizer.viewer.enable_videowriter(video_filename)
80 visualizer.run(frame_callback)
84 """ Parse command line arguments. 86 parser = argparse.ArgumentParser(description=
"Siamese Tracking")
88 "--sequence_dir", help=
"Path to the MOTChallenge sequence directory.",
89 default=
None, required=
True)
91 "--result_file", help=
"Tracking output in MOTChallenge file format.",
92 default=
None, required=
True)
94 "--detection_file", help=
"Path to custom detections (optional).",
97 "--update_ms", help=
"Time between consecutive frames in milliseconds. " 98 "Defaults to the frame_rate specified in seqinfo.ini, if available.",
101 "--output_file", help=
"Filename of the (optional) output video.",
104 "--show_false_alarms", help=
"Show false alarms as red bounding boxes.",
105 type=bool, default=
False)
106 return parser.parse_args()
109 if __name__ ==
"__main__":
112 args.sequence_dir, args.result_file, args.show_false_alarms,
113 args.detection_file, args.update_ms, args.output_file)
def iou(bbox, candidates)
def create_detections(detection_mat, frame_idx, min_height=0)
def run(sequence_dir, result_file, show_false_alarms=False, detection_file=None, update_ms=None, video_filename=None)
def gather_sequence_info(sequence_dir, detection_file)