Compare commits
4 Commits
c85d78f0e6
...
fb5c15ff43
Author | SHA1 | Date |
---|---|---|
|
fb5c15ff43 | |
|
3da987340b | |
|
a4216bf9ec | |
|
ab26413ce8 |
|
@ -379,6 +379,10 @@ For the latest experimental builds and features, see the [experimental branch](h
|
|||
|
||||
This is an open-source project developed in our free time. Updates may be delayed.
|
||||
|
||||
**Tips and Links:**
|
||||
- [How to make the most of Deep-Live-Cam](https://hacksider.gumroad.com/p/how-to-make-the-most-on-deep-live-cam)
|
||||
- Face enhancer is good, but still very slow for any live streaming purpose.
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
|
|
|
@ -9,23 +9,35 @@ import modules.processors.frame.core
|
|||
from modules.core import update_status
|
||||
from modules.face_analyser import get_one_face
|
||||
from modules.typing import Frame, Face
|
||||
from modules.utilities import conditional_download, resolve_relative_path, is_image, is_video
|
||||
from modules.utilities import (
|
||||
conditional_download,
|
||||
resolve_relative_path,
|
||||
is_image,
|
||||
is_video,
|
||||
)
|
||||
|
||||
FACE_ENHANCER = None
|
||||
THREAD_SEMAPHORE = threading.Semaphore()
|
||||
THREAD_LOCK = threading.Lock()
|
||||
NAME = 'DLC.FACE-ENHANCER'
|
||||
NAME = "DLC.FACE-ENHANCER"
|
||||
|
||||
|
||||
def pre_check() -> bool:
|
||||
download_directory_path = resolve_relative_path('..\models')
|
||||
conditional_download(download_directory_path, ['https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth'])
|
||||
download_directory_path = resolve_relative_path("..\models")
|
||||
conditional_download(
|
||||
download_directory_path,
|
||||
[
|
||||
"https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth"
|
||||
],
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def pre_start() -> bool:
|
||||
if not is_image(modules.globals.target_path) and not is_video(modules.globals.target_path):
|
||||
update_status('Select an image or video for target path.', NAME)
|
||||
if not is_image(modules.globals.target_path) and not is_video(
|
||||
modules.globals.target_path
|
||||
):
|
||||
update_status("Select an image or video for target path.", NAME)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -35,21 +47,18 @@ def get_face_enhancer() -> Any:
|
|||
|
||||
with THREAD_LOCK:
|
||||
if FACE_ENHANCER is None:
|
||||
if os.name == 'nt':
|
||||
model_path = resolve_relative_path('..\models\GFPGANv1.4.pth')
|
||||
if os.name == "nt":
|
||||
model_path = resolve_relative_path("..\models\GFPGANv1.4.pth")
|
||||
# todo: set models path https://github.com/TencentARC/GFPGAN/issues/399
|
||||
else:
|
||||
model_path = resolve_relative_path('../models/GFPGANv1.4.pth')
|
||||
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]
|
||||
model_path = resolve_relative_path("../models/GFPGANv1.4.pth")
|
||||
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined]
|
||||
return FACE_ENHANCER
|
||||
|
||||
|
||||
def enhance_face(temp_frame: Frame) -> Frame:
|
||||
with THREAD_SEMAPHORE:
|
||||
_, _, temp_frame = get_face_enhancer().enhance(
|
||||
temp_frame,
|
||||
paste_back=True
|
||||
)
|
||||
_, _, temp_frame = get_face_enhancer().enhance(temp_frame, paste_back=True)
|
||||
return temp_frame
|
||||
|
||||
|
||||
|
@ -60,7 +69,9 @@ def process_frame(source_face: Face, temp_frame: Frame) -> Frame:
|
|||
return temp_frame
|
||||
|
||||
|
||||
def process_frames(source_path: str, temp_frame_paths: List[str], progress: Any = None) -> None:
|
||||
def process_frames(
|
||||
source_path: str, temp_frame_paths: List[str], progress: Any = None
|
||||
) -> None:
|
||||
for temp_frame_path in temp_frame_paths:
|
||||
temp_frame = cv2.imread(temp_frame_path)
|
||||
result = process_frame(None, temp_frame)
|
||||
|
@ -77,3 +88,10 @@ def process_image(source_path: str, target_path: str, output_path: str) -> None:
|
|||
|
||||
def process_video(source_path: str, temp_frame_paths: List[str]) -> None:
|
||||
modules.processors.frame.core.process_video(None, temp_frame_paths, process_frames)
|
||||
|
||||
|
||||
def process_frame_v2(temp_frame: Frame) -> Frame:
|
||||
target_face = get_one_face(temp_frame)
|
||||
if target_face:
|
||||
temp_frame = enhance_face(temp_frame)
|
||||
return temp_frame
|
||||
|
|
|
@ -229,7 +229,7 @@ def create_root(start: Callable[[], None], destroy: Callable[[], None]) -> ctk.C
|
|||
color_correction_value = ctk.BooleanVar(value=modules.globals.color_correction)
|
||||
color_correction_switch = ctk.CTkSwitch(
|
||||
root,
|
||||
text="Fix Blueish Cam\n(force cv2 to use RGB instead of BGR)",
|
||||
text="Fix Blueish Cam",
|
||||
variable=color_correction_value,
|
||||
cursor="hand2",
|
||||
command=lambda: (
|
||||
|
@ -514,6 +514,12 @@ def update_pop_live_status(text: str) -> None:
|
|||
def update_tumbler(var: str, value: bool) -> None:
|
||||
modules.globals.fp_ui[var] = value
|
||||
save_switch_states()
|
||||
# If we're currently in a live preview, update the frame processors
|
||||
if PREVIEW.state() == "normal":
|
||||
global frame_processors
|
||||
frame_processors = get_frame_processors_modules(
|
||||
modules.globals.frame_processors
|
||||
)
|
||||
|
||||
|
||||
def select_source_path() -> None:
|
||||
|
@ -753,6 +759,8 @@ def create_webcam_preview(camera_index: int):
|
|||
|
||||
source_image = None
|
||||
prev_time = time.time()
|
||||
fps_update_interval = 0.5 # Update FPS every 0.5 seconds
|
||||
frame_count = 0
|
||||
fps = 0
|
||||
|
||||
while camera:
|
||||
|
@ -775,22 +783,33 @@ def create_webcam_preview(camera_index: int):
|
|||
source_image = get_one_face(cv2.imread(modules.globals.source_path))
|
||||
|
||||
for frame_processor in frame_processors:
|
||||
temp_frame = frame_processor.process_frame(source_image, temp_frame)
|
||||
if frame_processor.NAME == "DLC.FACE-ENHANCER":
|
||||
if modules.globals.fp_ui["face_enhancer"]:
|
||||
temp_frame = frame_processor.process_frame(None, temp_frame)
|
||||
else:
|
||||
temp_frame = frame_processor.process_frame(source_image, temp_frame)
|
||||
else:
|
||||
modules.globals.target_path = None
|
||||
|
||||
for frame_processor in frame_processors:
|
||||
temp_frame = frame_processor.process_frame_v2(temp_frame)
|
||||
if frame_processor.NAME == "DLC.FACE-ENHANCER":
|
||||
if modules.globals.fp_ui["face_enhancer"]:
|
||||
temp_frame = frame_processor.process_frame_v2(temp_frame)
|
||||
else:
|
||||
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
|
||||
frame_count += 1
|
||||
if current_time - prev_time >= fps_update_interval:
|
||||
fps = frame_count / (current_time - prev_time)
|
||||
frame_count = 0
|
||||
prev_time = current_time
|
||||
|
||||
if modules.globals.show_fps:
|
||||
cv2.putText(
|
||||
temp_frame,
|
||||
f"FPS: {fps:.2f}",
|
||||
f"FPS: {fps:.1f}",
|
||||
(10, 30),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
1,
|
||||
|
|
Loading…
Reference in New Issue