Download services/debug/helpers.py from modventures/room-visualizer-v2: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/modventures/room-visualizer-v2/resolve/main/services/debug/helpers.py
- Command line
-
hf download hf://spaces/modventures/room-visualizer-v2/services/debug/helpers.py
-
curl -L -o helpers.py https://huggingface.co/spaces/modventures/room-visualizer-v2/resolve/main/services/debug/helpers.py
1.31 kB
| """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__}") | |