Face key points recognition based on Python DLib Library of face recognition
Https://www.toutiao.com/a6702287840765542920/
First, install the DLib module
Here only describes the linux installation process, windows installation process, please own Baidu
1. First, install libboost before installing dlib and skimage
Sudo apt-get install libboost-python-dev cmake
Next, go to dlib's official website dlib.net to download the latest dlib version (I downloaded dlib-19.7), and go to the directory where the file is located to extract it.
Bzip2-d dlib-19.7.tar.bz2
Tar xvf dlib-19.7.tar
This is a two-level decompression process. Extract the file dlib-19.7, enter the directory, and execute the following command to install dlib.
Python setup.py install
After the installation is complete, switch to python and type import dlib. No exception indicates that the installation is successful!
Then install skimage
Sudo apt-get install python-skimage
Second, face detection
First call dlib.get_frontal_face_detector () to load the face detector that comes with dlib.
Dets = detector (img, 1) applies the detector to the input image, and the result is returned to dets (parameter 1 indicates that the image is upsampled once to help detect more human faces)
The number of dets is the number of faces detected.
Four coordinate extremes of each human face detected can be obtained by traversing the dets.
In order to frame the detected face, use dlib.image_window () to load the display window. Window.set_image (img) first displays the picture on the window, and then uses window.add_overlay (dets) to draw the detected face frame.
Dlib.hit_enter_to_continue () is used to wait for clicks (similar to opencv's cv2.waitKey (0), without which a flicker occurs).
The test results are as follows:
Third, the extraction of key points
To implement the key point description, you need to use the official model for feature extraction, which can be downloaded at:
Http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2
First load the model from the path through dlib.shape_predictor (predictor_path), and the returned predictor is the feature extractor
Traversing the dets, using predictor (img, d) to calculate the key points of each face detected
The x, y values of each key point coordinate shape.parts () are obtained and stored in the landmark matrix (the model extracts 68 key points by default, so the landmark is 68 × 2 matrix).
The extraction results of key points are as follows: