Skip to content

Instantly share code, notes, and snippets.

@alonlavian
Last active April 28, 2019 19:25
Show Gist options
  • Save alonlavian/329eec63bdaca902bf2d64ff5ae4dff2 to your computer and use it in GitHub Desktop.
Save alonlavian/329eec63bdaca902bf2d64ff5ae4dff2 to your computer and use it in GitHub Desktop.
Only the crop part
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