From 432984b3b668110c8ff3bfe1d424a3b539603372 Mon Sep 17 00:00:00 2001 From: KRSHH <136873090+KRSHH@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:41:17 +0530 Subject: [PATCH 1/3] Mac Fix Pygrabber Module import only on windows --- modules/ui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ui.py b/modules/ui.py index 25c7de0..1d09e8f 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -7,7 +7,6 @@ from cv2_enumerate_cameras import enumerate_cameras # Add this import from PIL import Image, ImageOps import time import json -from pygrabber.dshow_graph import FilterGraph import modules.globals import modules.metadata from modules.face_analyser import ( @@ -773,6 +772,8 @@ def webcam_preview(root: ctk.CTk, camera_index: int): def get_available_cameras(): """Returns a list of available camera names and indices.""" if platform.system() == "Windows": + from pygrabber.dshow_graph import FilterGraph + try: graph = FilterGraph() devices = graph.get_input_devices() From 5ce991651d71e54f7fdfedc9617b1241aa0f08f7 Mon Sep 17 00:00:00 2001 From: KRSHH <136873090+KRSHH@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:46:59 +0530 Subject: [PATCH 2/3] Formatting Moved Windows only modules, to top too. --- modules/ui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 1d09e8f..16e7a9f 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -28,6 +28,9 @@ from modules.utilities import ( from modules.video_capture import VideoCapturer import platform +if platform.system() == "Windows": + from pygrabber.dshow_graph import FilterGraph + ROOT = None POPUP = None POPUP_LIVE = None @@ -772,8 +775,6 @@ def webcam_preview(root: ctk.CTk, camera_index: int): def get_available_cameras(): """Returns a list of available camera names and indices.""" if platform.system() == "Windows": - from pygrabber.dshow_graph import FilterGraph - try: graph = FilterGraph() devices = graph.get_input_devices() From 77c19d1073e72fa1cf26ad4b181c59fcf6a05cb9 Mon Sep 17 00:00:00 2001 From: KRSHH <136873090+KRSHH@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:58:43 +0530 Subject: [PATCH 3/3] FaceTime Camera Index to 0 --- modules/ui.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 16e7a9f..33ded63 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -812,13 +812,29 @@ def get_available_cameras(): camera_indices = [] camera_names = [] - # Test the first 10 indices - for i in range(10): - cap = cv2.VideoCapture(i) + if platform.system() == "Darwin": # macOS specific handling + # Try to open the default FaceTime camera first + cap = cv2.VideoCapture(0) if cap.isOpened(): - camera_indices.append(i) - camera_names.append(f"Camera {i}") + camera_indices.append(0) + camera_names.append("FaceTime Camera") cap.release() + + # On macOS, additional cameras typically use indices 1 and 2 + for i in [1, 2]: + cap = cv2.VideoCapture(i) + if cap.isOpened(): + camera_indices.append(i) + camera_names.append(f"Camera {i}") + cap.release() + else: + # Linux camera detection - test first 10 indices + for i in range(10): + cap = cv2.VideoCapture(i) + if cap.isOpened(): + camera_indices.append(i) + camera_names.append(f"Camera {i}") + cap.release() if not camera_names: return [], ["No cameras found"]