Add a processer bar with remain time for CLI
This commit is contained in:
parent
38fb60efca
commit
cfd29513b4
@ -1,42 +1,45 @@
|
|||||||
import os
|
import os
|
||||||
|
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.config import get_face
|
||||||
|
from tqdm import tqdm
|
||||||
FACE_SWAPPER = None
|
|
||||||
|
FACE_SWAPPER = None
|
||||||
|
|
||||||
def get_face_swapper():
|
|
||||||
global FACE_SWAPPER
|
def get_face_swapper():
|
||||||
if FACE_SWAPPER is None:
|
global FACE_SWAPPER
|
||||||
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx')
|
if FACE_SWAPPER is None:
|
||||||
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=core.globals.providers)
|
model_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '../inswapper_128.onnx')
|
||||||
return FACE_SWAPPER
|
FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=core.globals.providers)
|
||||||
|
return FACE_SWAPPER
|
||||||
|
|
||||||
def process_video(source_img, frame_paths):
|
|
||||||
source_face = get_face(cv2.imread(source_img))
|
def process_video(source_img, frame_paths):
|
||||||
for frame_path in frame_paths:
|
source_face = get_face(cv2.imread(source_img))
|
||||||
frame = cv2.imread(frame_path)
|
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 pbar:
|
||||||
try:
|
for frame_path in frame_paths:
|
||||||
face = get_face(frame)
|
frame = cv2.imread(frame_path)
|
||||||
if face:
|
try:
|
||||||
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
face = get_face(frame)
|
||||||
cv2.imwrite(frame_path, result)
|
if face:
|
||||||
print('.', end='', flush=True)
|
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
||||||
else:
|
cv2.imwrite(frame_path, result)
|
||||||
print('S', end='', flush=True)
|
pbar.set_postfix(status='.', refresh=True)
|
||||||
except Exception:
|
else:
|
||||||
print('E', end='', flush=True)
|
pbar.set_postfix(status='S', refresh=True)
|
||||||
pass
|
except Exception:
|
||||||
|
pbar.set_postfix(status='E', refresh=True)
|
||||||
|
pass
|
||||||
def process_img(source_img, target_path, output_file):
|
pbar.update(1)
|
||||||
frame = cv2.imread(target_path)
|
|
||||||
face = get_face(frame)
|
|
||||||
source_face = get_face(cv2.imread(source_img))
|
def process_img(source_img, target_path, output_file):
|
||||||
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
frame = cv2.imread(target_path)
|
||||||
cv2.imwrite(output_file, result)
|
face = get_face(frame)
|
||||||
print("\n\nImage saved as:", output_file, "\n\n")
|
source_face = get_face(cv2.imread(source_img))
|
||||||
|
result = get_face_swapper().get(frame, face, source_face, paste_back=True)
|
||||||
|
cv2.imwrite(output_file, result)
|
||||||
|
print("\n\nImage saved as:", output_file, "\n\n")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user