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"])}
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__)
def draw_timestamp(
frame,
timestamp,
@ -27,16 +28,14 @@ def draw_timestamp(
font_scale=1.0,
font_thickness=2,
font_color=(255, 255, 255),
position="ul",
position="tl",
):
time_to_show = datetime.datetime.fromtimestamp(
timestamp
).strftime(timestamp_format)
time_to_show = datetime.datetime.fromtimestamp(timestamp).strftime(timestamp_format)
size = cv2.getTextSize(
time_to_show,
cv2.FONT_HERSHEY_SIMPLEX,
fontScale=font_scale,
thickness = font_thickness
thickness=font_thickness,
)
image_width = frame.shape[1]
image_height = frame.shape[0]
@ -44,10 +43,10 @@ def draw_timestamp(
text_height = size[0][1]
line_height = text_height + size[1]
if position == "ul":
if position == "tl":
text_offset_x = 0
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_y = 0 if 0 < line_height else 0 - (line_height + 8)
elif position == "bl":
@ -59,12 +58,14 @@ def draw_timestamp(
if font_effect == "solid":
# 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_width, text_offset_y + line_height + 8],
[text_offset_x, text_offset_y + line_height + 8],
])
]
)
cv2.fillPoly(
frame,
@ -93,6 +94,7 @@ def draw_timestamp(
thickness=font_thickness,
)
def draw_box_with_label(
frame,
x_min,