简体   繁体   中英

How to get face matching percentage instead of boolean value in face_recognition python library

i am using face_recognition library for simple face recognition which is simple and easy for any developer [ like me without machine learning or deep learning knowledge ]

import face_recognition
known_image = face_recognition.load_image_file("knownimage.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")

known_image_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]

results = face_recognition.compare_faces([known_image_encoding], unknown_encoding)

here in

results = face_recognition.compare_faces([known_image_encoding], unknown_encoding)

i am getting True or False if face matched is there anyway i can get value in percentage matched

There's a good example here on the official github page that boils down to

face_distances = face_recognition.face_distance(known_encodings, image_to_test_encoding)
face_distances = face_recognition.face_distance(known_encodings, image_to_test_encoding) face_match_percentage = (1-face_distances)*100 for i, face_distance in enumerate(face_distances): print("The test image has a distance of {:.2} from known image #{}".format(face_distance, i)) print("- comparing with a tolerance of 0.6? {}".format(face_distance < 0.6)) print (numpy.round(face_match_percentage,4)) #upto 4 decimal places

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM