From 673cc64169b6fc5db2b6501ef337409eb4b3de99 Mon Sep 17 00:00:00 2001 From: bartool Date: Thu, 7 May 2026 00:39:18 +0200 Subject: [PATCH] Add camera rotation feature with configurable degrees --- README.md | 1 + app/camera.py | 16 ++++++++++++++++ app/config.py | 1 + app_config.json | 1 + 4 files changed, 19 insertions(+) diff --git a/README.md b/README.md index e70e9d8..1f573a2 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Glowny plik konfiguracji: `app_config.json`. Istotne ustawienia: - `camera.width`, `camera.height`, `camera.fps` - rozdzielczosc i FPS kamery. +- `camera.rotation_degrees` - obrot obrazu z kamery: `0`, `90`, `180` albo `270`. - `camera.properties` - parametry OpenCV ustawiane na kamerze, np. jasnosc, kontrast, ekspozycja. `null` oznacza brak wymuszania wartosci. - `detection.mode` - `best` rysuje najlepsza etykiete, `all` rysuje wszystkie wykrycia. - `detection.frame_stride` - YOLO uruchamiany co N klatek podczas aktywnego wykrywania. diff --git a/app/camera.py b/app/camera.py index e7e0700..cf56954 100644 --- a/app/camera.py +++ b/app/camera.py @@ -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: diff --git a/app/config.py b/app/config.py index 25bee96..7dd74d1 100644 --- a/app/config.py +++ b/app/config.py @@ -17,6 +17,7 @@ DEFAULT_CONFIG: dict[str, Any] = { "height": 1080, "fps": 30, "backend": "auto", + "rotation_degrees": 0, "properties": { "brightness": None, "contrast": None, diff --git a/app_config.json b/app_config.json index ac8d937..956d52b 100644 --- a/app_config.json +++ b/app_config.json @@ -5,6 +5,7 @@ "height": 1080, "fps": 30, "backend": "auto", + "rotation_degrees": 0, "properties": { "brightness": null, "contrast": null,