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
- Adam Geitgey's article on how Face Recognition works: Modern Face Recognition with Deep Learning
- Covers the algorithms and how they generally work
- Face recognition with OpenCV, Python, and deep learning by Adrian Rosebrock
- Covers how to use face recognition in practice
- Raspberry Pi Face Recognition by Adrian Rosebrock
- Covers how to use this on a Raspberry Pi
- Face clustering with Python by Adrian Rosebrock
- Covers how to automatically cluster photos based on who appears in each photo using unsupervised learning
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file face_biometric_recognition-0.0.1.tar.gz
.
File metadata
- Download URL: face_biometric_recognition-0.0.1.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 548e985c08fbc0e82358375e69c669a21cfbc9cde616bce9ce8e98e7aeecc4a7 |
|
MD5 | 1f7fd11307299e984a71435b8a036b1e |
|
BLAKE2b-256 | 872d800bc67731c74474412bd01861cd4991edc32d3be298394d2dc22768ea36 |
File details
Details for the file face_biometric_recognition-0.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: face_biometric_recognition-0.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 2, Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6d1dfa74705c6da9c685a70af725473eb35bf2ee5a1df1a0b2bd410ff99a208 |
|
MD5 | b5a5b5863379c709f80881cf1d38a69c |
|
BLAKE2b-256 | ccc4c814224dd4dc4f789ac5238676b08a89d916275b0a1e5dbfce204890cf4b |