Skip to main content

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.

Release files for face-biometric-recognition 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for face-biometric-recognition 0.0.1
File Size Uploaded
face_biometric_recognition-0.0.1.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for face-biometric-recognition 0.0.1
File Interpreter ABI Platform
face_biometric_recognition-0.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.6 kB

Release files / face_biometric_recognition-0.0.1.tar.gz

Download URL face_biometric_recognition-0.0.1.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
548e985c08fbc0e82358375e69c669a21cfbc9cde616bce9ce8e98e7aeecc4a7
BLAKE2b-256 checksum
How to use checksums
872d800bc67731c74474412bd01861cd4991edc32d3be298394d2dc22768ea36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

Release files / face_biometric_recognition-0.0.1-py2.py3-none-any.whl

Download URL face_biometric_recognition-0.0.1-py2.py3-none-any.whl
Size 9.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
c6d1dfa74705c6da9c685a70af725473eb35bf2ee5a1df1a0b2bd410ff99a208
BLAKE2b-256 checksum
How to use checksums
ccc4c814224dd4dc4f789ac5238676b08a89d916275b0a1e5dbfce204890cf4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.7

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page