Merge branch 'main' into main
This commit is contained in:
commit
c10e37cd2f
@ -31,11 +31,10 @@ def process_video(source_img, frame_paths):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def process_img(source_img, target_path):
|
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 = face_swapper.get(frame, face, source_face, paste_back=True)
|
result = face_swapper.get(frame, face, source_face, paste_back=True)
|
||||||
target_path = rreplace(target_path, "/", "/swapped-", 1) if "/" in target_path else "swapped-" + target_path
|
cv2.imwrite(output_file, result)
|
||||||
print(target_path)
|
print("\n\nImage saved as:", output_file, "\n\n")
|
||||||
cv2.imwrite(target_path, result)
|
|
9
run.py
9
run.py
@ -154,7 +154,10 @@ def toggle_keep_frames():
|
|||||||
|
|
||||||
|
|
||||||
def save_file():
|
def save_file():
|
||||||
args['output_file'] = asksaveasfilename(initialfile='output.mp4', defaultextension=".mp4", filetypes=[("All Files","*.*"),("Videos","*.mp4")])
|
filename, ext = 'output.mp4', '.mp4'
|
||||||
|
if is_img(args['target_path']):
|
||||||
|
filename, ext = 'output.png', '.png'
|
||||||
|
args['output_file'] = asksaveasfilename(initialfile=filename, defaultextension=ext, filetypes=[("All Files","*.*"),("Videos","*.mp4")])
|
||||||
|
|
||||||
|
|
||||||
def status(string):
|
def status(string):
|
||||||
@ -173,6 +176,8 @@ def start():
|
|||||||
elif not args['target_path'] or not os.path.isfile(args['target_path']):
|
elif not args['target_path'] or not os.path.isfile(args['target_path']):
|
||||||
print("\n[WARNING] Please select a video/image to swap face in.")
|
print("\n[WARNING] Please select a video/image to swap face in.")
|
||||||
return
|
return
|
||||||
|
if not args['output_file']:
|
||||||
|
args['output_file'] = rreplace(args['target_path'], "/", "/swapped-", 1) if "/" in target_path else "swapped-"+target_path
|
||||||
global pool
|
global pool
|
||||||
pool = mp.Pool(psutil.cpu_count()-1)
|
pool = mp.Pool(psutil.cpu_count()-1)
|
||||||
target_path = args['target_path']
|
target_path = args['target_path']
|
||||||
@ -181,7 +186,7 @@ def start():
|
|||||||
print("\n[WARNING] No face detected in source image. Please try with another one.\n")
|
print("\n[WARNING] No face detected in source image. Please try with another one.\n")
|
||||||
return
|
return
|
||||||
if is_img(target_path):
|
if is_img(target_path):
|
||||||
process_img(args['source_img'], target_path)
|
process_img(args['source_img'], target_path, args['output_file'])
|
||||||
status("swap successful!")
|
status("swap successful!")
|
||||||
return
|
return
|
||||||
video_name = target_path.split("/")[-1].split(".")[0]
|
video_name = target_path.split("/")[-1].split(".")[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user