对亚洲人识别准确度有点差,具体安装:https://www.cnblogs.com/ckAng/p/10981025.html
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import face_recognition # Load the jpg files into numpy arrays known1_image = face_recognition.load_image_file("img/test10.jpg") known2_image= face_recognition.load_image_file("img/test11.jpg") unknown_image = face_recognition.load_image_file("img/test12.jpg") # Get the face encodings for each face in each image file # Since there could be more than one face in each image, it returns a list of encodings. # But since I know each image only has one face, I only care about the first encoding in each image, so I grab index 0. try: known1_face_encoding = face_recognition.face_encodings(known1_image)[0] known2_face_encoding = face_recognition.face_encodings(known2_image)[0] unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0] except IndexError: print( "I wasn‘t able to locate any faces in at least one of the images. Check the image files. Aborting..." ) quit() known_faces = [known1_face_encoding, known2_face_encoding] # results is an array of True/False telling if the unknown face matched anyone in the known_faces array results = face_recognition.compare_faces(known_faces, unknown_face_encoding) print("Is the unknown face a picture of known1_image? {}".format(results[0])) print("Is the unknown face a picture of known2_image? {}".format(results[1])) print( "Is the unknown face a new person that we‘ve never seen before? {}".format( not True in results ) )
原文:https://www.cnblogs.com/ckAng/p/10983901.html