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_cnn.py 1.1 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
  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 a pre-trained convolutional neural network.
  6. # This method is more accurate than the default HOG model, but it's slower
  7. # unless you have an nvidia GPU and dlib compiled with CUDA extensions. But if you do,
  8. # this will use GPU acceleration and perform well.
  9. # See also: find_faces_in_picture.py
  10. face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")
  11. print("I found {} face(s) in this photograph.".format(len(face_locations)))
  12. for face_location in face_locations:
  13. # Print the location of each face in this image
  14. top, right, bottom, left = face_location
  15. print("A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))
  16. # You can access the actual face itself like this:
  17. face_image = image[top:bottom, left:right]
  18. pil_image = Image.fromarray(face_image)
  19. pil_image.show()
Tip!

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

Comments

Loading...