From 9e2f9a9b6fe1356c0f76787137e68eea6d6c0b2c Mon Sep 17 00:00:00 2001 From: Nick Mowen Date: Thu, 18 May 2023 11:43:24 -0600 Subject: [PATCH] Set thumbnail height to 175 --- frigate/events/external.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/frigate/events/external.py b/frigate/events/external.py index 5e79ff57fe..42cc10e210 100644 --- a/frigate/events/external.py +++ b/frigate/events/external.py @@ -82,11 +82,11 @@ def _write_images( label: str, event_id: str, draw: dict[str, any], - img_bytes: any, + img_frame: any, ) -> str: # write clean snapshot if enabled if camera_config.snapshots.clean_copy: - ret, png = cv2.imencode(".png", img_bytes) + ret, png = cv2.imencode(".png", img_frame) if ret: with open( @@ -107,7 +107,7 @@ def _write_images( height = box["box"][3] * camera_config.detect.height draw_box_with_label( - img_bytes, + img_frame, x, y, x + width, @@ -118,11 +118,17 @@ def _write_images( color=box.get("color", (255, 0, 0)), ) - ret, jpg = cv2.imencode(".jpg", img_bytes) + ret, jpg = cv2.imencode(".jpg", img_frame) with open( os.path.join(CLIPS_DIR, f"{camera_config.name}-{event_id}.jpg"), "wb", ) as j: j.write(jpg.tobytes()) + # create thumbnail with max height of 175 and save + width = int(175 * img_frame.shape[1] / img_frame.shape[0]) + thumb = cv2.resize( + img_frame, dsize=(width, 175), interpolation=cv2.INTER_AREA + ) + ret, jpg = cv2.imencode(".jpg", thumb) return base64.b64encode(jpg.tobytes()).decode("utf-8")