fixup timestamp config

This commit is contained in:
Blake Blackshear 2021-06-22 07:02:00 -05:00
parent e8c2cfa5b5
commit 0ff037997f
2 changed files with 28 additions and 25 deletions

View File

@ -963,6 +963,7 @@ class CameraConfig:
{"roles": c["roles"], "cmd": " ".join(c["cmd"])} {"roles": c["roles"], "cmd": " ".join(c["cmd"])}
for c in self.ffmpeg_cmds for c in self.ffmpeg_cmds
], ],
"timestamp_style": self.timestamp_style.to_dict(),
} }

View File

@ -19,6 +19,7 @@ import numpy as np
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def draw_timestamp( def draw_timestamp(
frame, frame,
timestamp, timestamp,
@ -27,16 +28,14 @@ def draw_timestamp(
font_scale=1.0, font_scale=1.0,
font_thickness=2, font_thickness=2,
font_color=(255, 255, 255), font_color=(255, 255, 255),
position="ul", position="tl",
): ):
time_to_show = datetime.datetime.fromtimestamp( time_to_show = datetime.datetime.fromtimestamp(timestamp).strftime(timestamp_format)
timestamp
).strftime(timestamp_format)
size = cv2.getTextSize( size = cv2.getTextSize(
time_to_show, time_to_show,
cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_SIMPLEX,
fontScale = font_scale, fontScale=font_scale,
thickness = font_thickness thickness=font_thickness,
) )
image_width = frame.shape[1] image_width = frame.shape[1]
image_height = frame.shape[0] image_height = frame.shape[0]
@ -44,10 +43,10 @@ def draw_timestamp(
text_height = size[0][1] text_height = size[0][1]
line_height = text_height + size[1] line_height = text_height + size[1]
if position == "ul": if position == "tl":
text_offset_x = 0 text_offset_x = 0
text_offset_y = 0 if 0 < line_height else 0 - (line_height + 8) text_offset_y = 0 if 0 < line_height else 0 - (line_height + 8)
elif position == "ur": elif position == "tr":
text_offset_x = image_width - text_width text_offset_x = image_width - text_width
text_offset_y = 0 if 0 < line_height else 0 - (line_height + 8) text_offset_y = 0 if 0 < line_height else 0 - (line_height + 8)
elif position == "bl": elif position == "bl":
@ -59,18 +58,20 @@ def draw_timestamp(
if font_effect == "solid": if font_effect == "solid":
# make the coords of the box with a small padding of two pixels # make the coords of the box with a small padding of two pixels
timestamp_box_coords = np.array([ timestamp_box_coords = np.array(
[text_offset_x, text_offset_y], [
[text_offset_x+text_width, text_offset_y], [text_offset_x, text_offset_y],
[text_offset_x+text_width, text_offset_y + line_height+ 8], [text_offset_x + text_width, text_offset_y],
[text_offset_x, text_offset_y + line_height+ 8], [text_offset_x + text_width, text_offset_y + line_height + 8],
]) [text_offset_x, text_offset_y + line_height + 8],
]
)
cv2.fillPoly( cv2.fillPoly(
frame, frame,
[timestamp_box_coords], [timestamp_box_coords],
# inverse color of text for background for max. contrast # inverse color of text for background for max. contrast
(255-font_color[0], 255-font_color[1], 255-font_color[2]), (255 - font_color[0], 255 - font_color[1], 255 - font_color[2]),
) )
elif font_effect == "shadow": elif font_effect == "shadow":
cv2.putText( cv2.putText(
@ -78,9 +79,9 @@ def draw_timestamp(
time_to_show, time_to_show,
(text_offset_x + 3, text_offset_y + line_height), (text_offset_x + 3, text_offset_y + line_height),
cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_SIMPLEX,
fontScale = font_scale, fontScale=font_scale,
color = (255-font_color[0], 255-font_color[1], 255-font_color[2]), color=(255 - font_color[0], 255 - font_color[1], 255 - font_color[2]),
thickness = font_thickness, thickness=font_thickness,
) )
cv2.putText( cv2.putText(
@ -88,11 +89,12 @@ def draw_timestamp(
time_to_show, time_to_show,
(text_offset_x, text_offset_y + line_height - 3), (text_offset_x, text_offset_y + line_height - 3),
cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_SIMPLEX,
fontScale = font_scale, fontScale=font_scale,
color = font_color, color=font_color,
thickness = font_thickness, thickness=font_thickness,
) )
def draw_box_with_label( def draw_box_with_label(
frame, frame,
x_min, x_min,