From 0ff037997f2fc5a1d09c151b15f36806130b5522 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Tue, 22 Jun 2021 07:02:00 -0500 Subject: [PATCH] fixup timestamp config --- frigate/config.py | 1 + frigate/util.py | 52 ++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/frigate/config.py b/frigate/config.py index bc4aa9930..eb792fc1f 100644 --- a/frigate/config.py +++ b/frigate/config.py @@ -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(), } diff --git a/frigate/util.py b/frigate/util.py index d531527b4..c94ddc5dc 100755 --- a/frigate/util.py +++ b/frigate/util.py @@ -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", - ): - time_to_show = datetime.datetime.fromtimestamp( - timestamp - ).strftime(timestamp_format) + position="tl", +): + 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 + time_to_show, + cv2.FONT_HERSHEY_SIMPLEX, + fontScale=font_scale, + 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,18 +58,20 @@ 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([ - [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], - ]) + 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, + frame, [timestamp_box_coords], # 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": cv2.putText( @@ -78,9 +79,9 @@ def draw_timestamp( time_to_show, (text_offset_x + 3, text_offset_y + line_height), cv2.FONT_HERSHEY_SIMPLEX, - fontScale = font_scale, - color = (255-font_color[0], 255-font_color[1], 255-font_color[2]), - thickness = font_thickness, + fontScale=font_scale, + color=(255 - font_color[0], 255 - font_color[1], 255 - font_color[2]), + thickness=font_thickness, ) cv2.putText( @@ -88,11 +89,12 @@ def draw_timestamp( time_to_show, (text_offset_x, text_offset_y + line_height - 3), cv2.FONT_HERSHEY_SIMPLEX, - fontScale = font_scale, - color = font_color, - thickness = font_thickness, + fontScale=font_scale, + color=font_color, + thickness=font_thickness, ) + def draw_box_with_label( frame, x_min,