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_Simplified_Chinese.py 1.7 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
  1. # 这是一个在树莓派上运行人脸识别的案例
  2. # 本案例会在命令行控制面板上输出识别出的人脸数量和身份结果。
  3. # 你需要一个2代以上的树莓派,并在树莓派上安装face_recognition,并连接上picamera摄像头
  4. # 并确保picamera这个模块已经安装(树莓派一般会内置安装)
  5. # 你可以参考这个教程配制你的树莓派:
  6. # https://gist.github.com/ageitgey/1ac8dbe8572f3f533df6269dab35df65
  7. import face_recognition
  8. import picamera
  9. import numpy as np
  10. # 你需要在sudo raspi-config中把camera功能打开
  11. camera = picamera.PiCamera()
  12. camera.resolution = (320, 240)
  13. output = np.empty((240, 320, 3), dtype=np.uint8)
  14. # 载入样本图片(奥巴马和拜登)
  15. print("Loading known face image(s)")
  16. obama_image = face_recognition.load_image_file("obama_small.jpg")
  17. obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
  18. # 初始化变量
  19. face_locations = []
  20. face_encodings = []
  21. while True:
  22. print("Capturing image.")
  23. # 以numpy array的数据结构从picamera摄像头中获取一帧图片
  24. camera.capture(output, format="rgb")
  25. # 获得所有人脸的位置以及它们的编码
  26. face_locations = face_recognition.face_locations(output)
  27. print("Found {} faces in image.".format(len(face_locations)))
  28. face_encodings = face_recognition.face_encodings(output, face_locations)
  29. # 将每一个人脸与已知样本图片比对
  30. for face_encoding in face_encodings:
  31. # 看是否属于奥巴马或者拜登
  32. match = face_recognition.compare_faces([obama_face_encoding], face_encoding)
  33. name = "<Unknown Person>"
  34. if match[0]:
  35. name = "Barack Obama"
  36. 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...