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

blur_faces_on_webcam.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
47
48
49
50
51
52
  1. import face_recognition
  2. import cv2
  3. # This is a demo of blurring faces in video.
  4. # PLEASE NOTE: This example requires OpenCV (the `cv2` library) to be installed only to read from your webcam.
  5. # OpenCV is *not* required to use the face_recognition library. It's only required if you want to run this
  6. # specific demo. If you have trouble installing it, try any of the other demos that don't require it instead.
  7. # Get a reference to webcam #0 (the default one)
  8. video_capture = cv2.VideoCapture(0)
  9. # Initialize some variables
  10. face_locations = []
  11. while True:
  12. # Grab a single frame of video
  13. ret, frame = video_capture.read()
  14. # Resize frame of video to 1/4 size for faster face detection processing
  15. small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
  16. # Find all the faces and face encodings in the current frame of video
  17. face_locations = face_recognition.face_locations(small_frame, model="cnn")
  18. # Display the results
  19. for top, right, bottom, left in face_locations:
  20. # Scale back up face locations since the frame we detected in was scaled to 1/4 size
  21. top *= 4
  22. right *= 4
  23. bottom *= 4
  24. left *= 4
  25. # Extract the region of the image that contains the face
  26. face_image = frame[top:bottom, left:right]
  27. # Blur the face image
  28. face_image = cv2.GaussianBlur(face_image, (99, 99), 30)
  29. # Put the blurred face region back into the frame image
  30. frame[top:bottom, left:right] = face_image
  31. # Display the resulting image
  32. cv2.imshow('Video', frame)
  33. # Hit 'q' on the keyboard to quit!
  34. if cv2.waitKey(1) & 0xFF == ord('q'):
  35. break
  36. # Release handle to the webcam
  37. video_capture.release()
  38. cv2.destroyAllWindows()
Tip!

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

Comments

Loading...