Add camera rotation feature with configurable degrees
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user