-
Notifications
You must be signed in to change notification settings - Fork 1
/
facehandler.py
31 lines (28 loc) · 909 Bytes
/
facehandler.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
# import face_recognition
from face_recognition import load_image_file, face_encodings, compare_faces, face_locations
import numpy as np
# should be image file blob
def makeBlob(imagefile):
image = load_image_file(imagefile)
encoding = face_encodings(image)
loc = face_locations(image)
if len(loc) > 0:
return np.array(encoding).tostring()
else:
return 'nah'
# def makeBlob(filename)
# returns feature vector
def fromBlob(blob):
return np.frombuffer(blob, dtype=np.float64)
def compare(imgfile, knownEncodings, knownNames):
try:
image = load_image_file(imgfile)
encoding = face_encodings(image)[0]
matches = compare_faces(knownEncodings, encoding)
print(matches)
for match, name in zip(matches,knownNames):
if match:
return name
return "unknown name"
except:
return "error"