-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_face.py
More file actions
64 lines (50 loc) · 1.89 KB
/
Copy pathencode_face.py
File metadata and controls
64 lines (50 loc) · 1.89 KB
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
61
62
63
64
import sys
import dlib
import cv2
import face_recognition
import os
import psycopg2
import crud
import io,base64
import re
from datetime import date
crudOperation = crud.CRUD()
class encod:
def encoding(self,file_name,faceId,tenantid):
data = None
query=""
entry_encoding=""
try:
retorna="e1"
#face_detector = dlib.get_frontal_face_detector()
retorna="e2"
#image = cv2.imread(file_name)
retorna="e3"
#detected_faces = face_detector(image, 1)
retorna="e4"
image_entry = face_recognition.load_image_file(file_name)
retorna="e5"
entry_encoding = face_recognition.face_encodings(image_entry)[0]
retorna="e6"
if len(entry_encoding) > 0:
retorna="e7"
query = """insert into kycface."vectors"("faceId","tenantid","vec_low", "vec_high") VALUES('{}','{}', CUBE(array[{}]), CUBE(array[{}]))""".format(
faceId,tenantid,','.join(str(s) for s in entry_encoding[0:64]),
','.join(str(s) for s in entry_encoding[64:128]),)
retorna="e8"
data = crudOperation.insertData(query,None)
#cv2.imwrite("/var/www/flask/face/faces/aligned_face_{}_{}_crop.jpg".format(faceId, i), crop)
#for i, face_rect in enumerate(detected_faces):
# crop = image[face_rect.top():face_rect.bottom(), face_rect.left():face_rect.right()]
# encodings = face_recognition.face_encodings(crop)
# if len(encodings) > 0:
# query = """insert into kycface."vectors" ("faceId", "vec_low", "vec_high") VALUES ('{}', CUBE(array[{}]), CUBE(array[{}]))""".format(
# faceId,
# ','.join(str(s) for s in encodings[0][0:64]),
# ','.join(str(s) for s in encodings[0][64:128]),
# )
# data = crudOperation.insertData(query,None)
# cv2.imwrite("/var/www/flask/face/faces/aligned_face_{}_{}_crop.jpg".format(faceId, i), crop)
except Exception as e:
return str(retorna)
return data