cadyderwin commited on
Commit
a7abf6d
·
verified ·
1 Parent(s): b01803f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -16,18 +16,19 @@ from opyfacerecog import processImage
16
  from opyfacerecog import verifyFeat
17
  from face import Face
18
 
19
- licenseKeyPath = "license.txt"
20
- license = ""
21
-
22
  maxFaceCount1 = 5
23
  maxFaceCount2 = 10
24
 
25
- try:
26
- with open(licenseKeyPath, 'r') as file:
27
- license = file.read().strip()
28
- except IOError as exc:
29
- print("failed to open license.txt: ", exc.errno)
30
- print("License Key: ", license)
 
 
 
 
31
 
32
  hwid = getHWID()
33
  print("HWID: ", hwid.decode('utf-8'))
@@ -171,25 +172,41 @@ def compare_face_base64():
171
  faces1 = (Face * maxFaceCount1)()
172
  faceNum1 = processImage(image_np1, image_np1.shape[1], image_np1.shape[0], faces1, maxFaceCount1)
173
 
 
 
 
 
 
174
  image_np2 = np.asarray(image2)
175
  faces2 = (Face * maxFaceCount1)()
176
  faceNum2 = processImage(image_np2, image_np2.shape[1], image_np2.shape[0], faces2, maxFaceCount1)
177
 
178
- if faceNum1 == 1 and faceNum2 == 1:
179
- score = verifyFeat(faces1[0].featSize, faces1[0].featData, faces2[0].featSize, faces2[0].featData)
180
- response = jsonify({"resultCode": "Ok", "score": score})
 
 
 
 
 
 
 
 
 
 
 
181
 
182
  response.status_code = 200
183
  response.headers["Content-Type"] = "application/json; charset=utf-8"
184
  return response
185
  elif faceNum1 == 0:
186
- response = jsonify({"resultCode": "No face1"})
187
 
188
  response.status_code = 200
189
  response.headers["Content-Type"] = "application/json; charset=utf-8"
190
  return response
191
  elif faceNum2 == 0:
192
- response = jsonify({"resultCode": "No face2"})
193
 
194
  response.status_code = 200
195
  response.headers["Content-Type"] = "application/json; charset=utf-8"
 
16
  from opyfacerecog import verifyFeat
17
  from face import Face
18
 
 
 
 
19
  maxFaceCount1 = 5
20
  maxFaceCount2 = 10
21
 
22
+ licenseKeyPath = "license.txt"
23
+ license = os.environ.get("LICENSE_KEY")
24
+
25
+ if license is None:
26
+ try:
27
+ with open(licenseKeyPath, 'r') as file:
28
+ license = file.read().strip()
29
+ except IOError as exc:
30
+ print("failed to open license.txt: ", exc.errno)
31
+ print("License Key: ", license)
32
 
33
  hwid = getHWID()
34
  print("HWID: ", hwid.decode('utf-8'))
 
172
  faces1 = (Face * maxFaceCount1)()
173
  faceNum1 = processImage(image_np1, image_np1.shape[1], image_np1.shape[0], faces1, maxFaceCount1)
174
 
175
+ faces1_result = []
176
+ for i in range(faceNum1):
177
+ face = {"x": faces1[i].x, "y": faces1[i].y, "width": faces1[i].width, "height": faces1[i].height}
178
+ faces1_result.append(face)
179
+
180
  image_np2 = np.asarray(image2)
181
  faces2 = (Face * maxFaceCount1)()
182
  faceNum2 = processImage(image_np2, image_np2.shape[1], image_np2.shape[0], faces2, maxFaceCount1)
183
 
184
+ faces2_result = []
185
+ for i in range(faceNum2):
186
+ face = {"x": faces2[i].x, "y": faces2[i].y, "width": faces2[i].width, "height": faces2[i].height}
187
+ faces2_result.append(face)
188
+
189
+ if faceNum1 > 0 and faceNum2 > 0:
190
+ results = []
191
+ for i in range(faceNum1):
192
+ for j in range(faceNum2):
193
+ score = verifyFeat(faces1[i].featSize, faces1[i].featData, faces2[j].featSize, faces2[j].featData)
194
+ match_result = {"face1": i, "face2": j, "score": score}
195
+ results.append(match_result)
196
+
197
+ response = jsonify({"resultCode": "Ok", "faces1": faces1_result, "faces2": faces2_result, "results": results})
198
 
199
  response.status_code = 200
200
  response.headers["Content-Type"] = "application/json; charset=utf-8"
201
  return response
202
  elif faceNum1 == 0:
203
+ response = jsonify({"resultCode": "No face1", "faces1": faces1, "faces2": faces2})
204
 
205
  response.status_code = 200
206
  response.headers["Content-Type"] = "application/json; charset=utf-8"
207
  return response
208
  elif faceNum2 == 0:
209
+ response = jsonify({"resultCode": "No face2", "faces1": faces1, "faces2": faces2})
210
 
211
  response.status_code = 200
212
  response.headers["Content-Type"] = "application/json; charset=utf-8"