face_recognition package

Module contents

face_recognition.api.compare_faces(known_face_encodings, face_encoding_to_check, tolerance=0.6)[source]

Compare a list of face encodings against a candidate encoding to see if they match.

Parameters:
  • known_face_encodings – A list of known face encodings
  • face_encoding_to_check – A single face encoding to compare against the list
  • tolerance – How much distance between faces to consider it a match. Lower is more strict. 0.6 is typical best performance.
Returns:

A list of True/False values indicating which known_face_encodings match the face encoding to check

face_recognition.api.face_distance(face_encodings, face_to_compare)[source]

Given a list of face encodings, compare them to a known face encoding and get a euclidean distance for each comparison face. The distance tells you how similar the faces are.

Parameters:
  • faces – List of face encodings to compare
  • face_to_compare – A face encoding to compare against
Returns:

A numpy ndarray with the distance for each face in the same order as the ‘faces’ array

face_recognition.api.face_encodings(face_image, known_face_locations=None, num_jitters=1)[source]

Given an image, return the 128-dimension face encoding for each face in the image.

Parameters:
  • face_image – The image that contains one or more faces
  • known_face_locations – Optional - the bounding boxes of each face if you already know them.
  • num_jitters – How many times to re-sample the face when calculating encoding. Higher is more accurate, but slower (i.e. 100 is 100x slower)
Returns:

A list of 128-dimentional face encodings (one for each face in the image)

face_recognition.api.face_landmarks(face_image, face_locations=None)[source]

Given an image, returns a dict of face feature locations (eyes, nose, etc) for each face in the image

Parameters:
  • face_image – image to search
  • face_locations – Optionally provide a list of face locations to check.
Returns:

A list of dicts of face feature locations (eyes, nose, etc)

face_recognition.api.face_locations(img, number_of_times_to_upsample=1)[source]

Returns an array of bounding boxes of human faces in a image

Parameters:
  • img – An image (as a numpy array)
  • number_of_times_to_upsample – How many times to upsample the image looking for faces. Higher numbers find smaller faces.
Returns:

A list of tuples of found face locations in css (top, right, bottom, left) order

face_recognition.api.load_image_file(filename, mode='RGB')[source]

Loads an image file (.jpg, .png, etc) into a numpy array

Parameters:
  • filename – image file to load
  • mode – format to convert the image to. Only ‘RGB’ (8-bit RGB, 3 channels) and ‘L’ (black and white) are supported.
Returns:

image contents as numpy array