this is a demo of running face recognition on a raspberry pi this program will print out the names of anyone it recognizes to the console to run this you need a raspberry pi 2 or greater with facerecognition and the picameraarray module installed you can follow this installation instructions to get your rpi set up https gist github comageitgey1ac8dbe8572f3f533df6269dab35df65 get a reference to the raspberry pi camera if this fails make sure you have a camera connected to the rpi and that you enabled your camera in raspiconfig and rebooted first load a sample picture and learn how to recognize it initialize some variables grab a single frame of video from the rpi camera as a numpy array find all the faces and face encodings in the current frame of video loop over each face found in the frame to see if it s someone we know see if the face is a match for the known faces this is a demo of running face recognition on a raspberry pi this program will print out the names of anyone it recognizes to the console to run this you need a raspberry pi 2 or greater with face_recognition and the picamera array module installed you can follow this installation instructions to get your rpi set up https gist github com ageitgey 1ac8dbe8572f3f533df6269dab35df65 get a reference to the raspberry pi camera if this fails make sure you have a camera connected to the rpi and that you enabled your camera in raspi config and rebooted first load a sample picture and learn how to recognize it initialize some variables grab a single frame of video from the rpi camera as a numpy array find all the faces and face encodings in the current frame of video loop over each face found in the frame to see if it s someone we know see if the face is a match for the known face s
import face_recognition
import picamera
import numpy as np




camera = picamera.PiCamera()
camera.resolution = (320, 240)
output = np.empty((240, 320, 3), dtype=np.uint8)


print("Loading known face image(s)")
obama_image = face_recognition.load_image_file("obama_small.jpg")
obama_face_encoding = face_recognition.face_encodings(obama_image)[0]


face_locations = []
face_encodings = []

while True:
    print("Capturing image.")
    
    camera.capture(output, format="rgb")

    
    face_locations = face_recognition.face_locations(output)
    print("Found {} faces in image.".format(len(face_locations)))
    face_encodings = face_recognition.face_encodings(output, face_locations)

    
    for face_encoding in face_encodings:
        
        match = face_recognition.compare_faces([obama_face_encoding], face_encoding)
        name = "<Unknown Person>"

        if match[0]:
            name = "Barack Obama"

        print("I see someone named {}!".format(name))