diff --git a/face_recognition/__init__.py b/face_recognition/__init__.py index 6e91db046..29a742234 100644 --- a/face_recognition/__init__.py +++ b/face_recognition/__init__.py @@ -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 diff --git a/face_recognition/api.py b/face_recognition/api.py index 80a3f7fbe..ed112feda 100644 --- a/face_recognition/api.py +++ b/face_recognition/api.py @@ -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)