# coding=utf-8
import os
import face_recognition
images = os.listdir('F:\one_face')#对比图片的图片库
#print(images)
image_to_be_matched = face_recognition.load_image_file('F:/two_face/29a.JPG')#加载需要识别的图片
# print(image_to_be_matched)
image_to_be_matched_encoded = face_recognition.face_encodings(image_to_be_matched)[0]#向量化图片
#print(image_to_be_matched_encoded)
for image in images:#遍历图片名字
# print(image)
current_image = face_recognition.load_image_file("F:/one_face/" + image)#在相应目录加载图片
# print(current_image)
try:#捕捉不可识别出脸部的图片,并规避
current_image_encoded = face_recognition.face_encodings(current_image)[0]#向量化图片
# print(current_image_encoded)
result = face_recognition.compare_faces([image_to_be_matched_encoded], current_image_encoded)#图片向量化比较
if result[0] == True:
print("Matched: " + image)
else:
print("Not matched: " + image)
except:#弹出未找到脸部的图片
print("Unidentified: " + image)