【人脸比对】几行代码实现离线人脸比对

import face_recognition
def detect_faces_in_image(file_stream1, file_stream2):
    code1 = face_recognition.face_encodings(face_recognition.load_image_file(file_stream1))[0]
    code2 = face_recognition.face_encodings(face_recognition.load_image_file(file_stream2))[0]
    if len(code1) > 0 and len(code2) > 0:
        match_results = face_recognition.face_distance([code1], code2)
    print(match_results[0])
    if match_results[0]>0.5:
        result = "不是同一个人"
    else:
        result = "同一个人"
    return result

file_stream1=r'##############'
file_stream2=r'##############'
detect_faces_in_image(file_stream1, file_stream2)
该函数传入两张图片,利用face_recognition进行人脸比对,返回一个match_result[0],为两图之间的欧式距离,如果大于0.5,则判断不是同一个人,否则判断同一个人

 

你可能感兴趣的:(人脸识别项目)