face-intel / cores /vision /drawing.py
Marwan
Restructure + add reverse face search (PimEyes-style)
f5eeb1c
Raw
History Blame Contribute Delete
755 Bytes
"""Drawing helpers for UI annotations."""
from __future__ import annotations
from typing import Tuple
import cv2
import numpy as np
from cores.vision.geometry import BBox
def draw_boxes(
img: np.ndarray,
boxes: list,
color: Tuple[int, int, int] = (0, 255, 0),
thickness: int = 2,
) -> np.ndarray:
"""Draw a list of BBox / dict / tuple onto a copy of the image."""
out = img.copy()
for b in boxes:
if isinstance(b, dict):
b = BBox(b["x"], b["y"], b["w"], b["h"])
elif isinstance(b, (list, tuple)) and len(b) == 4:
b = BBox(*b)
elif not isinstance(b, BBox):
continue
cv2.rectangle(out, (b.x, b.y), (b.x + b.w, b.y + b.h), color, thickness)
return out