Dlib is a popular library. It can be used for face detection or face recognition. In this article I will use it for facial landmark detection. Facial landmarks are fecial features like nose, eyes, mouth or jaw.
Start with installing Dlib library. Dlib requires Lib Boost.
Now we can install Dlib.
Following example uses PIL and numpy packages. Instead of Pillow it is possible to use skimage package.
Note that in order to detect facial landmarks, a previously trained model file is needed. You can download one from Dlib site.
Download model file from this link : http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
After download is completed, extract the archive and make sure its location is correctly referenced in the source file.
The application first tries to detect faces in the given image. After that for each face it tries to detect landmarks. For each face an image file is created and landmarks are drawn to that file.
Landmarks are returned in a shape object. Shape object contains part objects which are two dimensional points each of which corresponds to a landmark point. To understand which point corresponds to which landmark point look at the following image. It is taken from dlib link https://sourceforge.net/p/dclib/discussion/442518/thread/c038d05f/
Given application also contains sample methods to add circles around eyes to simulate glasses.
Start with installing Dlib library. Dlib requires Lib Boost.
sudo apt-get install libboost-all-dev
Now we can install Dlib.
sudo pip install dlib
Following example uses PIL and numpy packages. Instead of Pillow it is possible to use skimage package.
pip install Pillow pip install numpy
Note that in order to detect facial landmarks, a previously trained model file is needed. You can download one from Dlib site.
Download model file from this link : http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
After download is completed, extract the archive and make sure its location is correctly referenced in the source file.
The application first tries to detect faces in the given image. After that for each face it tries to detect landmarks. For each face an image file is created and landmarks are drawn to that file.
Landmarks are returned in a shape object. Shape object contains part objects which are two dimensional points each of which corresponds to a landmark point. To understand which point corresponds to which landmark point look at the following image. It is taken from dlib link https://sourceforge.net/p/dclib/discussion/442518/thread/c038d05f/
Given application also contains sample methods to add circles around eyes to simulate glasses.
Comments
Post a Comment