Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic cutting function #1538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion face_recognition/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
__email__ = 'ageitgey@gmail.com'
__version__ = '1.4.0'

from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance, get_face_image
8 changes: 8 additions & 0 deletions face_recognition/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,11 @@ def compare_faces(known_face_encodings, face_encoding_to_check, tolerance=0.6):
:return: A list of True/False values indicating which known_face_encodings match the face encoding to check
"""
return list(face_distance(known_face_encodings, face_encoding_to_check) <= tolerance)


def get_face_image(face_image ,output_path="./face.jpg" ,known_face_locations=None):
if known_face_locations is None:
known_face_locations = face_locations(face_image)[0]
box = (known_face_locations[3],known_face_locations[0],known_face_locations[1],known_face_locations[2])
target_image = PIL.Image.fromarray(face_image).crop(box)
target_image.save(output_path)