Skip to content
This repository was archived by the owner on Mar 19, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion custom_components/deepstack_face/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = ""
Expand All @@ -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,
}
)

Expand Down Expand Up @@ -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),
)
Expand Down Expand Up @@ -180,6 +186,7 @@ def __init__(
save_faces_folder,
save_faces,
show_boxes,
box_color,
camera_entity,
name=None,
):
Expand All @@ -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
Expand Down Expand Up @@ -331,14 +339,15 @@ 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,
(box["y_min"], box["x_min"], box["y_max"], box["x_max"]),
image_width,
image_height,
text=box_label,
color=RED,
color=box_color.upper(),
)

latest_save_path = (
Expand Down