Compare commits
1 Commits
ec78c98be8
...
c0ef056e03
Author | SHA1 | Date |
---|---|---|
|
c0ef056e03 |
|
@ -35,3 +35,4 @@ log_level = 'error'
|
||||||
fp_ui: Dict[str, bool] = {}
|
fp_ui: Dict[str, bool] = {}
|
||||||
camera_input_combobox = None
|
camera_input_combobox = None
|
||||||
webcam_preview_running = False
|
webcam_preview_running = False
|
||||||
|
opacity = 100
|
||||||
|
|
|
@ -18,7 +18,7 @@ NAME = 'DLC.FACE-SWAPPER'
|
||||||
|
|
||||||
def pre_check() -> bool:
|
def pre_check() -> bool:
|
||||||
download_directory_path = resolve_relative_path('../models')
|
download_directory_path = resolve_relative_path('../models')
|
||||||
conditional_download(download_directory_path, ['https://huggingface.co/hacksider/deep-live-cam/blob/main/inswapper_128_fp16.onnx'])
|
conditional_download(download_directory_path, ['https://huggingface.co/hacksider/deep-live-cam/blob/main/inswapper_128.onnx'])
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ def get_face_swapper() -> Any:
|
||||||
|
|
||||||
with THREAD_LOCK:
|
with THREAD_LOCK:
|
||||||
if FACE_SWAPPER is None:
|
if FACE_SWAPPER is None:
|
||||||
model_path = resolve_relative_path('../models/inswapper_128_fp16.onnx')
|
model_path = resolve_relative_path('../models/inswapper_128.onnx')
|
||||||
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=modules.globals.execution_providers)
|
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=modules.globals.execution_providers)
|
||||||
return FACE_SWAPPER
|
return FACE_SWAPPER
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from typing import Callable, Tuple
|
||||||
import cv2
|
import cv2
|
||||||
from cv2_enumerate_cameras import enumerate_cameras # Add this import
|
from cv2_enumerate_cameras import enumerate_cameras # Add this import
|
||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
import time
|
|
||||||
import modules.globals
|
import modules.globals
|
||||||
import modules.metadata
|
import modules.metadata
|
||||||
from modules.face_analyser import (
|
from modules.face_analyser import (
|
||||||
|
@ -81,7 +81,7 @@ def init(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.CTk:
|
||||||
|
|
||||||
|
|
||||||
def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.CTk:
|
def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.CTk:
|
||||||
global source_label, target_label, status_label, show_fps_switch
|
global source_label, target_label, status_label
|
||||||
|
|
||||||
ctk.deactivate_automatic_dpi_awareness()
|
ctk.deactivate_automatic_dpi_awareness()
|
||||||
ctk.set_appearance_mode("system")
|
ctk.set_appearance_mode("system")
|
||||||
|
@ -201,17 +201,6 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
||||||
)
|
)
|
||||||
map_faces_switch.place(relx=0.1, rely=0.75)
|
map_faces_switch.place(relx=0.1, rely=0.75)
|
||||||
|
|
||||||
# Add Show FPS switch
|
|
||||||
show_fps_value = ctk.BooleanVar(value=False)
|
|
||||||
show_fps_switch = ctk.CTkSwitch(
|
|
||||||
root,
|
|
||||||
text="Show FPS",
|
|
||||||
variable=show_fps_value,
|
|
||||||
cursor="hand2",
|
|
||||||
command=lambda: setattr(modules.globals, "show_fps", show_fps_value.get()),
|
|
||||||
)
|
|
||||||
show_fps_switch.place(relx=0.6, rely=0.75)
|
|
||||||
|
|
||||||
start_button = ctk.CTkButton(
|
start_button = ctk.CTkButton(
|
||||||
root, text="Start", cursor="hand2", command=lambda: analyze_target(start, root)
|
root, text="Start", cursor="hand2", command=lambda: analyze_target(start, root)
|
||||||
)
|
)
|
||||||
|
@ -653,17 +642,17 @@ def update_preview(frame_number: int = 0) -> None:
|
||||||
PREVIEW.deiconify()
|
PREVIEW.deiconify()
|
||||||
|
|
||||||
|
|
||||||
def webcam_preview(root: ctk.CTk, camera_index: int):
|
def webcam_preview(root: ctk.CTk, camera_index: int): # Added camera_index parameter
|
||||||
if not modules.globals.map_faces:
|
if not modules.globals.map_faces:
|
||||||
if modules.globals.source_path is None:
|
if modules.globals.source_path is None:
|
||||||
# No image selected
|
# No image selected
|
||||||
return
|
return
|
||||||
create_webcam_preview(camera_index)
|
create_webcam_preview(
|
||||||
|
camera_index
|
||||||
|
) # Pass camera_index to create_webcam_preview
|
||||||
else:
|
else:
|
||||||
modules.globals.souce_target_map = []
|
modules.globals.souce_target_map = []
|
||||||
create_source_target_popup_for_webcam(
|
create_source_target_popup_for_webcam(root, modules.globals.souce_target_map)
|
||||||
root, modules.globals.souce_target_map, camera_index
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_available_cameras():
|
def get_available_cameras():
|
||||||
|
@ -680,10 +669,10 @@ def get_available_cameras():
|
||||||
return (camera_indices, camera_names)
|
return (camera_indices, camera_names)
|
||||||
|
|
||||||
|
|
||||||
def create_webcam_preview(camera_index: int):
|
def create_webcam_preview(camera_index: int): # Added camera_index parameter
|
||||||
global preview_label, PREVIEW
|
global preview_label, PREVIEW
|
||||||
|
|
||||||
camera = cv2.VideoCapture(camera_index)
|
camera = cv2.VideoCapture(camera_index) # Use the provided camera index
|
||||||
camera.set(cv2.CAP_PROP_FRAME_WIDTH, PREVIEW_DEFAULT_WIDTH)
|
camera.set(cv2.CAP_PROP_FRAME_WIDTH, PREVIEW_DEFAULT_WIDTH)
|
||||||
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, PREVIEW_DEFAULT_HEIGHT)
|
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, PREVIEW_DEFAULT_HEIGHT)
|
||||||
camera.set(cv2.CAP_PROP_FPS, 60)
|
camera.set(cv2.CAP_PROP_FPS, 60)
|
||||||
|
@ -695,8 +684,6 @@ def create_webcam_preview(camera_index: int):
|
||||||
frame_processors = get_frame_processors_modules(modules.globals.frame_processors)
|
frame_processors = get_frame_processors_modules(modules.globals.frame_processors)
|
||||||
|
|
||||||
source_image = None
|
source_image = None
|
||||||
prev_time = time.time()
|
|
||||||
fps = 0
|
|
||||||
|
|
||||||
while camera:
|
while camera:
|
||||||
ret, frame = camera.read()
|
ret, frame = camera.read()
|
||||||
|
@ -725,22 +712,6 @@ def create_webcam_preview(camera_index: int):
|
||||||
for frame_processor in frame_processors:
|
for frame_processor in frame_processors:
|
||||||
temp_frame = frame_processor.process_frame_v2(temp_frame)
|
temp_frame = frame_processor.process_frame_v2(temp_frame)
|
||||||
|
|
||||||
# Calculate and display FPS
|
|
||||||
current_time = time.time()
|
|
||||||
fps = 1 / (current_time - prev_time)
|
|
||||||
prev_time = current_time
|
|
||||||
|
|
||||||
if modules.globals.show_fps:
|
|
||||||
cv2.putText(
|
|
||||||
temp_frame,
|
|
||||||
f"FPS: {fps:.2f}",
|
|
||||||
(10, 30),
|
|
||||||
cv2.FONT_HERSHEY_SIMPLEX,
|
|
||||||
1,
|
|
||||||
(0, 255, 0),
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
|
|
||||||
image = cv2.cvtColor(temp_frame, cv2.COLOR_BGR2RGB)
|
image = cv2.cvtColor(temp_frame, cv2.COLOR_BGR2RGB)
|
||||||
image = Image.fromarray(image)
|
image = Image.fromarray(image)
|
||||||
image = ImageOps.contain(
|
image = ImageOps.contain(
|
||||||
|
@ -757,9 +728,7 @@ def create_webcam_preview(camera_index: int):
|
||||||
PREVIEW.withdraw()
|
PREVIEW.withdraw()
|
||||||
|
|
||||||
|
|
||||||
def create_source_target_popup_for_webcam(
|
def create_source_target_popup_for_webcam(root: ctk.CTk, map: list) -> None:
|
||||||
root: ctk.CTk, map: list, camera_index: int
|
|
||||||
) -> None:
|
|
||||||
global POPUP_LIVE, popup_status_label_live
|
global POPUP_LIVE, popup_status_label_live
|
||||||
|
|
||||||
POPUP_LIVE = ctk.CTkToplevel(root)
|
POPUP_LIVE = ctk.CTkToplevel(root)
|
||||||
|
@ -771,9 +740,9 @@ def create_source_target_popup_for_webcam(
|
||||||
if has_valid_map():
|
if has_valid_map():
|
||||||
POPUP_LIVE.destroy()
|
POPUP_LIVE.destroy()
|
||||||
simplify_maps()
|
simplify_maps()
|
||||||
create_webcam_preview(camera_index)
|
create_webcam_preview()
|
||||||
else:
|
else:
|
||||||
update_pop_live_status("At least 1 source with target is required!")
|
update_pop_live_status("Atleast 1 source with target is required!")
|
||||||
|
|
||||||
def on_add_click():
|
def on_add_click():
|
||||||
add_blank_map()
|
add_blank_map()
|
||||||
|
|
Loading…
Reference in New Issue