-
Notifications
You must be signed in to change notification settings - Fork 3
/
Final.py
60 lines (53 loc) · 2.15 KB
/
Final.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from commonfunctions import *
from PIL import Image, ImageDraw
import cv2
from skimage.filters import median
import numpy as np
import skimage.io as io
from skimage.color import rgb2gray, rgb2hsv, hsv2rgb
from skimage.morphology import binary_erosion, binary_dilation, binary_closing, skeletonize, thin
import face_recognition
import imutils
from landmark_detection import *
from functions import *
drawpoint = False
drawtri = False
from PIL import Image
import cv2
face2 = io.imread("images/sanad.jpg") # host el soora ely ha5odha menko ya shabab
show_images([face2])
face1 = io.imread("images/atwa.jpeg") # to be swapped
#emotion=hf.getemotion(face2,path1,path2)
emotion = "Happy"
if emotion=="Happy":
face1 = io.imread("images/atwa.jpeg") # to be swapped
elif emotion=="Angry":
face1 = io.imread("images/angry.jpg") # to be swapped
elif emotion=="Sad":
face1 = io.imread("images/sad.jpeg") # to be swapped
elif emotion=="Surprised":
face1 = io.imread("images/surprised.jpeg") # to be swapped
elif emotion=="Neutral":
face1 = io.imread("images/sayed.jpg")
elif emotion=="Other":
face1 = io.imread("images/atwa.jpeg") # to be swapped
# Face to swap
points1 = detect_landmarks(face1)[0] # points of face to swap
points2 = detect_landmarks(face2)
for i in range(len(points2)):
drawPoints(points1, face1, drawpoint)
hullPointsList1, hullPointsList2, hullIndex = convexHull(face1, points1, points2[i], False)
triangleList1 = getDelaunayTriangulation(face1.shape, hullPointsList1)
triangleList2 = getOtherDelaunayTriangulation(triangleList1, hullPointsList1, hullIndex, points2[i])
drawDelaunayTriangulation(face1, triangleList1, drawtri)
drawOther(face2, triangleList2, drawtri)
facecpy = np.copy(face2)
morphedface = face2
triangleList1 = triListforMorph(triangleList1)
for i in range(len(triangleList1)):
morphing(face1, triangleList1[i].astype(int), morphedface, triangleList2[i].astype(int))
# show_images([morphedface])
output = applymask(facecpy, hullPointsList2, morphedface)
show_images([output])
face2 = output
show_images([face2])