From 8864e33d1ceb985ffde7dd4f75b17095c391575c Mon Sep 17 00:00:00 2001 From: tpjanssen <25168870+tpjanssen@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:51:54 +0100 Subject: [PATCH] Customize regions grid overlay API (#8668) * Customize regions grid overlay * Update http.py Fix --- docs/docs/integrations/api.md | 5 +++++ frigate/http.py | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/docs/integrations/api.md b/docs/docs/integrations/api.md index 304cec60e..a4efd85bf 100644 --- a/docs/docs/integrations/api.md +++ b/docs/docs/integrations/api.md @@ -267,6 +267,11 @@ Returns the snapshot image from the specific point in that cameras recordings. Returns the latest camera image with the regions grid overlaid. +| param | Type | Description | +| ------------ | ----- | ------------------------------------------------------------------------------------------ | +| `color` | str | The color of the grid (red,green,blue,black,white). Defaults to "green". | +| `font_scale` | float | Font scale. Can be used to increase font size on high resolution cameras. Defaults to 0.5. | + ### `GET /clips/-.jpg` JPG snapshot for the given camera and event id. diff --git a/frigate/http.py b/frigate/http.py index 2a581ac9f..1ca87bdf9 100644 --- a/frigate/http.py +++ b/frigate/http.py @@ -755,6 +755,20 @@ def grid_snapshot(camera_name): 500, ) + color_arg = request.args.get("color", default="", type=str).lower() + draw_font_scale = request.args.get("font_scale", default=0.5, type=float) + + if color_arg == "red": + draw_color = (0, 0, 255) + elif color_arg == "blue": + draw_color = (255, 0, 0) + elif color_arg == "black": + draw_color = (0, 0, 0) + elif color_arg == "white": + draw_color = (255, 255, 255) + else: + draw_color = (0, 255, 0) + grid_size = len(grid) grid_coef = 1.0 / grid_size width = detect.width @@ -775,7 +789,7 @@ def grid_snapshot(camera_name): int((x + 1) * grid_coef * width), int((y + 1) * grid_coef * height), ), - (0, 255, 0), + draw_color, 2, ) cv2.putText( @@ -786,8 +800,8 @@ def grid_snapshot(camera_name): int((y * grid_coef + 0.02) * height), ), cv2.FONT_HERSHEY_SIMPLEX, - fontScale=0.5, - color=(0, 255, 0), + fontScale=draw_font_scale, + color=draw_color, thickness=2, ) cv2.putText( @@ -798,8 +812,8 @@ def grid_snapshot(camera_name): int((y * grid_coef + 0.05) * height), ), cv2.FONT_HERSHEY_SIMPLEX, - fontScale=0.5, - color=(0, 255, 0), + fontScale=draw_font_scale, + color=draw_color, thickness=2, ) cv2.putText( @@ -810,8 +824,8 @@ def grid_snapshot(camera_name): int((y * grid_coef + 0.08) * height), ), cv2.FONT_HERSHEY_SIMPLEX, - fontScale=0.5, - color=(0, 255, 0), + fontScale=draw_font_scale, + color=draw_color, thickness=2, )