GitHub Address: https://github.com/ageitgey/face_recognition
This project is the world's most compact face recognition database, you can use the command-line tool and Python extraction, recognition, operation faces.
Recognition of this project is the industry's leading open source C ++ library based dlib depth learning model, using Labeled Faces in the Wild tested facial data sets, there are up to 99.38% accuracy. However, recognition accuracy for Asian children and have yet to face lift.
Labeled Faces in the Wild is Amn University of Massachusetts Amherst (University of Massachusetts Amherst) made face data set, the data set contains more than 13,000 sheets of facial images collected from the network.
This project provides a simple face_recognition
command-line tool, you can use it to process the entire folder of images.
characteristic
Find the face from the picture
Everyone locate the picture face:
image
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_locations = face_recognition.face_locations(image)
The key point to recognize faces
The key point to recognize faces, including the eyes, nose, mouth and chin.
image
import face_recognition
image = face_recognition.load_image_file("your_file.jpg")
face_landmarks_list = face_recognition.face_landmarks(image)
The key point to recognize faces in many fields use, but you can also put this same function to play bad, such as the project's digital make-up automatic makeup case (like the Mito Xiu Xiu the same).
image
Identify who the picture
image
import face_recognition
known_image = face_recognition.load_image_file("biden.jpg")
unknown_image = face_recognition.load_image_file("unknown.jpg")
biden_encoding = face_recognition.face_encodings(known_image)[0]
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
You can also with other Python libraries (such as opencv) real-time face detection:
image
Look at this case real-time face detection .
installation
Environment Configuration
- Python 3.3+ or Python 2.7
- macOS or Linux
- Windows is not our official support, but may also use
Operating system installation methods
The project installed on a Mac or Linux
The first step, and the associated Python installation dlib dependence:
Then, with the pip
command to download the project pyhon module from the pypi community:
pip3 command to download the corresponding version is python3, pip command to download the corresponding version is python2
pip3 install face_recognition
If you encounter a unitary moths, you can install Ubuntu virtual machine with this project, see the following tutorial.
How to use the great God provided Adam Geitgey Ubuntu virtual machine image file to install the virtual machine configuration, this project has been included in the mirror .
Installation come in raspberry
Installing on Windows
Although the project does not officially support Windows, but some of the great God who worked out a way to run this project on Windows:
Use Ubuntu virtual machine image file to install the virtual machine configuration, this project has been included in this mirror
- How to use the great God provided Adam Geitgey Ubuntu virtual machine image file to install the virtual machine configuration, this project has been included in the mirror (need a computer to install VMWare Player or VirtualBox)
Instructions
Command Line Interface
When you have installed this item, you can use two command-line tool:
face_recognition
- in a single picture or picture folder recognize who face.face_detection
- folder locate the face position in a single picture or a picture file.
face_recognition
Command-line tool
face_recognition
Command-line tool in a single image or picture folder recognize who face.
First of all, you have to have a name you already know the face picture folder, a person a picture, the picture corresponding to the file name is the name of the person:
known
Then, you need a second picture folder, the folder which you wish to identify the picture:
unknown
Then, you switch on the command line the path to the folder where these two, and then use the face_recognition
command line, passing in these two pictures folder, then it will output the picture of unknown human name:
$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/
/unknown_pictures/unknown.jpg,Barack Obama
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
Each line of output corresponds to the picture of a face, picture names and the corresponding recognition results separated by commas.
If the result is output unknown_person
, then this face on behalf of no one in the known human face on the corresponding picture folder.
face_detection
Command-line tool
face_detection
Command-line tool can locate the position of the face (output pixel coordinates) in a single picture or picture folder.
Use the command line face_detection
, passing in a single picture folder or image file to the face position detection:
$ face_detection ./folder_with_pictures/
examples/image1.jpg,65,215,169,112
examples/image2.jpg,62,394,211,244
examples/image2.jpg,95,941,244,792
On a face, each row corresponding to the coordinates of the output picture output in the face of this represents, right, down, left pixel coordinates.
Fault tolerance and sensitivity adjustment face recognition
If a face to identify more than one result, then this means that he and others had long too much like (this project for face recognition accuracy and Asian children should be improved). You can reduce the number of fault tolerance, the recognition result of more stringent.
By passing parameters --tolerance
to achieve this function, the default rate is 0.6 fault tolerance, fault tolerance lower the rate, the more stringent recognition accuracy.
$ face_recognition --tolerance 0.54 ./pictures_of_people_i_know/ ./unknown_pictures/
/unknown_pictures/unknown.jpg,Barack Obama
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person
If you want to see the specific value of face matching, you can pass parameters --show-distance true
:
$ face_recognition --show-distance true ./pictures_of_people_i_know/ ./unknown_pictures/
/unknown_pictures/unknown.jpg,Barack Obama,0.378542298956785
/face_recognition_test/unknown_pictures/unknown.jpg,unknown_person,None
More examples
If you do not care about the image file name, folder just want to know who the picture, you can use this command pipeline:
$ face_recognition ./pictures_of_people_i_know/ ./unknown_pictures/ | cut -d ',' -f2
Barack Obama
unknown_person
Accelerated recognition operation
If your CPU polynuclear, you can speed up recognition by parallel operation. For example, if your CPU has four cores, you can enhance the computing speed is probably four times by parallel computing.
If you use Python3.4 or later, you can pass --cpus <number_of_cpu_cores_to_use>
parameters:
$ face_recognition --cpus 4 ./pictures_of_people_i_know/ ./unknown_pictures/
You can pass --cpus -1
parameters to call all core cpu's.
Zihao brother annotation: Raspberry Pi 3B has four CPU core, multicore incoming parameters may significantly improve the speed of image recognition (pro-test).
Python modules:face_recognition
In Python, you can import the face_recognition
module, call the rich API interface we provide, with a few lines of code can easily play a variety of face recognition!
API interface documentation: https://face-recognition.readthedocs.io
Locate the face in the picture position
import face_recognition
image = face_recognition.load_image_file("my_picture.jpg")
face_locations = face_recognition.face_locations(image)
# face_locations is now an array listing the co-ordinates of each face!
Look case: Target Biden's face
Case: Positioning Biden's face
You can also use deep learning model to achieve a more accurate face location.
Note: This method requires GPU-accelerated (driven by NVIDIA CUDA graphics library), you compile and install dlib
also need to open CUDA support time.
import face_recognition
image = face_recognition.load_image_file("my_picture.jpg")
face_locations = face_recognition.face_locations(image, model="cnn")
# face_locations is now an array listing the co-ordinates of each face!
Look Case: convolution depth learning neural network model positioning Biden's face
If you have lots of pictures need to be identified, while another GPU, then you can refer to this example: Case: using human neural network convolution depth study to identify the picture of the model batch face .
Identifying faces in a single image key points
import face_recognition
image = face_recognition.load_image_file("my_picture.jpg")
face_landmarks_list = face_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.
Look at this case case: key points extracted face Obama and Biden
Case: extracting facial key points Obama and Biden
Identify who the picture
import face_recognition
picture_of_me = face_recognition.load_image_file("me.jpg")
my_face_encoding = face_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_recognition.load_image_file("unknown.jpg")
unknown_face_encoding = face_recognition.face_encodings(unknown_picture)[0]
# Now we can see the two face encodings are of the same person with `compare_faces`!
results = face_recognition.compare_faces([my_face_encoding], unknown_face_encoding)
if results[0] == True:
print("It's a picture of me!")
else:
print("It's not a picture of me!")
Look at this case Case: Obama or Biden?
Python Case
All cases are in this link is the examples folder .
Face Location
- Case: Positioning Biden's face
- Case: convolution depth learning neural network model positioning Biden's face
- Case: convolution depth learning neural network model to identify batches of human faces in pictures
- Case: The people from the webcam video in the face of a Gaussian blur (need to install OpenCV)
Face recognition key points
Face Recognition
- Case: Obama or Biden?
- Case: Face painting after the original box and label name
- Case: compare two different people on the face accuracy whether a person
- Case: Get video from a camera for face recognition - slower version (need to install OpenCV)
- Case: Get video from a camera for face recognition - a faster version (need to install OpenCV)
- Case: to recognize faces and to the recognition result output from video files for the new video file (you need to install OpenCV)
- Case: the number of people carried out statistical face and facial identification by Raspberry Pi camera
- Case: face recognition access the network through the browser HTTP server (Flask need to install the back-end development framework))
- Case: face recognition based on K-nearest neighbor KNN classification algorithm
About face_recognition
articles and tutorials
- The project authors to write an article Modern Face Recognition with Deep Learning
- Content: basic principles and algorithms
- Face recognition with OpenCV, Python, and deep learning by Adrian Rosebrock
- Content: how to actually use this project
- Raspberry Pi Face Recognition by Adrian Rosebrock
- Content: How to use this project come in raspberry
- Face clustering with Python by Adrian Rosebrock
- Contents: use of non-supervised learning algorithm to face the Gaussian blur the picture
Principle of face recognition
If you want a deeper understanding of the principles of recognition of the black box to read this article .
Zihao brother annotation: have to look at this article, talking about both interesting material.
Warning Description
- Face recognition model of the project is based on adults, and in children who may be the general effect. If there are children in the picture, it is recommended to set the threshold at 0.6.
- Recognition of the results of different races may be different, see Wikipedia wiki page for more details.
The project deployed on the cloud server (Heroku, AWS, etc.)
The project is based on the C ++ library dlib
, so put this project deployed on Heroku or AWS cloud server is very wise.
To simplify this process, there is a Dockerfile case, teach you how to face_recognition
develop the app packaged as a Docker container file, you can deploy it on so Docker image file support cloud services.
Out of the unitary moths?
If there is a problem, please check before submitting Issue in Github common errors .
Link: https: //www.jianshu.com/p/0b37452be63e