"""Small helper utilities shared by debug capture and overlay modules.""" import numpy as np import cv2 from config.runtime import ( DEBUG_ARTIFACTS_MAX_DIMENSION, DEBUG_ARTIFACTS_PREVIEW_DIMENSION, ) def _debug_resize_rgb(image_rgb: np.ndarray) -> np.ndarray: height, width = image_rgb.shape[:2] largest = max(height, width) if largest <= DEBUG_ARTIFACTS_MAX_DIMENSION: return image_rgb scale = DEBUG_ARTIFACTS_MAX_DIMENSION / largest return cv2.resize( image_rgb, (max(1, round(width * scale)), max(1, round(height * scale))), interpolation=cv2.INTER_AREA, ) def _debug_preview_rgb(image_rgb: np.ndarray) -> np.ndarray: height, width = image_rgb.shape[:2] largest = max(height, width) if largest <= DEBUG_ARTIFACTS_PREVIEW_DIMENSION: return image_rgb scale = DEBUG_ARTIFACTS_PREVIEW_DIMENSION / largest return cv2.resize( image_rgb, (max(1, round(width * scale)), max(1, round(height * scale))), interpolation=cv2.INTER_AREA, ) def _debug_json_default(value): if isinstance(value, np.generic): return value.item() if isinstance(value, np.ndarray): return value.tolist() raise TypeError(f"Unsupported debug manifest value: {type(value).__name__}")