Spaces:
Running
Running
justin2341
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ from facebox import FaceBox
|
|
18 |
|
19 |
verifyThreshold = 0.67
|
20 |
|
21 |
-
maxFaceCount =
|
22 |
|
23 |
licensePath = "license.txt"
|
24 |
license = ""
|
@@ -90,49 +90,67 @@ def compare_face():
|
|
90 |
faceBoxes2 = (FaceBox * maxFaceCount)()
|
91 |
faceCount2 = faceDetection(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2, maxFaceCount)
|
92 |
|
93 |
-
|
94 |
-
|
95 |
-
templateExtraction(
|
96 |
-
|
97 |
-
if similarity > verifyThreshold:
|
98 |
-
result = "Same person"
|
99 |
-
else:
|
100 |
-
result = "Different person"
|
101 |
-
elif faceCount1 == 0:
|
102 |
-
result = "No face1"
|
103 |
-
elif faceCount2 == 0:
|
104 |
-
result = "No face2"
|
105 |
-
|
106 |
-
if faceCount1 == 1:
|
107 |
landmark_68 = []
|
108 |
for j in range(68):
|
109 |
-
landmark_68.append({"x": faceBoxes1[
|
110 |
|
111 |
-
|
112 |
-
"yaw": faceBoxes1[
|
113 |
-
"face_quality": faceBoxes1[
|
114 |
-
"left_eye_closed": faceBoxes1[
|
115 |
-
"face_occlusion": faceBoxes1[
|
116 |
"landmark_68": landmark_68}
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
-
if faceCount2 == 1:
|
119 |
landmark_68 = []
|
120 |
for j in range(68):
|
121 |
-
landmark_68.append({"x": faceBoxes2[
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
"
|
126 |
-
"
|
127 |
-
"
|
|
|
128 |
"landmark_68": landmark_68}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
135 |
|
|
|
|
|
|
|
|
|
136 |
@app.route('/compare_face_base64', methods=['POST'])
|
137 |
def compare_face_base64():
|
138 |
result = "None"
|
@@ -175,48 +193,66 @@ def compare_face_base64():
|
|
175 |
faceBoxes2 = (FaceBox * maxFaceCount)()
|
176 |
faceCount2 = faceDetection(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2, maxFaceCount)
|
177 |
|
178 |
-
|
179 |
-
|
180 |
-
templateExtraction(
|
181 |
-
|
182 |
-
if similarity > verifyThreshold:
|
183 |
-
result = "Same person"
|
184 |
-
else:
|
185 |
-
result = "Different person"
|
186 |
-
elif faceCount1 == 0:
|
187 |
-
result = "No face1"
|
188 |
-
elif faceCount2 == 0:
|
189 |
-
result = "No face2"
|
190 |
-
|
191 |
-
if faceCount1 == 1:
|
192 |
landmark_68 = []
|
193 |
for j in range(68):
|
194 |
-
landmark_68.append({"x": faceBoxes1[
|
195 |
|
196 |
-
|
197 |
-
"yaw": faceBoxes1[
|
198 |
-
"face_quality": faceBoxes1[
|
199 |
-
"left_eye_closed": faceBoxes1[
|
200 |
-
"face_occlusion": faceBoxes1[
|
201 |
"landmark_68": landmark_68}
|
|
|
|
|
|
|
|
|
|
|
202 |
|
203 |
-
if faceCount2 == 1:
|
204 |
landmark_68 = []
|
205 |
for j in range(68):
|
206 |
-
landmark_68.append({"x": faceBoxes2[
|
|
|
207 |
|
208 |
-
|
209 |
-
"yaw": faceBoxes2[
|
210 |
-
"face_quality": faceBoxes2[
|
211 |
-
"left_eye_closed": faceBoxes2[
|
212 |
-
"face_occlusion": faceBoxes2[
|
213 |
"landmark_68": landmark_68}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
if __name__ == '__main__':
|
222 |
port = int(os.environ.get("PORT", 8080))
|
|
|
18 |
|
19 |
verifyThreshold = 0.67
|
20 |
|
21 |
+
maxFaceCount = 8
|
22 |
|
23 |
licensePath = "license.txt"
|
24 |
license = ""
|
|
|
90 |
faceBoxes2 = (FaceBox * maxFaceCount)()
|
91 |
faceCount2 = faceDetection(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2, maxFaceCount)
|
92 |
|
93 |
+
faces1_result = []
|
94 |
+
for i in range(faceCount1):
|
95 |
+
templateExtraction(image_np1, image_np1.shape[1], image_np1.shape[0], faceBoxes1[i])
|
96 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
landmark_68 = []
|
98 |
for j in range(68):
|
99 |
+
landmark_68.append({"x": faceBoxes1[i].landmark_68[j * 2], "y": faceBoxes1[i].landmark_68[j * 2 + 1]})
|
100 |
|
101 |
+
face = {"x1": faceBoxes1[i].x1, "y1": faceBoxes1[i].y1, "x2": faceBoxes1[i].x2, "y2": faceBoxes1[i].y2,
|
102 |
+
"yaw": faceBoxes1[i].yaw, "roll": faceBoxes1[i].roll, "pitch": faceBoxes1[i].pitch,
|
103 |
+
"face_quality": faceBoxes1[i].face_quality, "face_luminance": faceBoxes1[i].face_luminance, "eye_dist": faceBoxes1[i].eye_dist,
|
104 |
+
"left_eye_closed": faceBoxes1[i].left_eye_closed, "right_eye_closed": faceBoxes1[i].right_eye_closed,
|
105 |
+
"face_occlusion": faceBoxes1[i].face_occlusion, "mouth_opened": faceBoxes1[i].mouth_opened,
|
106 |
"landmark_68": landmark_68}
|
107 |
+
|
108 |
+
faces1_result.append(face)
|
109 |
+
|
110 |
+
for i in range(faceCount2):
|
111 |
+
templateExtraction(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2[i])
|
112 |
|
|
|
113 |
landmark_68 = []
|
114 |
for j in range(68):
|
115 |
+
landmark_68.append({"x": faceBoxes2[i].landmark_68[j * 2], "y": faceBoxes2[i].landmark_68[j * 2 + 1]})
|
116 |
|
117 |
+
|
118 |
+
face = {"x1": faceBoxes2[i].x1, "y1": faceBoxes2[i].y1, "x2": faceBoxes2[i].x2, "y2": faceBoxes2[i].y2,
|
119 |
+
"yaw": faceBoxes2[i].yaw, "roll": faceBoxes2[i].roll, "pitch": faceBoxes2[i].pitch,
|
120 |
+
"face_quality": faceBoxes2[i].face_quality, "face_luminance": faceBoxes2[i].face_luminance, "eye_dist": faceBoxes2[i].eye_dist,
|
121 |
+
"left_eye_closed": faceBoxes2[i].left_eye_closed, "right_eye_closed": faceBoxes2[i].right_eye_closed,
|
122 |
+
"face_occlusion": faceBoxes2[i].face_occlusion, "mouth_opened": faceBoxes2[i].mouth_opened,
|
123 |
"landmark_68": landmark_68}
|
124 |
+
|
125 |
+
faces2_result.append(face)
|
126 |
+
|
127 |
+
|
128 |
+
if faceCount1 > 0 and faceCount2 > 0:
|
129 |
+
results = []
|
130 |
+
for i in range(faceCount1):
|
131 |
+
for j in range(faceCount2):
|
132 |
+
similarity = similarityCalculation(faceBoxes1[i].templates, faceBoxes2[j].templates)
|
133 |
+
match_result = {"face1": i, "face2": j, "similarity": similarity}
|
134 |
+
results.append(match_result)
|
135 |
+
|
136 |
+
response = jsonify({"resultCode": "Ok", "faces1": faces1_result, "faces2": faces2_result, "results": results})
|
137 |
|
138 |
+
response.status_code = 200
|
139 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
140 |
+
return response
|
141 |
+
elif faceNum1 == 0:
|
142 |
+
response = jsonify({"resultCode": "No face1", "faces1": faces1, "faces2": faces2})
|
143 |
|
144 |
+
response.status_code = 200
|
145 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
146 |
+
return response
|
147 |
+
elif faceNum2 == 0:
|
148 |
+
response = jsonify({"resultCode": "No face2", "faces1": faces1, "faces2": faces2})
|
149 |
|
150 |
+
response.status_code = 200
|
151 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
152 |
+
return response
|
153 |
+
|
154 |
@app.route('/compare_face_base64', methods=['POST'])
|
155 |
def compare_face_base64():
|
156 |
result = "None"
|
|
|
193 |
faceBoxes2 = (FaceBox * maxFaceCount)()
|
194 |
faceCount2 = faceDetection(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2, maxFaceCount)
|
195 |
|
196 |
+
faces1_result = []
|
197 |
+
for i in range(faceCount1):
|
198 |
+
templateExtraction(image_np1, image_np1.shape[1], image_np1.shape[0], faceBoxes1[i])
|
199 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
landmark_68 = []
|
201 |
for j in range(68):
|
202 |
+
landmark_68.append({"x": faceBoxes1[i].landmark_68[j * 2], "y": faceBoxes1[i].landmark_68[j * 2 + 1]})
|
203 |
|
204 |
+
face = {"x1": faceBoxes1[i].x1, "y1": faceBoxes1[i].y1, "x2": faceBoxes1[i].x2, "y2": faceBoxes1[i].y2,
|
205 |
+
"yaw": faceBoxes1[i].yaw, "roll": faceBoxes1[i].roll, "pitch": faceBoxes1[i].pitch,
|
206 |
+
"face_quality": faceBoxes1[i].face_quality, "face_luminance": faceBoxes1[i].face_luminance, "eye_dist": faceBoxes1[i].eye_dist,
|
207 |
+
"left_eye_closed": faceBoxes1[i].left_eye_closed, "right_eye_closed": faceBoxes1[i].right_eye_closed,
|
208 |
+
"face_occlusion": faceBoxes1[i].face_occlusion, "mouth_opened": faceBoxes1[i].mouth_opened,
|
209 |
"landmark_68": landmark_68}
|
210 |
+
|
211 |
+
faces1_result.append(face)
|
212 |
+
|
213 |
+
for i in range(faceCount2):
|
214 |
+
templateExtraction(image_np2, image_np2.shape[1], image_np2.shape[0], faceBoxes2[i])
|
215 |
|
|
|
216 |
landmark_68 = []
|
217 |
for j in range(68):
|
218 |
+
landmark_68.append({"x": faceBoxes2[i].landmark_68[j * 2], "y": faceBoxes2[i].landmark_68[j * 2 + 1]})
|
219 |
+
|
220 |
|
221 |
+
face = {"x1": faceBoxes2[i].x1, "y1": faceBoxes2[i].y1, "x2": faceBoxes2[i].x2, "y2": faceBoxes2[i].y2,
|
222 |
+
"yaw": faceBoxes2[i].yaw, "roll": faceBoxes2[i].roll, "pitch": faceBoxes2[i].pitch,
|
223 |
+
"face_quality": faceBoxes2[i].face_quality, "face_luminance": faceBoxes2[i].face_luminance, "eye_dist": faceBoxes2[i].eye_dist,
|
224 |
+
"left_eye_closed": faceBoxes2[i].left_eye_closed, "right_eye_closed": faceBoxes2[i].right_eye_closed,
|
225 |
+
"face_occlusion": faceBoxes2[i].face_occlusion, "mouth_opened": faceBoxes2[i].mouth_opened,
|
226 |
"landmark_68": landmark_68}
|
227 |
+
|
228 |
+
faces2_result.append(face)
|
229 |
+
|
230 |
+
|
231 |
+
if faceCount1 > 0 and faceCount2 > 0:
|
232 |
+
results = []
|
233 |
+
for i in range(faceCount1):
|
234 |
+
for j in range(faceCount2):
|
235 |
+
similarity = similarityCalculation(faceBoxes1[i].templates, faceBoxes2[j].templates)
|
236 |
+
match_result = {"face1": i, "face2": j, "similarity": similarity}
|
237 |
+
results.append(match_result)
|
238 |
|
239 |
+
response = jsonify({"resultCode": "Ok", "faces1": faces1_result, "faces2": faces2_result, "results": results})
|
240 |
+
|
241 |
+
response.status_code = 200
|
242 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
243 |
+
return response
|
244 |
+
elif faceNum1 == 0:
|
245 |
+
response = jsonify({"resultCode": "No face1", "faces1": faces1, "faces2": faces2})
|
246 |
|
247 |
+
response.status_code = 200
|
248 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
249 |
+
return response
|
250 |
+
elif faceNum2 == 0:
|
251 |
+
response = jsonify({"resultCode": "No face2", "faces1": faces1, "faces2": faces2})
|
252 |
+
|
253 |
+
response.status_code = 200
|
254 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
255 |
+
return response
|
256 |
|
257 |
if __name__ == '__main__':
|
258 |
port = int(os.environ.get("PORT", 8080))
|