Add camera rotation feature with configurable degrees

This commit is contained in:
2026-05-07 00:39:18 +02:00
parent ec4872a5d6
commit 673cc64169
4 changed files with 19 additions and 0 deletions

View File

@@ -35,6 +35,19 @@ def backend_for_name(name: str) -> int:
return cv2.CAP_ANY
def rotate_frame(frame: np.ndarray, degrees: int) -> np.ndarray:
normalized = degrees % 360
if normalized == 0:
return frame
if normalized == 90:
return cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
if normalized == 180:
return cv2.rotate(frame, cv2.ROTATE_180)
if normalized == 270:
return cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE)
return frame
class CameraWorker(QThread):
frame_ready = Signal(object)
detection_ready = Signal(object)
@@ -98,6 +111,9 @@ class CameraWorker(QThread):
time.sleep(0.2)
continue
with self._lock:
rotation_degrees = int(self.config["camera"].get("rotation_degrees", 0))
frame = rotate_frame(frame, rotation_degrees)
self.frame_ready.emit(frame)
self._maybe_detect(frame)
finally:

View File

@@ -17,6 +17,7 @@ DEFAULT_CONFIG: dict[str, Any] = {
"height": 1080,
"fps": 30,
"backend": "auto",
"rotation_degrees": 0,
"properties": {
"brightness": None,
"contrast": None,