Browse Source

Rotate webcam image CCW 90° to match headset orientation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
main
Joe DiPrima 1 month ago
parent
commit
c7be418232
  1. 7
      teleop/teleop_hand_and_arm.py

7
teleop/teleop_hand_and_arm.py

@ -107,8 +107,9 @@ class ThreadedWebcam:
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height) self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
# Minimize internal buffer so we always get the latest frame # Minimize internal buffer so we always get the latest frame
self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1) self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
self.actual_w = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
self.actual_h = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# After CCW 90° rotation, width and height are swapped
self.actual_w = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
self.actual_h = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
self._frame = None self._frame = None
self._lock = threading.Lock() self._lock = threading.Lock()
self._stop = threading.Event() self._stop = threading.Event()
@ -116,9 +117,11 @@ class ThreadedWebcam:
self._thread.start() self._thread.start()
def _capture_loop(self): def _capture_loop(self):
import cv2
while not self._stop.is_set(): while not self._stop.is_set():
ret, frame = self.cap.read() ret, frame = self.cap.read()
if ret: if ret:
frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE)
with self._lock: with self._lock:
self._frame = frame self._frame = frame

Loading…
Cancel
Save