show_results.py
Go to the documentation of this file.
1 # vim: expandtab:ts=4:sw=4
2 import argparse
3 
4 import cv2
5 import numpy as np
6 
7 import deep_sort_app
8 from deep_sort.iou_matching import iou
9 from application_util import visualization
10 
11 
12 DEFAULT_UPDATE_MS = 20
13 
14 
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.
18 
19  Parameters
20  ----------
21  sequence_dir : str
22  Path to the MOTChallenge sequence directory.
23  result_file : str
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.
35 
36  """
37  seq_info = deep_sort_app.gather_sequence_info(sequence_dir, detection_file)
38  results = np.loadtxt(result_file, delimiter=',')
39 
40  if show_false_alarms and seq_info["groundtruth"] is None:
41  raise ValueError("No groundtruth available. Cannot show false alarms.")
42 
43  def frame_callback(vis, frame_idx):
44  print("Frame idx", frame_idx)
45  image = cv2.imread(
46  seq_info["image_filenames"][frame_idx], cv2.IMREAD_COLOR)
47 
48  vis.set_image(image.copy())
49 
50  if seq_info["detections"] is not None:
52  seq_info["detections"], frame_idx)
53  vis.draw_detections(detections)
54 
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)
59 
60  if show_false_alarms:
61  groundtruth = seq_info["groundtruth"]
62  mask = groundtruth[:, 0].astype(np.int) == frame_idx
63  gt_boxes = groundtruth[mask, 2:6]
64  for box in boxes:
65  # NOTE(nwojke): This is not strictly correct, because we don't
66  # solve the assignment problem here.
67  min_iou_overlap = 0.5
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))
72 
73  if update_ms is None:
74  update_ms = seq_info["update_ms"]
75  if update_ms is None:
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)
81 
82 
83 def parse_args():
84  """ Parse command line arguments.
85  """
86  parser = argparse.ArgumentParser(description="Siamese Tracking")
87  parser.add_argument(
88  "--sequence_dir", help="Path to the MOTChallenge sequence directory.",
89  default=None, required=True)
90  parser.add_argument(
91  "--result_file", help="Tracking output in MOTChallenge file format.",
92  default=None, required=True)
93  parser.add_argument(
94  "--detection_file", help="Path to custom detections (optional).",
95  default=None)
96  parser.add_argument(
97  "--update_ms", help="Time between consecutive frames in milliseconds. "
98  "Defaults to the frame_rate specified in seqinfo.ini, if available.",
99  default=None)
100  parser.add_argument(
101  "--output_file", help="Filename of the (optional) output video.",
102  default=None)
103  parser.add_argument(
104  "--show_false_alarms", help="Show false alarms as red bounding boxes.",
105  type=bool, default=False)
106  return parser.parse_args()
107 
108 
109 if __name__ == "__main__":
110  args = parse_args()
111  run(
112  args.sequence_dir, args.result_file, args.show_false_alarms,
113  args.detection_file, args.update_ms, args.output_file)
def parse_args()
Definition: show_results.py:83
def iou(bbox, candidates)
Definition: iou_matching.py:7
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)
Definition: show_results.py:16
def gather_sequence_info(sequence_dir, detection_file)


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27