赞
踩
在使用face_recognition的过程中发现 compare_faces 比较人脸的过程会将小于 tolerance 的人脸编码全部按照true返回,会丢失具体的欧氏距离的信息,源码如下:
- def compare_faces(known_face_encodings, face_encoding_to_check, tolerance=0.6):
- """
- Compare a list of face encodings against a candidate encoding to see if they match.
- :param known_face_encodings: A list of known face encodings
- :param face_encoding_to_check: A single face encoding to compare against the list
- :param tolerance: How much distance between faces to consider it a match. Lower is more strict. 0.6 is typical best performance.
- :return: A list of True/False values indicating which known_face_encodings match the face encoding to check
- """
- return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)
在这里返回的是一个list,长度和传入的known_face_encodings相等
对此进行调整,自己写了一个函数,如下:
- # 调整face_recognition的脸部编码比较函数,返回下标和距离最小值
- def my_compare_faces(known_face_encodings, face_encoding_to_check, tolerance):
- # 如果已知人脸列表为空或待比较人脸为空则直接返回
- if len(known_face_encodings) == 0 or len(face_encoding_to_check) == 0:
- return -1, 1
- distance = face_recognition.face_distance(known_face_encodings, face_encoding_to_check)
- if distance.min() < tolerance:
- return distance.argmin(), distance.min()
- else:
- return -1, distance.min()
在这里返回人脸距离的小于 tolerance 的最小值的下标,即返回最相似的人脸下标,如果不符合tolerance 就返回-1,对返回值做一个判定即可区分。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。