-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfr.py
38 lines (29 loc) · 1.26 KB
/
fr.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
32
33
34
35
36
37
38
# import the libraries
import os
import face_recognition
def my_facial_recognition_matcher(my_image):
# make a list of all the available images
images = os.listdir('images')
# load your image
image_to_be_matched = face_recognition.load_image_file(my_image)
try:
# encoded the loaded image into a feature vector
image_to_be_matched_encoded = face_recognition.face_encodings(image_to_be_matched)[0]
# iterate over each image
for image in images:
# load the image
current_image = face_recognition.load_image_file("images/" + image)
# encode the loaded image into a feature vector
current_image_encoded = face_recognition.face_encodings(current_image)[0]
# match your image with the image and check if it matches
result = face_recognition.compare_faces(
[image_to_be_matched_encoded], current_image_encoded)
# check if it was a match
if result[0] == True:
print ("Matched: " + image)
else:
print ("Not matched: " + image)
except IndexError:
print('IndexError: No faces detected in image.')
if __name__ == "__main__":
my_facial_recognition_matcher('my_image.jpg')