diff --git a/faceswap.py b/faceswap.py index 012594e..e4f7a89 100755 --- a/faceswap.py +++ b/faceswap.py @@ -4,9 +4,22 @@ from face_enhancer import load_face_enhancer_model +def validate_image(img): + if not os.path.exists(img): + raise ValueError(f'Image {img} does not exist') + # check if img is a valid image file + if not os.path.isfile(img): + raise ValueError(f'Image {img} is not a valid image file') + # validate it to be jpg jpeg, png formats + if not img.lower().endswith(('.jpg', '.jpeg', '.png')): + raise ValueError(f'Image {img} is not a valid image file') + def swap_n_show(img1_fn, img2_fn, app, swapper, plot_before=False, plot_after=True, enhance=False, enhancer='REAL-ESRGAN 2x'): + validate_image(img1_fn) + validate_image(img2_fn) + img1 = cv2.imread(img1_fn) img2 = cv2.imread(img2_fn) @@ -42,6 +55,8 @@ def swap_n_show_same_img(img1_fn, app, swapper, plot_before=False, plot_after=True, enhance=False, enhancer='REAL-ESRGAN 2x'): + + validate_image(img1_fn) img1 = cv2.imread(img1_fn) if plot_before: @@ -69,6 +84,9 @@ def swap_n_show_same_img(img1_fn, def swap_face_single(img1_fn, img2_fn, app, swapper, plot_before=False, plot_after=True, enhance=False, enhancer='REAL-ESRGAN 2x'): + validate_image(img1_fn) + validate_image(img2_fn) + img1 = cv2.imread(img1_fn) img2 = cv2.imread(img2_fn) diff --git a/images/Anushka.jpg b/images/Anushka.jpg new file mode 100644 index 0000000..fc336e0 Binary files /dev/null and b/images/Anushka.jpg differ diff --git a/images/bramhi.jpg b/images/bramhi.jpg deleted file mode 100755 index d2f2d03..0000000 Binary files a/images/bramhi.jpg and /dev/null differ diff --git a/images/keerthi.jpg b/images/keerthi.jpg new file mode 100644 index 0000000..d4160f1 Binary files /dev/null and b/images/keerthi.jpg differ diff --git a/images/modi.jpg b/images/modi.jpg deleted file mode 100755 index 98c3465..0000000 Binary files a/images/modi.jpg and /dev/null differ diff --git a/images/result.png b/images/result.png index 71923b2..281a60a 100755 Binary files a/images/result.png and b/images/result.png differ diff --git a/main.py b/main.py index f43be5f..0470204 100755 --- a/main.py +++ b/main.py @@ -18,8 +18,8 @@ swapper = insightface.model_zoo.get_model('inswapper/inswapper_128.onnx', download=False, download_zip=False) # Load images -img1_fn = 'images/bramhi.jpg' -img2_fn = 'images/modi.jpg' +img1_fn = 'images/Anushka.jpg' +img2_fn = 'images/keerthi.jpg' # Swap faces between two images # swap_n_show(img1_fn, img2_fn, app, swapper)