Created
June 22, 2018 10:22
-
-
Save moshfiqur/3f388d10b7aed3a3c810f8c8d2f4aa07 to your computer and use it in GitHub Desktop.
Cropped faces after detection in an image using face_detection module and save them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import face_recognition | |
from PIL import Image | |
np_image = face_recognition.load_image_file("avengers2.jpg") | |
# face_locations returns a list of locations for each face | |
# detected in the picture, each list item contains a tuple | |
# of 4 items in the format of (top, right, bottom, left) | |
face_locations = face_recognition.face_locations(np_image) | |
image_obj = Image.open("avengers2.jpg") | |
seq = 0 | |
for face_location in face_locations: | |
# Be careful in ordering top, right, bottom, left | |
top, right, bottom, left = face_location | |
cropped_image = image_obj.crop((left, top, right, bottom)) | |
cropped_image.save('avengers2_cropped_'+str(seq)+'.jpg') | |
cropped_image.show() | |
seq += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The face recognition module: https://github.com/ageitgey/face_recognition