webcam: changes for comma zero (#35464)

* Revert "webcam: remove other cv2 usage (#33236)"

This reverts commit 0cade54015.

* Revert "remove cv2 usage (#33101)"

This reverts commit 144e9e271c.

* Revert "remove opencv-python-headless (#33082)"

This reverts commit 488e08507a.

* webcam: set width, height, fps; flip image; use av reformat

* 1280x720 @ 25fps
This commit is contained in:
Andrei Radulescu
2025-06-28 21:30:13 +03:00
committed by GitHub
parent 713c02cc3f
commit 0f1a9d5c8c
2 changed files with 11 additions and 2 deletions
+9
View File
@@ -11,7 +11,14 @@ class Camera:
self.stream_type = stream_type
self.cur_frame_id = 0
print(f"Opening {cam_type_state} at {camera_id}")
self.cap = cv.VideoCapture(camera_id)
self.cap.set(cv.CAP_PROP_FRAME_WIDTH, 1280.0)
self.cap.set(cv.CAP_PROP_FRAME_HEIGHT, 720.0)
self.cap.set(cv.CAP_PROP_FPS, 25.0)
self.W = self.cap.get(cv.CAP_PROP_FRAME_WIDTH)
self.H = self.cap.get(cv.CAP_PROP_FRAME_HEIGHT)
@@ -25,6 +32,8 @@ class Camera:
ret, frame = self.cap.read()
if not ret:
break
# Rotate the frame 180 degrees (flip both axes)
frame = cv.flip(frame, -1)
yuv = Camera.bgr2nv12(frame)
yield yuv.data.tobytes()
self.cap.release()
+2 -2
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import threading
import os
import platform
from collections import namedtuple
from msgq.visionipc import VisionIpcServer, VisionStreamType
@@ -30,8 +31,7 @@ class Camerad:
self.cameras = []
for c in CAMERAS:
cam_device = f"/dev/video{c.cam_id}"
print(f"opening {c.msg_name} at {cam_device}")
cam_device = f"/dev/video{c.cam_id}" if platform.system() != "Darwin" else c.cam_id
cam = Camera(c.msg_name, c.stream_type, cam_device)
self.cameras.append(cam)
self.vipc_server.create_buffers(c.stream_type, 20, cam.W, cam.H)