def draw_tracks(self, out, colored=False, color_type='unique', min_track_length=4, max_track_length=4): """ color_type: {age, unique} """ N = 20 # inds = self.confident_tracks(min_length=min_track_length) # if not len(inds): # return # ids, pts = self.latest_ids[inds], self.latest_pts[inds] # lengths = self.tm_.lengths[inds] ids, pts, lengths = self.latest_ids, self.latest_pts, self.tm_.lengths if color_type == 'unique': cwheel = colormap(np.linspace(0, 1, N)) cols = np.vstack([cwheel[tid % N] for idx, tid in enumerate(ids)]) elif color_type == 'age': cols = colormap(lengths) else: raise ValueError('Color type {:} undefined, use age or unique'.format(color_type)) if not colored: cols = np.tile([0,240,0], [len(self.tm_.tracks), 1]) for col, pts in izip(cols.astype(np.int64), self.tm_.tracks.itervalues()): cv2.polylines(out, [np.vstack(pts.items).astype(np.int32)[-max_track_length:]], False, tuple(col), thickness=1) tl, br = np.int32(pts.latest_item)-2, np.int32(pts.latest_item)+2 cv2.rectangle(out, (tl[0], tl[1]), (br[0], br[1]), tuple(col), -1)
def draw_bboxes(vis, bboxes, texts=None, ellipse=False, colored=True): if not len(bboxes): return vis if not colored: cols = np.tile([240, 240, 240], [len(bboxes), 1]) else: N = 20 cwheel = colormap(np.linspace(0, 1, N)) cols = np.vstack([cwheel[idx % N] for idx, _ in enumerate(bboxes)]) texts = [None] * len(bboxes) if texts is None else texts for col, b, t in zip(cols, bboxes, texts): if ellipse: cv2.ellipse(vis, ((b[0] + b[2]) / 2, (b[1] + b[3]) / 2), ((b[2] - b[0]) / 2, (b[3] - b[1]) / 2), 0, 0, 360, color=tuple(col), thickness=1) else: cv2.rectangle(vis, (b[0], b[1]), (b[2], b[3]), tuple(col), 2) if t: annotate_bbox(vis, b, title=t) return vis
def visualize(self, out, colored=False): if not len(self.latest_pts): return N = 20 cols = colormap(np.linspace(0, 1, N)) valid = finite_and_within_bounds(self.latest_pts, out.shape) for tid, pt in izip(self.latest_ids[valid], self.latest_pts[valid]): cv2.rectangle(out, tuple(map(int, pt-2)), tuple(map(int, pt+2)), tuple(map(int, cols[tid % N])) if colored else (0,240,0), -1) return out