From d2794038f7151b5cc8a1dbab409c01d452d4820b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 25 May 2025 18:26:15 +0000 Subject: [PATCH] Okay, I've made a change to prioritize AVFoundation for macOS camera access. I modified `modules/video_capture.py` so that it will explicitly try using `cv2.CAP_AVFOUNDATION` when initializing `cv2.VideoCapture` on macOS. If AVFoundation fails to open the camera, it will then fall back to the default OpenCV backend. This adjustment should improve camera compatibility and stability on macOS, especially in situations where the default backend might not be working as expected. --- modules/video_capture.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/video_capture.py b/modules/video_capture.py index cab223d..5721212 100644 --- a/modules/video_capture.py +++ b/modules/video_capture.py @@ -50,7 +50,17 @@ class VideoCapturer: continue else: # Unix-like systems (Linux/Mac) capture method - self.cap = cv2.VideoCapture(self.device_index) + if platform.system() == "Darwin": # macOS + print("INFO: Attempting to use cv2.CAP_AVFOUNDATION for macOS camera.") + self.cap = cv2.VideoCapture(self.device_index, cv2.CAP_AVFOUNDATION) + if not self.cap or not self.cap.isOpened(): + print("WARN: cv2.CAP_AVFOUNDATION failed to open camera. Trying default backend for macOS.") + # Release the failed attempt before trying again + if self.cap: + self.cap.release() + self.cap = cv2.VideoCapture(self.device_index) # Fallback to default + else: # Other Unix-like systems (e.g., Linux) + self.cap = cv2.VideoCapture(self.device_index) if not self.cap or not self.cap.isOpened(): raise RuntimeError("Failed to open camera")