visualization.py
Go to the documentation of this file.
1 # vim: expandtab:ts=4:sw=4
2 import numpy as np
3 import colorsys
4 from .image_viewer import ImageViewer
5 
6 
7 def create_unique_color_float(tag, hue_step=0.41):
8  """Create a unique RGB color code for a given track id (tag).
9 
10  The color code is generated in HSV color space by moving along the
11  hue angle and gradually changing the saturation.
12 
13  Parameters
14  ----------
15  tag : int
16  The unique target identifying tag.
17  hue_step : float
18  Difference between two neighboring color codes in HSV space (more
19  specifically, the distance in hue channel).
20 
21  Returns
22  -------
23  (float, float, float)
24  RGB color code in range [0, 1]
25 
26  """
27  h, v = (tag * hue_step) % 1, 1. - (int(tag * hue_step) % 4) / 5.
28  r, g, b = colorsys.hsv_to_rgb(h, 1., v)
29  return r, g, b
30 
31 
32 def create_unique_color_uchar(tag, hue_step=0.41):
33  """Create a unique RGB color code for a given track id (tag).
34 
35  The color code is generated in HSV color space by moving along the
36  hue angle and gradually changing the saturation.
37 
38  Parameters
39  ----------
40  tag : int
41  The unique target identifying tag.
42  hue_step : float
43  Difference between two neighboring color codes in HSV space (more
44  specifically, the distance in hue channel).
45 
46  Returns
47  -------
48  (int, int, int)
49  RGB color code in range [0, 255]
50 
51  """
52  r, g, b = create_unique_color_float(tag, hue_step)
53  return int(255*r), int(255*g), int(255*b)
54 
55 
57  """
58  A dummy visualization object that loops through all frames in a given
59  sequence to update the tracker without performing any visualization.
60  """
61 
62  def __init__(self, seq_info):
63  self.frame_idx = seq_info["min_frame_idx"]
64  self.last_idx = seq_info["max_frame_idx"]
65 
66  def set_image(self, image):
67  pass
68 
69  def draw_groundtruth(self, track_ids, boxes):
70  pass
71 
72  def draw_detections(self, detections):
73  pass
74 
75  def draw_trackers(self, trackers):
76  pass
77 
78  def run(self, frame_callback):
79  while self.frame_idx <= self.last_idx:
80  frame_callback(self, self.frame_idx)
81  self.frame_idx += 1
82 
83 
85  """
86  This class shows tracking output in an OpenCV image viewer.
87  """
88 
89  def __init__(self, seq_info, update_ms):
90  image_shape = seq_info["image_size"][::-1]
91  aspect_ratio = float(image_shape[1]) / image_shape[0]
92  image_shape = 1024, int(aspect_ratio * 1024)
93  self.viewer = ImageViewer(
94  update_ms, image_shape, "Figure %s" % seq_info["sequence_name"])
95  self.viewer.thickness = 2
96  self.frame_idx = seq_info["min_frame_idx"]
97  self.last_idx = seq_info["max_frame_idx"]
98 
99  def run(self, frame_callback):
100  self.viewer.run(lambda: self._update_fun(frame_callback))
101 
102  def _update_fun(self, frame_callback):
103  if self.frame_idx > self.last_idx:
104  return False # Terminate
105  frame_callback(self, self.frame_idx)
106  self.frame_idx += 1
107  return True
108 
109  def set_image(self, image):
110  self.viewer.image = image
111 
112  def draw_groundtruth(self, track_ids, boxes):
113  self.viewer.thickness = 2
114  for track_id, box in zip(track_ids, boxes):
115  self.viewer.color = create_unique_color_uchar(track_id)
116  self.viewer.rectangle(*box.astype(np.int), label=str(track_id))
117 
118  def draw_detections(self, detections):
119  self.viewer.thickness = 2
120  self.viewer.color = 0, 0, 255
121  for i, detection in enumerate(detections):
122  self.viewer.rectangle(*detection.tlwh)
123 
124  def draw_trackers(self, tracks):
125  self.viewer.thickness = 2
126  for track in tracks:
127  if not track.is_confirmed() or track.time_since_update > 0:
128  continue
129  self.viewer.color = create_unique_color_uchar(track.track_id)
130  self.viewer.rectangle(
131  *track.to_tlwh().astype(np.int), label=str(track.track_id))
132  # self.viewer.gaussian(track.mean[:2], track.covariance[:2, :2],
133  # label="%d" % track.track_id)
134 #
def __init__(self, seq_info, update_ms)
def create_unique_color_uchar(tag, hue_step=0.41)
def draw_groundtruth(self, track_ids, boxes)
def create_unique_color_float(tag, hue_step=0.41)
Definition: visualization.py:7
def draw_groundtruth(self, track_ids, boxes)


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