Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating premain #849

Merged
merged 9 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions modules/processors/frame/face_enhancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ def get_face_enhancer() -> Any:
with THREAD_LOCK:
if FACE_ENHANCER is None:
model_path = os.path.join(models_dir, "GFPGANv1.4.pth")
if platform.system() == "Darwin": # Mac OS
mps_device = None
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=mps_device) # type: ignore[attr-defined]
else: # Other OS
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]

match platform.system():
case "Darwin": # Mac OS
if torch.backends.mps.is_available():
mps_device = torch.device("mps")
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=mps_device) # type: ignore[attr-defined]
else:
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]
case _: # Other OS
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]

return FACE_ENHANCER


Expand Down
30 changes: 24 additions & 6 deletions modules/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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 (
Expand All @@ -29,6 +28,9 @@
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
Expand Down Expand Up @@ -810,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"]
Expand Down
Loading