Python script that swaps the faces from one or two images.
The project has been inspired by the following resources:
-
This tutorial from by Sergio Canu.
-
The repo found in wuhuikai - FaceSwap has also been useful.
This is how the results look like:
And what the script does:
- The 81 points landmark detector model found in codeniko - shape_predictor_81_face_landmarks has been used.
We can swap the faces from one image:
import cv2
from face_swap import swap_faces
# Read images
img = cv2.imread("assets/img3.jpg")
# Swap faces
img_changed_faces = swap_faces(img)
# Show results
cv2.imshow("img_changed_faces", img_changed_faces)
cv2.waitKey(0)
Or we can also swap the faces from two images:
import cv2
from face_swap import swap_faces
# Read images
img = cv2.imread("assets/img1.jpg")
img2 = cv2.imread("assets/img2.jpg")
# Swap faces
img_changed_face, img2_changed_face = swap_faces(img, img2)
# Show results
cv2.imshow("img_changed_face", img_changed_face)
cv2.imshow("img2_changed_face", img2_changed_face)
cv2.waitKey(0)
- Oriol Bernal - oriolbernal