-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathoverlay.py
56 lines (48 loc) · 2.24 KB
/
overlay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Draw func adds car classification models outputs: car color, car make, car type."""
from savant_rs.draw_spec import LabelDraw, ObjectDraw
from savant.deepstream.drawfunc import NvDsDrawFunc
from savant.meta.object import ObjectMeta
class Overlay(NvDsDrawFunc):
def override_draw_spec(
self, object_meta: ObjectMeta, draw_spec: ObjectDraw
) -> ObjectDraw:
"""Override draw spec for objects with label 'Car'.
Add classifier attributes labels to the object visualisation.
"""
if object_meta.label == 'Car':
new_label_format = draw_spec.label.format
# one attribute per line
# if there's no specific attribute for the object on this frame
# reserve a line for it anyway
# so that the object's labels don't jump up and down
attr_meta = object_meta.get_attr_meta('Secondary_CarColor', 'car_color')
if attr_meta is not None:
new_label_format += [str(attr_meta.value)]
else:
new_label_format += ['']
attr_meta = object_meta.get_attr_meta('Secondary_CarMake', 'car_make')
if attr_meta is not None:
new_label_format += [str(attr_meta.value)]
else:
new_label_format += ['']
attr_meta = object_meta.get_attr_meta('Secondary_VehicleTypes', 'car_type')
if attr_meta is not None:
new_label_format += [str(attr_meta.value)]
else:
new_label_format += ['']
draw_spec = ObjectDraw(
bounding_box=draw_spec.bounding_box,
label=LabelDraw(
font_color=draw_spec.label.font_color,
border_color=draw_spec.label.border_color,
background_color=draw_spec.label.background_color,
padding=draw_spec.label.padding,
font_scale=draw_spec.label.font_scale,
thickness=draw_spec.label.thickness,
format=new_label_format,
position=draw_spec.label.position,
),
central_dot=draw_spec.central_dot,
blur=draw_spec.blur,
)
return draw_spec