Last active
April 28, 2019 19:25
Only the crop part
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
from PIL import Image | |
def crop_faces(image_path,image_name,cropped_images_lib): | |
with open(image_path, 'rb') as image: | |
faces = detect_face(image, 8) | |
im = Image.open(image_path) | |
for idx,face in enumerate(faces): | |
vects = face.fd_bounding_poly.vertices | |
im2 = im.crop([vects[0].x, vects[0].y, vects[2].x - 1, vects[2].y - 1]) | |
cropped_image_path = cropped_images_lib + 'face' + str(idx+1) + '_' + image_name | |
im2.save(cropped_image_path, 'JPEG') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment