From 5ca4a75ec7aab092124edf77aa692c78bedb2a96 Mon Sep 17 00:00:00 2001 From: Sebastian Weyer Date: Mon, 7 Feb 2022 11:52:18 +0100 Subject: [PATCH] Config option for box color Add config option "box_color:" to change the color of the face box. Available colors are red, green, yellow, blue. --- custom_components/deepstack_face/image_processing.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/custom_components/deepstack_face/image_processing.py b/custom_components/deepstack_face/image_processing.py index 2fe764c..f7f50e7 100644 --- a/custom_components/deepstack_face/image_processing.py +++ b/custom_components/deepstack_face/image_processing.py @@ -38,6 +38,9 @@ # rgb(red, green, blue) RED = (255, 0, 0) # For objects within the ROI +YELLOW = (255,255,0) +GREEN = (34,139,34) +BLUE = (0,0,255) CONF_API_KEY = "api_key" CONF_TIMEOUT = "timeout" @@ -47,6 +50,7 @@ CONF_SAVE_FACES_FOLDER = "save_faces_folder" CONF_SAVE_FACES = "save_faces" CONF_SHOW_BOXES = "show_boxes" +CONF_BOX_COLOR = "box_color" DATETIME_FORMAT = "%Y-%m-%d_%H-%M-%S" DEFAULT_API_KEY = "" @@ -71,6 +75,7 @@ vol.Optional(CONF_SAVE_FACES_FOLDER): cv.isdir, vol.Optional(CONF_SAVE_FACES, default=False): cv.boolean, vol.Optional(CONF_SHOW_BOXES, default=True): cv.boolean, + vol.Optional(CONF_BOX_COLOR, default=RED): cv.string, } ) @@ -139,6 +144,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): save_faces_folder, config.get(CONF_SAVE_FACES), config[CONF_SHOW_BOXES], + config.get(CONF_BOX_COLOR), camera[CONF_ENTITY_ID], camera.get(CONF_NAME), ) @@ -180,6 +186,7 @@ def __init__( save_faces_folder, save_faces, show_boxes, + box_color, camera_entity, name=None, ): @@ -190,6 +197,7 @@ def __init__( ) self._detect_only = detect_only self._show_boxes = show_boxes + self._box_color = box_color self._last_detection = None self._save_file_folder = save_file_folder self._save_timestamped_file = save_timestamped_file @@ -331,6 +339,7 @@ def save_image(self, pil_image: Image, directory: Path): confidence = face["confidence"] box = face["bounding_box"] box_label = f"{name}: {confidence:.1f}%" + box_color = self._box_color draw_box( draw, @@ -338,7 +347,7 @@ def save_image(self, pil_image: Image, directory: Path): image_width, image_height, text=box_label, - color=RED, + color=box_color.upper(), ) latest_save_path = (