| """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 | |