Skip to main content

Recognize faces from Python

Project description

Facial Recognition

Recognize and manipulate faces from Python. This is a fork from https://github.com/ageitgey/face_recognition.

Built using dlib's state-of-the-art face recognition built with deep learning. The model has an accuracy of 99.38% on the Labeled Faces in the Wild benchmark.

Features

Find faces in pictures

Find all the faces that appear in a picture:

import face_biometric_recognition
image = face_biometric_recognition.load_image_file("your_file.jpg")
face_locations = face_biometric_recognition.face_locations(image)

Find and manipulate facial features in pictures

Get the locations and outlines of each person's eyes, nose, mouth and chin.

import face_biometric_recognition
image = face_biometric_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_biometric_recognition.face_landmarks(image)

Identify faces in pictures

Recognize who appears in each photo.

import face_biometric_recognition
known_image = face_biometric_recognition.load_image_file("biden.jpg")
unknown_image = face_biometric_recognition.load_image_file("unknown.jpg")

biden_encoding = face_biometric_recognition.face_encodings(known_image)[0]
unknown_encoding = face_biometric_recognition.face_encodings(unknown_image)[0]

results = face_biometric_recognition.compare_faces([biden_encoding], unknown_encoding)

Installation

Requirements

  • Python 3.3+ or Python 2.7
  • macOS or Linux (Windows not officially supported, but might work)

Installation Options:

Installing on Mac or Linux

First, make sure you have dlib already installed with Python bindings:

Then, make sure you have cmake installed:

brew install cmake

Finally, install this module from pypi using pip3 (or pip2 for Python 2):

pip3 install face_biometric_recognition --no-index --find-links file:/path/to/face_biometric_recognition

Usage

Python Module

You can import the face_biometric_recognition module and then easily manipulate faces with just a couple of lines of code. It's super easy!

Automatically find all the faces in an image
import face_biometric_recognition

image = face_biometric_recognition.load_image_file("my_picture.jpg")
face_locations = face_biometric_recognition.face_locations(image)

# face_locations is now an array listing the co-ordinates of each face!

You can also opt-in to a somewhat more accurate deep-learning-based face detection model.

Note: GPU acceleration (via NVidia's CUDA library) is required for good performance with this model. You'll also want to enable CUDA support when compliling dlib.

import face_biometric_recognition

image = face_biometric_recognition.load_image_file("my_picture.jpg")
face_locations = face_biometric_recognition.face_locations(image, model="cnn")

# face_locations is now an array listing the co-ordinates of each face!
Automatically locate the facial features of a person in an image
import face_biometric_recognition

image = face_biometric_recognition.load_image_file("my_picture.jpg")
face_landmarks_list = face_biometric_recognition.face_landmarks(image)

# face_landmarks_list is now an array with the locations of each facial feature in each face.
# face_landmarks_list[0]['left_eye'] would be the location and outline of the first person's left eye.
Recognize faces in images and identify who they are
import face_biometric_recognition

picture_of_me = face_biometric_recognition.load_image_file("me.jpg")
my_face_encoding = face_biometric_recognition.face_encodings(picture_of_me)[0]

# my_face_encoding now contains a universal 'encoding' of my facial features
# that can be compared to any other picture of a face!

unknown_picture = face_biometric_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_biometric_recognition.face_encodings(unknown_picture)[0]

# Now we can see the two face encodings
# are of the same person with `compare_faces`!

results = face_biometric_recognition.compare_faces(
    [my_face_encoding], unknown_face_encoding
)

if results[0] is True:
    print("It's a picture of me!")
else:
    print("It's not a picture of me!")

Articles and Guides that cover face_biometric_recognition

How Face Recognition Works

If you want to learn how face location and recognition work instead of depending on a black box library, read Adam Geitgey's article.

Caveats

  • The facial recognition model is trained on adults and does not work very well on children. It tends to mix up children quite easy using the default comparison threshold of 0.6.
  • Accuracy may vary between ethnic groups. Please see this wiki page for more details.

Thanks

  • Many thanks to Adam Geitgey for putting together such an amazing project and allowing public access to it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

face_biometric_recognition-0.0.1.tar.gz (10.7 kB view hashes)

Uploaded Source

Built Distribution

face_biometric_recognition-0.0.1-py2.py3-none-any.whl (9.9 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page