Rename files
This commit is contained in:
parent
91b7301f32
commit
5aa91e9157
@ -1,44 +1,44 @@
|
|||||||
import os
|
import os
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
import cv2
|
import cv2
|
||||||
import insightface
|
import insightface
|
||||||
import core.globals
|
import core.globals
|
||||||
from core.config import get_face
|
from core.analyser import get_face
|
||||||
|
|
||||||
FACE_SWAPPER = None
|
FACE_SWAPPER = None
|
||||||
|
|
||||||
|
|
||||||
def get_face_swapper():
|
def get_face_swapper():
|
||||||
global FACE_SWAPPER
|
global FACE_SWAPPER
|
||||||
if FACE_SWAPPER is None:
|
if FACE_SWAPPER is None:
|
||||||
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx')
|
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx')
|
||||||
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=core.globals.providers)
|
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=core.globals.providers)
|
||||||
return FACE_SWAPPER
|
return FACE_SWAPPER
|
||||||
|
|
||||||
|
|
||||||
def process_video(source_img, frame_paths):
|
def process_video(source_img, frame_paths):
|
||||||
source_face = get_face(cv2.imread(source_img))
|
source_face = get_face(cv2.imread(source_img))
|
||||||
with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]') as progress:
|
with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]') as progress:
|
||||||
for frame_path in frame_paths:
|
for frame_path in frame_paths:
|
||||||
frame = cv2.imread(frame_path)
|
frame = cv2.imread(frame_path)
|
||||||
try:
|
try:
|
||||||
face = get_face(frame)
|
face = get_face(frame)
|
||||||
if face:
|
if face:
|
||||||
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
||||||
cv2.imwrite(frame_path, result)
|
cv2.imwrite(frame_path, result)
|
||||||
progress.set_postfix(status='.', refresh=True)
|
progress.set_postfix(status='.', refresh=True)
|
||||||
else:
|
else:
|
||||||
progress.set_postfix(status='S', refresh=True)
|
progress.set_postfix(status='S', refresh=True)
|
||||||
except Exception:
|
except Exception:
|
||||||
progress.set_postfix(status='E', refresh=True)
|
progress.set_postfix(status='E', refresh=True)
|
||||||
pass
|
pass
|
||||||
progress.update(1)
|
progress.update(1)
|
||||||
|
|
||||||
|
|
||||||
def process_img(source_img, target_path, output_file):
|
def process_img(source_img, target_path, output_file):
|
||||||
frame = cv2.imread(target_path)
|
frame = cv2.imread(target_path)
|
||||||
face = get_face(frame)
|
face = get_face(frame)
|
||||||
source_face = get_face(cv2.imread(source_img))
|
source_face = get_face(cv2.imread(source_img))
|
||||||
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
||||||
cv2.imwrite(output_file, result)
|
cv2.imwrite(output_file, result)
|
||||||
print("\n\nImage saved as:", output_file, "\n\n")
|
print("\n\nImage saved as:", output_file, "\n\n")
|
4
run.py
4
run.py
@ -21,9 +21,9 @@ import cv2
|
|||||||
import threading
|
import threading
|
||||||
from PIL import Image, ImageTk
|
from PIL import Image, ImageTk
|
||||||
import core.globals
|
import core.globals
|
||||||
from core.processor import process_video, process_img
|
from core.swapper import process_video, process_img
|
||||||
from core.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames, rreplace
|
from core.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames, rreplace
|
||||||
from core.config import get_face
|
from core.analyser import get_face
|
||||||
|
|
||||||
if 'ROCMExecutionProvider' in core.globals.providers:
|
if 'ROCMExecutionProvider' in core.globals.providers:
|
||||||
del torch
|
del torch
|
||||||
|
Loading…
x
Reference in New Issue
Block a user