From eb733ad8c5dea5f90116a721832d7592f2b84257 Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 00:42:53 -0400 Subject: [PATCH 1/7] started using pygrabber to get input cameras with names; fixed issue with webcam preview not stopping when the preview window is closed --- modules/ui.py | 29 ++++++++++++++++------------- requirements.txt | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 0a1bb39..bfd2ab2 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -5,6 +5,7 @@ import customtkinter as ctk from typing import Callable, Tuple import cv2 from PIL import Image, ImageOps +from pygrabber.dshow_graph import FilterGraph # Import OS-specific modules only when necessary if platform.system() == 'Darwin': # macOS @@ -310,6 +311,10 @@ def webcam_preview(camera_name: str): global preview_label, PREVIEW + WIDTH = 960 + HEIGHT = 540 + FPS = 60 + # Select the camera by its name selected_camera = select_camera(camera_name) if selected_camera is None: @@ -325,12 +330,12 @@ def webcam_preview(camera_name: str): update_status(f"Error: Could not open camera {camera_name}") return - cap.set(cv2.CAP_PROP_FRAME_WIDTH, 960) - cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 540) - cap.set(cv2.CAP_PROP_FPS, 60) + cap.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH) + cap.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT) + cap.set(cv2.CAP_PROP_FPS, FPS) - PREVIEW_MAX_WIDTH = 960 - PREVIEW_MAX_HEIGHT = 540 + PREVIEW_MAX_WIDTH = WIDTH + PREVIEW_MAX_HEIGHT = HEIGHT preview_label.configure(image=None) PREVIEW.deiconify() @@ -355,6 +360,9 @@ def webcam_preview(camera_name: str): preview_label.configure(image=image) ROOT.update() + if PREVIEW.state() == 'withdrawn': + break + cap.release() PREVIEW.withdraw() @@ -389,12 +397,7 @@ def get_available_cameras(): print(f"Skipping Continuity Camera: {device.localizedName()}") elif platform.system() == 'Windows' or platform.system() == 'Linux': # Use OpenCV to detect camera indexes - index = 0 - while True: - cap = cv2.VideoCapture(index) - if not cap.isOpened(): - break - available_cameras.append(f"Camera {index}") - cap.release() - index += 1 + devices = FilterGraph().get_input_devices() + + available_cameras = devices return available_cameras diff --git a/requirements.txt b/requirements.txt index 6858313..72f60f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,3 +22,4 @@ protobuf==4.23.2 tqdm==4.66.4 gfpgan==1.3.8 pyobjc==9.1; sys_platform == 'darwin' +pygrabber==0.2 \ No newline at end of file From b4cf8854f8c3aec440601e21e5cdb27abc0b419c Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 00:50:14 -0400 Subject: [PATCH 2/7] refactored camera preview to use a loop function --- modules/ui.py | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index bfd2ab2..46c6f0b 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -2,7 +2,8 @@ import os import platform import webbrowser import customtkinter as ctk -from typing import Callable, Tuple +from typing import Callable, Tuple, List, Any +from types import ModuleType import cv2 from PIL import Image, ImageOps from pygrabber.dshow_graph import FilterGraph @@ -304,6 +305,25 @@ def update_preview(frame_number: int = 0) -> None: image = ctk.CTkImage(image, size=image.size) preview_label.configure(image=image) +def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processors: List[ModuleType]): + global preview_label, PREVIEW + + ret, frame = cap.read() + if not ret: + update_status(f"Error: Frame not received from camera.") + return False + + temp_frame = frame.copy() + + for frame_processor in frame_processors: + temp_frame = frame_processor.process_frame(source_image, temp_frame) + + image = Image.fromarray(cv2.cvtColor(temp_frame, cv2.COLOR_BGR2RGB)) + image = ImageOps.contain(image, (PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT), Image.LANCZOS) + image = ctk.CTkImage(image, size=image.size) + preview_label.configure(image=image) + ROOT.update() + return True def webcam_preview(camera_name: str): if modules.globals.source_path is None: @@ -343,22 +363,10 @@ def webcam_preview(camera_name: str): frame_processors = get_frame_processors_modules(modules.globals.frame_processors) source_image = get_one_face(cv2.imread(modules.globals.source_path)) - while True: - ret, frame = cap.read() - if not ret: - update_status(f"Error: Frame not received from camera.") - break + preview_running = True - temp_frame = frame.copy() - - for frame_processor in frame_processors: - temp_frame = frame_processor.process_frame(source_image, temp_frame) - - image = Image.fromarray(cv2.cvtColor(temp_frame, cv2.COLOR_BGR2RGB)) - image = ImageOps.contain(image, (PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT), Image.LANCZOS) - image = ctk.CTkImage(image, size=image.size) - preview_label.configure(image=image) - ROOT.update() + while preview_running: + preview_running = webcam_preview_loop(cap, source_image, frame_processors) if PREVIEW.state() == 'withdrawn': break From 3fbc1d0433a50e6e4d7e8b0f0fc150ac2be261fd Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 01:04:57 -0400 Subject: [PATCH 3/7] added virtual cam output toggle --- modules/ui.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 46c6f0b..50faf9d 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -22,7 +22,7 @@ from modules.processors.frame.core import get_frame_processors_modules from modules.utilities import is_image, is_video, resolve_relative_path ROOT = None -ROOT_HEIGHT = 700 +ROOT_HEIGHT = 800 ROOT_WIDTH = 600 PREVIEW = None @@ -104,65 +104,69 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C root.protocol('WM_DELETE_WINDOW', lambda: destroy()) source_label = ctk.CTkLabel(root, text=None) - source_label.place(relx=0.1, rely=0.1, relwidth=0.3, relheight=0.25) + source_label.place(relx=0.1, rely=0.1*700/800, relwidth=0.3, relheight=0.25) target_label = ctk.CTkLabel(root, text=None) - target_label.place(relx=0.6, rely=0.1, relwidth=0.3, relheight=0.25) + target_label.place(relx=0.6, rely=0.1*700/800, relwidth=0.3, relheight=0.25) source_button = ctk.CTkButton(root, text='Select a face', cursor='hand2', command=select_source_path) - source_button.place(relx=0.1, rely=0.4, relwidth=0.3, relheight=0.1) + source_button.place(relx=0.1, rely=0.4*700/800, relwidth=0.3, relheight=0.1) target_button = ctk.CTkButton(root, text='Select a target', cursor='hand2', command=select_target_path) - target_button.place(relx=0.6, rely=0.4, relwidth=0.3, relheight=0.1) + target_button.place(relx=0.6, rely=0.4*700/800, relwidth=0.3, relheight=0.1) keep_fps_value = ctk.BooleanVar(value=modules.globals.keep_fps) keep_fps_checkbox = ctk.CTkSwitch(root, text='Keep fps', variable=keep_fps_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_fps', not modules.globals.keep_fps)) - keep_fps_checkbox.place(relx=0.1, rely=0.6) + keep_fps_checkbox.place(relx=0.1, rely=0.6*700/800) keep_frames_value = ctk.BooleanVar(value=modules.globals.keep_frames) keep_frames_switch = ctk.CTkSwitch(root, text='Keep frames', variable=keep_frames_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_frames', keep_frames_value.get())) - keep_frames_switch.place(relx=0.1, rely=0.65) + keep_frames_switch.place(relx=0.1, rely=0.65*700/800) enhancer_value = ctk.BooleanVar(value=modules.globals.fp_ui['face_enhancer']) enhancer_switch = ctk.CTkSwitch(root, text='Face Enhancer', variable=enhancer_value, cursor='hand2', command=lambda: update_tumbler('face_enhancer', enhancer_value.get())) - enhancer_switch.place(relx=0.1, rely=0.7) + enhancer_switch.place(relx=0.1, rely=0.7*700/800) keep_audio_value = ctk.BooleanVar(value=modules.globals.keep_audio) keep_audio_switch = ctk.CTkSwitch(root, text='Keep audio', variable=keep_audio_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_audio', keep_audio_value.get())) - keep_audio_switch.place(relx=0.6, rely=0.6) + keep_audio_switch.place(relx=0.6, rely=0.6*700/800) many_faces_value = ctk.BooleanVar(value=modules.globals.many_faces) many_faces_switch = ctk.CTkSwitch(root, text='Many faces', variable=many_faces_value, cursor='hand2', command=lambda: setattr(modules.globals, 'many_faces', many_faces_value.get())) - many_faces_switch.place(relx=0.6, rely=0.65) + many_faces_switch.place(relx=0.6, rely=0.65*700/800) nsfw_value = ctk.BooleanVar(value=modules.globals.nsfw) nsfw_switch = ctk.CTkSwitch(root, text='NSFW', variable=nsfw_value, cursor='hand2', command=lambda: setattr(modules.globals, 'nsfw', nsfw_value.get())) - nsfw_switch.place(relx=0.6, rely=0.7) + nsfw_switch.place(relx=0.6, rely=0.7*700/800) start_button = ctk.CTkButton(root, text='Start', cursor='hand2', command=lambda: select_output_path(start)) - start_button.place(relx=0.15, rely=0.8, relwidth=0.2, relheight=0.05) + start_button.place(relx=0.15, rely=0.8*700/800, relwidth=0.2, relheight=0.05) stop_button = ctk.CTkButton(root, text='Destroy', cursor='hand2', command=destroy) - stop_button.place(relx=0.4, rely=0.8, relwidth=0.2, relheight=0.05) + stop_button.place(relx=0.4, rely=0.8*700/800, relwidth=0.2, relheight=0.05) preview_button = ctk.CTkButton(root, text='Preview', cursor='hand2', command=toggle_preview) - preview_button.place(relx=0.65, rely=0.8, relwidth=0.2, relheight=0.05) + preview_button.place(relx=0.65, rely=0.8*700/800, relwidth=0.2, relheight=0.05) camera_label = ctk.CTkLabel(root, text="Select Camera:") - camera_label.place(relx=0.4, rely=0.86, relwidth=0.2, relheight=0.05) + camera_label.place(relx=0.4, rely=0.86*700/800, relwidth=0.2, relheight=0.05) available_cameras = get_available_cameras() available_camera_strings = [str(cam) for cam in available_cameras] camera_variable = ctk.StringVar(value=available_camera_strings[0] if available_camera_strings else "No cameras found") camera_optionmenu = ctk.CTkOptionMenu(root, variable=camera_variable, values=available_camera_strings) - camera_optionmenu.place(relx=0.65, rely=0.86, relwidth=0.2, relheight=0.05) + camera_optionmenu.place(relx=0.65, rely=0.86*700/800, relwidth=0.2, relheight=0.05) - live_button = ctk.CTkButton(root, text='Live', cursor='hand2', command=lambda: webcam_preview(camera_variable.get())) - live_button.place(relx=0.15, rely=0.86, relwidth=0.2, relheight=0.05) + virtual_cam_out_value = ctk.BooleanVar(value=False) + virtual_cam_out_switch = ctk.CTkSwitch(root, text='Virtual Cam Output (OBS)', variable=virtual_cam_out_value, cursor='hand2') + virtual_cam_out_switch.place(relx=0.4, rely=0.92*700/800) + + live_button = ctk.CTkButton(root, text='Live', cursor='hand2', command=lambda: webcam_preview(camera_variable.get(), virtual_cam_out_value.get())) + live_button.place(relx=0.15, rely=0.86*700/800, relwidth=0.2, relheight=0.05) status_label = ctk.CTkLabel(root, text=None, justify='center') - status_label.place(relx=0.1, relwidth=0.8, rely=0.9) + status_label.place(relx=0.1, relwidth=0.8, rely=1*700/800) donate_label = ctk.CTkLabel(root, text='Deep Live Cam', justify='center', cursor='hand2') donate_label.place(relx=0.1, rely=0.95, relwidth=0.8) @@ -325,7 +329,7 @@ def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processo ROOT.update() return True -def webcam_preview(camera_name: str): +def webcam_preview(camera_name: str, virtual_cam_output: bool): if modules.globals.source_path is None: return From cd2c3c2103500091c9ac662e0fc4abd44d64005d Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 01:31:10 -0400 Subject: [PATCH 4/7] added virtual cam output --- modules/ui.py | 18 +++++++++++++++--- requirements.txt | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 50faf9d..8e43c67 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -7,6 +7,7 @@ from types import ModuleType import cv2 from PIL import Image, ImageOps from pygrabber.dshow_graph import FilterGraph +import pyvirtualcam # Import OS-specific modules only when necessary if platform.system() == 'Darwin': # macOS @@ -309,7 +310,7 @@ def update_preview(frame_number: int = 0) -> None: image = ctk.CTkImage(image, size=image.size) preview_label.configure(image=image) -def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processors: List[ModuleType]): +def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processors: List[ModuleType], virtual_cam: pyvirtualcam.Camera = None) -> bool: global preview_label, PREVIEW ret, frame = cap.read() @@ -326,7 +327,14 @@ def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processo image = ImageOps.contain(image, (PREVIEW_MAX_WIDTH, PREVIEW_MAX_HEIGHT), Image.LANCZOS) image = ctk.CTkImage(image, size=image.size) preview_label.configure(image=image) + if virtual_cam: + virtual_cam.send(temp_frame) + virtual_cam.sleep_until_next_frame() ROOT.update() + + if PREVIEW.state() == 'withdrawn': + return False + return True def webcam_preview(camera_name: str, virtual_cam_output: bool): @@ -369,11 +377,15 @@ def webcam_preview(camera_name: str, virtual_cam_output: bool): preview_running = True + if virtual_cam_output: + with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS, fmt=pyvirtualcam.PixelFormat.BGR) as virtual_cam: + while preview_running: + preview_running = webcam_preview_loop(cap, source_image, frame_processors, virtual_cam) + while preview_running: preview_running = webcam_preview_loop(cap, source_image, frame_processors) - if PREVIEW.state() == 'withdrawn': - break + cap.release() PREVIEW.withdraw() diff --git a/requirements.txt b/requirements.txt index 72f60f7..915179d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,4 +22,5 @@ protobuf==4.23.2 tqdm==4.66.4 gfpgan==1.3.8 pyobjc==9.1; sys_platform == 'darwin' -pygrabber==0.2 \ No newline at end of file +pygrabber==0.2 +pyvirtualcam==0.12.0 \ No newline at end of file From f9768854565634db03f9ee51a068862276162325 Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 01:36:24 -0400 Subject: [PATCH 5/7] updated rely coords for the taller window --- modules/ui.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 8e43c67..5ad2a65 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -105,69 +105,69 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C root.protocol('WM_DELETE_WINDOW', lambda: destroy()) source_label = ctk.CTkLabel(root, text=None) - source_label.place(relx=0.1, rely=0.1*700/800, relwidth=0.3, relheight=0.25) + source_label.place(relx=0.1, rely=0.0875, relwidth=0.3, relheight=0.25) target_label = ctk.CTkLabel(root, text=None) - target_label.place(relx=0.6, rely=0.1*700/800, relwidth=0.3, relheight=0.25) + target_label.place(relx=0.6, rely=0.0875, relwidth=0.3, relheight=0.25) source_button = ctk.CTkButton(root, text='Select a face', cursor='hand2', command=select_source_path) - source_button.place(relx=0.1, rely=0.4*700/800, relwidth=0.3, relheight=0.1) + source_button.place(relx=0.1, rely=0.35, relwidth=0.3, relheight=0.1) target_button = ctk.CTkButton(root, text='Select a target', cursor='hand2', command=select_target_path) - target_button.place(relx=0.6, rely=0.4*700/800, relwidth=0.3, relheight=0.1) + target_button.place(relx=0.6, rely=0.35, relwidth=0.3, relheight=0.1) keep_fps_value = ctk.BooleanVar(value=modules.globals.keep_fps) keep_fps_checkbox = ctk.CTkSwitch(root, text='Keep fps', variable=keep_fps_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_fps', not modules.globals.keep_fps)) - keep_fps_checkbox.place(relx=0.1, rely=0.6*700/800) + keep_fps_checkbox.place(relx=0.1, rely=0.525) keep_frames_value = ctk.BooleanVar(value=modules.globals.keep_frames) keep_frames_switch = ctk.CTkSwitch(root, text='Keep frames', variable=keep_frames_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_frames', keep_frames_value.get())) - keep_frames_switch.place(relx=0.1, rely=0.65*700/800) + keep_frames_switch.place(relx=0.1, rely=0.56875) enhancer_value = ctk.BooleanVar(value=modules.globals.fp_ui['face_enhancer']) enhancer_switch = ctk.CTkSwitch(root, text='Face Enhancer', variable=enhancer_value, cursor='hand2', command=lambda: update_tumbler('face_enhancer', enhancer_value.get())) - enhancer_switch.place(relx=0.1, rely=0.7*700/800) + enhancer_switch.place(relx=0.1, rely=0.6125) keep_audio_value = ctk.BooleanVar(value=modules.globals.keep_audio) keep_audio_switch = ctk.CTkSwitch(root, text='Keep audio', variable=keep_audio_value, cursor='hand2', command=lambda: setattr(modules.globals, 'keep_audio', keep_audio_value.get())) - keep_audio_switch.place(relx=0.6, rely=0.6*700/800) + keep_audio_switch.place(relx=0.6, rely=0.525) many_faces_value = ctk.BooleanVar(value=modules.globals.many_faces) many_faces_switch = ctk.CTkSwitch(root, text='Many faces', variable=many_faces_value, cursor='hand2', command=lambda: setattr(modules.globals, 'many_faces', many_faces_value.get())) - many_faces_switch.place(relx=0.6, rely=0.65*700/800) + many_faces_switch.place(relx=0.6, rely=0.56875) nsfw_value = ctk.BooleanVar(value=modules.globals.nsfw) nsfw_switch = ctk.CTkSwitch(root, text='NSFW', variable=nsfw_value, cursor='hand2', command=lambda: setattr(modules.globals, 'nsfw', nsfw_value.get())) - nsfw_switch.place(relx=0.6, rely=0.7*700/800) + nsfw_switch.place(relx=0.6, rely=0.6125) start_button = ctk.CTkButton(root, text='Start', cursor='hand2', command=lambda: select_output_path(start)) - start_button.place(relx=0.15, rely=0.8*700/800, relwidth=0.2, relheight=0.05) + start_button.place(relx=0.15, rely=0.7, relwidth=0.2, relheight=0.05) stop_button = ctk.CTkButton(root, text='Destroy', cursor='hand2', command=destroy) - stop_button.place(relx=0.4, rely=0.8*700/800, relwidth=0.2, relheight=0.05) + stop_button.place(relx=0.4, rely=0.7, relwidth=0.2, relheight=0.05) preview_button = ctk.CTkButton(root, text='Preview', cursor='hand2', command=toggle_preview) - preview_button.place(relx=0.65, rely=0.8*700/800, relwidth=0.2, relheight=0.05) + preview_button.place(relx=0.65, rely=0.7, relwidth=0.2, relheight=0.05) camera_label = ctk.CTkLabel(root, text="Select Camera:") - camera_label.place(relx=0.4, rely=0.86*700/800, relwidth=0.2, relheight=0.05) + camera_label.place(relx=0.4, rely=0.7525, relwidth=0.2, relheight=0.05) available_cameras = get_available_cameras() available_camera_strings = [str(cam) for cam in available_cameras] camera_variable = ctk.StringVar(value=available_camera_strings[0] if available_camera_strings else "No cameras found") camera_optionmenu = ctk.CTkOptionMenu(root, variable=camera_variable, values=available_camera_strings) - camera_optionmenu.place(relx=0.65, rely=0.86*700/800, relwidth=0.2, relheight=0.05) + camera_optionmenu.place(relx=0.65, rely=0.7525, relwidth=0.2, relheight=0.05) virtual_cam_out_value = ctk.BooleanVar(value=False) virtual_cam_out_switch = ctk.CTkSwitch(root, text='Virtual Cam Output (OBS)', variable=virtual_cam_out_value, cursor='hand2') - virtual_cam_out_switch.place(relx=0.4, rely=0.92*700/800) + virtual_cam_out_switch.place(relx=0.4, rely=0.805) live_button = ctk.CTkButton(root, text='Live', cursor='hand2', command=lambda: webcam_preview(camera_variable.get(), virtual_cam_out_value.get())) - live_button.place(relx=0.15, rely=0.86*700/800, relwidth=0.2, relheight=0.05) + live_button.place(relx=0.15, rely=0.7525, relwidth=0.2, relheight=0.05) status_label = ctk.CTkLabel(root, text=None, justify='center') - status_label.place(relx=0.1, relwidth=0.8, rely=1*700/800) + status_label.place(relx=0.1, relwidth=0.8, rely=0.875) donate_label = ctk.CTkLabel(root, text='Deep Live Cam', justify='center', cursor='hand2') donate_label.place(relx=0.1, rely=0.95, relwidth=0.8) From 575373beacbd3c066203cd5382b8411d8cb14432 Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 12:22:19 -0400 Subject: [PATCH 6/7] fixed variable names not matching after merge conflict resolution from upstream --- modules/ui.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/ui.py b/modules/ui.py index 3c5fbc3..47ecf9b 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -318,10 +318,10 @@ def update_preview(frame_number: int = 0) -> None: image = ctk.CTkImage(image, size=image.size) preview_label.configure(image=image) -def webcam_preview_loop(cap: cv2.VideoCapture, source_image: Any, frame_processors: List[ModuleType], virtual_cam: pyvirtualcam.Camera = None) -> bool: +def webcam_preview_loop(camera: cv2.VideoCapture, source_image: Any, frame_processors: List[ModuleType], virtual_cam: pyvirtualcam.Camera = None) -> bool: global preview_label, PREVIEW - ret, frame = cap.read() + ret, frame = camera.read() if not ret: update_status(f"Error: Frame not received from camera.") return False @@ -409,12 +409,10 @@ def webcam_preview(camera_name: str, virtual_cam_output: bool): if virtual_cam_output: with pyvirtualcam.Camera(width=WIDTH, height=HEIGHT, fps=FPS, fmt=pyvirtualcam.PixelFormat.BGR) as virtual_cam: while preview_running: - preview_running = webcam_preview_loop(cap, source_image, frame_processors, virtual_cam) + preview_running = webcam_preview_loop(camera, source_image, frame_processors, virtual_cam) while preview_running: - preview_running = webcam_preview_loop(cap, source_image, frame_processors) - - + preview_running = webcam_preview_loop(camera, source_image, frame_processors) if camera: camera.release() PREVIEW.withdraw() From a90c4facc585caf3c928f834d5bd57f4c84ecd0d Mon Sep 17 00:00:00 2001 From: Aleksandr Spiridonov Date: Thu, 15 Aug 2024 12:27:52 -0400 Subject: [PATCH 7/7] added a note to README to document new virtual cam output feature --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4707982..fe60fe5 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Just follow the clicks on the screenshot Just use your favorite screencapture to stream like OBS > Note: In case you want to change your face, just select another picture, the preview mode will then restart (so just wait a bit). +You can now use the virtual camera output (uses pyvirtualcam) by turning on the `Virtual Cam Output (OBS)` toggle which should output to the OBS Virtual Camera. Note: this may not work on macOS. You will get a preview as before, but now you will also have a virtual camera output which can be used in applications like Zoom. Additional command line arguments are given below. To learn out what they do, check [this guide](https://github.com/s0md3v/roop/wiki/Advanced-Options).