Spaces:
Runtime error
Runtime error
Update create_gif.py
Browse files- create_gif.py +4 -33
create_gif.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# USAGE
|
2 |
-
# python create_gif.py --config config.json --image images/
|
3 |
|
4 |
# import the necessary packages
|
5 |
from imutils import face_utils
|
@@ -15,8 +15,6 @@ import sys
|
|
15 |
import os
|
16 |
|
17 |
|
18 |
-
|
19 |
-
|
20 |
def overlay_image(bg, fg, fgMask, coords):
|
21 |
|
22 |
(sH, sW) = fg.shape[:2]
|
@@ -33,8 +31,6 @@ def overlay_image(bg, fg, fgMask, coords):
|
|
33 |
|
34 |
|
35 |
output = alpha_blend(overlay, bg, alpha)
|
36 |
-
|
37 |
-
|
38 |
return output
|
39 |
|
40 |
def alpha_blend(fg, bg, alpha):
|
@@ -43,7 +39,7 @@ def alpha_blend(fg, bg, alpha):
|
|
43 |
bg = bg.astype("float")
|
44 |
alpha = alpha.astype("float") / 255
|
45 |
|
46 |
-
|
47 |
fg = cv2.multiply(alpha, fg)
|
48 |
bg = cv2.multiply(1 - alpha, bg)
|
49 |
|
@@ -59,7 +55,7 @@ def get_features(img_rd,*args):
|
|
59 |
# 输入: img_rd: 图像文件
|
60 |
# 输出: pos_69to81: feature 69 to feature 81, 13 feature points in all, 40 points
|
61 |
detector1 = dlib.get_frontal_face_detector()
|
62 |
-
predictor1=dlib.shape_predictor(
|
63 |
# read img file
|
64 |
img = cv2.imread(img_rd)
|
65 |
# 取灰度
|
@@ -75,13 +71,6 @@ def get_features(img_rd,*args):
|
|
75 |
pos = (point[0, 0], point[0, 1])
|
76 |
pos_81.append(pos)
|
77 |
|
78 |
-
# pos_69to81 = []
|
79 |
-
# # 将点 69-81 写入 CSV
|
80 |
-
# # 即 pos_81[68]-pos_81[80]
|
81 |
-
# for i in range(68, 81):
|
82 |
-
# pos_69to81.append(pos_81[i][0])
|
83 |
-
# pos_69to81.append(pos_81[i][1])
|
84 |
-
# return pos_69to81
|
85 |
get_pos=[]
|
86 |
get_pos.append((pos_81[args[0]][0],pos_81[args[0]][1]))
|
87 |
get_pos.append((pos_81[args[1]][0],pos_81[args[1]][1]))
|
@@ -157,28 +146,10 @@ shape = predictor(image, rect)
|
|
157 |
shape = face_utils.shape_to_np(shape)
|
158 |
|
159 |
forehead=get_features(args["image"],76,73)
|
160 |
-
|
161 |
-
|
162 |
-
# print("LANDMARKS_IDXS"+str(face_utils.FACIAL_LANDMARKS_IDXS))
|
163 |
-
# (lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
|
164 |
-
# (rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
|
165 |
-
# leftEyePts = shape[lStart:lEnd]
|
166 |
-
# rightEyePts = shape[rStart:rEnd]
|
167 |
-
#
|
168 |
-
# # compute the center of mass for each eye
|
169 |
-
# leftEyeCenter = leftEyePts.mean(axis=0).astype("int")
|
170 |
-
# rightEyeCenter = rightEyePts.mean(axis=0).astype("int")
|
171 |
-
|
172 |
-
# compute the angle between the eye centroids
|
173 |
-
# dY = rightEyeCenter[1] - leftEyeCenter[1]
|
174 |
-
# dX = rightEyeCenter[0] - leftEyeCenter[0]
|
175 |
-
# angle = np.degrees(np.arctan2(dY, dX)) - 180
|
176 |
left_point=forehead[0]
|
177 |
right_point=forehead[1]
|
178 |
|
179 |
-
# left_point=shape[75].astype(int)
|
180 |
-
# right_point=shape[79].astype(int)
|
181 |
-
|
182 |
dY=left_point[1]-right_point[1]
|
183 |
dX=left_point[0]-right_point[0]
|
184 |
print("left_point:"+str(left_point[1]))
|
1 |
# USAGE
|
2 |
+
# python create_gif.py --config config.json --image images/me.jpg --output me.gif
|
3 |
|
4 |
# import the necessary packages
|
5 |
from imutils import face_utils
|
15 |
import os
|
16 |
|
17 |
|
|
|
|
|
18 |
def overlay_image(bg, fg, fgMask, coords):
|
19 |
|
20 |
(sH, sW) = fg.shape[:2]
|
31 |
|
32 |
|
33 |
output = alpha_blend(overlay, bg, alpha)
|
|
|
|
|
34 |
return output
|
35 |
|
36 |
def alpha_blend(fg, bg, alpha):
|
39 |
bg = bg.astype("float")
|
40 |
alpha = alpha.astype("float") / 255
|
41 |
|
42 |
+
|
43 |
fg = cv2.multiply(alpha, fg)
|
44 |
bg = cv2.multiply(1 - alpha, bg)
|
45 |
|
55 |
# 输入: img_rd: 图像文件
|
56 |
# 输出: pos_69to81: feature 69 to feature 81, 13 feature points in all, 40 points
|
57 |
detector1 = dlib.get_frontal_face_detector()
|
58 |
+
predictor1=dlib.shape_predictor("shape_predictor_81_face_landmarks.dat")
|
59 |
# read img file
|
60 |
img = cv2.imread(img_rd)
|
61 |
# 取灰度
|
71 |
pos = (point[0, 0], point[0, 1])
|
72 |
pos_81.append(pos)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
get_pos=[]
|
75 |
get_pos.append((pos_81[args[0]][0],pos_81[args[0]][1]))
|
76 |
get_pos.append((pos_81[args[1]][0],pos_81[args[1]][1]))
|
146 |
shape = face_utils.shape_to_np(shape)
|
147 |
|
148 |
forehead=get_features(args["image"],76,73)
|
149 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
left_point=forehead[0]
|
151 |
right_point=forehead[1]
|
152 |
|
|
|
|
|
|
|
153 |
dY=left_point[1]-right_point[1]
|
154 |
dX=left_point[0]-right_point[0]
|
155 |
print("left_point:"+str(left_point[1]))
|