Add camera rotation feature with configurable degrees
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -17,6 +17,7 @@ DEFAULT_CONFIG: dict[str, Any] = {
|
||||
"height": 1080,
|
||||
"fps": 30,
|
||||
"backend": "auto",
|
||||
"rotation_degrees": 0,
|
||||
"properties": {
|
||||
"brightness": None,
|
||||
"contrast": None,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"height": 1080,
|
||||
"fps": 30,
|
||||
"backend": "auto",
|
||||
"rotation_degrees": 0,
|
||||
"properties": {
|
||||
"brightness": null,
|
||||
"contrast": null,
|
||||
|
||||
Reference in New Issue
Block a user