Bounding Boxes & Trajectories

Tracking-by-detection results can be visualized via draw_bounding_box_2d() and draw_trajectory(). For example:

Tracking-by-Detection Example

This visualization has been created with the following Python code:

 1painter.set_canvas_filename(VIREN2D_DATA_PATH / 'ninja.jpg')
 2
 3# Create a customized bounding box style
 4line_style = viren2d.LineStyle(width=4, color='navy-blue!80')
 5
 6text_style = viren2d.TextStyle(
 7    family='xkcd', size=18, color='navy-blue', halign='center')
 8
 9bbox_style = viren2d.BoundingBox2DStyle(
10    line_style=line_style, text_style=text_style,
11    box_fill_color = 'same!15', text_fill_color = 'white!60')
12
13# Draw the bounding box containing the Tabi
14rect_tabi = viren2d.Rect(
15    center=(508, 285), size=(120, 70), rotation=18, radius=20)
16painter.draw_bounding_box_2d(
17    rect_tabi, bbox_style, label_top=['Tabi socks'])
18
19# Draw the bounding box around the face
20bbox_style.line_style.color = 'crimson'
21bbox_style.text_style.color = 'crimson'
22rect_face = viren2d.Rect(
23    center=(525, 120), size=(80, 100), rotation=10, radius=20)
24painter.draw_bounding_box_2d(
25    rect_face, bbox_style, label_top=['Angry'], label_bottom=['Warrior'])
26
27
28# Draw the bounding box containing the lens
29bbox_style.line_style.color = 'teal-green'
30bbox_style.text_style.color = 'black'
31rect_lens = viren2d.Rect(
32    center=(150, 145), size=(310, 190), rotation=-5, radius=20)
33painter.draw_bounding_box_2d(
34    rect_lens, bbox_style, label_top=['IP camera'],
35    label_right=['Varifocal lens'], right_t2b=True)
36
37# Draw the trajectory of the katana:
38traj_sword = [
39    (646, 192), (642, 166), (634, 136), (620, 108), (610,  88), (588,  70),
40    (566,  58), (546,  54), (522,  52), (492,  56), (462,  66), (434,  80),
41    (414,  98), (402, 124), (392, 148), (384, 174), (366, 200), (350, 224),
42    (318, 240), (288, 246), (256, 246), (230, 238)]
43
44line_style.cap = viren2d.LineCap.Round
45line_style.color = 'navy-blue'
46painter.draw_trajectory(
47    traj_sword, line_style=line_style,
48    fade_out_color="white!100", tail_first=False,
49    smoothing_window=3)
50
51# Mark the tip of the sword:
52marker_style = viren2d.MarkerStyle(
53    marker='5', size=30, filled=True, color=line_style.color,
54    bg_border=3, bg_color='ivory!70')
55painter.draw_marker(traj_sword[0], marker_style)
56