Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

facerec_on_raspberry_pi.py 1.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  1. # This is a demo of running face recognition on a Raspberry Pi.
  2. # This program will print out the names of anyone it recognizes to the console.
  3. # To run this, you need a Raspberry Pi 2 (or greater) with face_recognition and
  4. # the picamera[array] module installed.
  5. # You can follow this installation instructions to get your RPi set up:
  6. # https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65
  7. import face_recognition
  8. import picamera
  9. import numpy as np
  10. # Get a reference to the Raspberry Pi camera.
  11. # If this fails, make sure you have a camera connected to the RPi and that you
  12. # enabled your camera in raspi-config and rebooted first.
  13. camera = picamera.PiCamera()
  14. camera.resolution = (320, 240)
  15. output = np.empty((240, 320, 3), dtype=np.uint8)
  16. # Load a sample picture and learn how to recognize it.
  17. print("Loading known face image(s)")
  18. obama_image = face_recognition.load_image_file("obama_small.jpg")
  19. obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
  20. # Initialize some variables
  21. face_locations = []
  22. face_encodings = []
  23. while True:
  24. print("Capturing image.")
  25. # Grab a single frame of video from the RPi camera as a numpy array
  26. camera.capture(output, format="rgb")
  27. # Find all the faces and face encodings in the current frame of video
  28. face_locations = face_recognition.face_locations(output)
  29. print("Found {} faces in image.".format(len(face_locations)))
  30. face_encodings = face_recognition.face_encodings(output, face_locations)
  31. # Loop over each face found in the frame to see if it's someone we know.
  32. for face_encoding in face_encodings:
  33. # See if the face is a match for the known face(s)
  34. match = face_recognition.compare_faces([obama_face_encoding], face_encoding)
  35. name = "<Unknown Person>"
  36. if match[0]:
  37. name = "Barack Obama"
  38. print("I see someone named {}!".format(name))
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...