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

find_faces_in_picture.py 907 B

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
  1. from PIL import Image
  2. import face_recognition
  3. # Load the jpg file into a numpy array
  4. image = face_recognition.load_image_file("biden.jpg")
  5. # Find all the faces in the image using the default HOG-based model.
  6. # This method is fairly accurate, but not as accurate as the CNN model and not GPU accelerated.
  7. # See also: find_faces_in_picture_cnn.py
  8. face_locations = face_recognition.face_locations(image)
  9. print("I found {} face(s) in this photograph.".format(len(face_locations)))
  10. for face_location in face_locations:
  11. # Print the location of each face in this image
  12. top, right, bottom, left = face_location
  13. print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
  14. # You can access the actual face itself like this:
  15. face_image = image[top:bottom, left:right]
  16. pil_image = Image.fromarray(face_image)
  17. pil_image.show()
Tip!

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

Comments

Loading...