load the jpg files into numpy arrays 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 results is an array of truefalse telling if the unknown face matched anyone in the knownfaces array load the jpg files into numpy arrays 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 results is an array of true false telling if the unknown face matched anyone in the known_faces array
import face_recognition


biden_image = face_recognition.load_image_file("biden.jpg")
obama_image = face_recognition.load_image_file("obama.jpg")
unknown_image = face_recognition.load_image_file("obama2.jpg")




try:
    biden_face_encoding = face_recognition.face_encodings(biden_image)[0]
    obama_face_encoding = face_recognition.face_encodings(obama_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 = [
    biden_face_encoding,
    obama_face_encoding
]


results = face_recognition.compare_faces(known_faces, unknown_face_encoding)

print("Is the unknown face a picture of Biden? {}".format(results[0]))
print("Is the unknown face a picture of Obama? {}".format(results[1]))
print("Is the unknown face a new person that we've never seen before? {}".format(not True in results))