-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect.py
31 lines (25 loc) · 912 Bytes
/
detect.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 io
import os
import pickle
import numpy as np
import face_recognition
from update_encodings import updateEncodings
def detectFaces(ref):
reference_data = ref.read()
reference_image = face_recognition.load_image_file(io.BytesIO(reference_data))
faces = face_recognition.face_locations(reference_image)
if len(faces) != 1:
return -1
reference_encoding = face_recognition.face_encodings(reference_image)[0]
updateEncodings()
output = []
for encoding_file in os.listdir("./static/encodings/"):
with open(f'./static/encodings/{encoding_file}', 'rb') as file:
target = pickle.load(file)
for encoding in target:
encoding = np.array(encoding)
result = face_recognition.compare_faces([reference_encoding], encoding)
if result[0]:
output.append(encoding_file[:-4])
break
return output