Search code examples
c++opencvimage-processingface-detectiondlib

How to manipulate dlib landmark points


I wonder how can I manipulate/access the dlib landmark points. I run the code on the camera preview with the intention of detecting some particular emotions. I would like to check how for example the distance between eyelids or how the position of the lips changes in time and so on.


Solution

  • For python api - try this link (https://matthewearl.github.io/2015/07/28/switching-eds-with-python/)

    For C++ - http://dlib.net/train_shape_predictor_ex.cpp.html sample has code for estimating interocular distance:

    double interocular_distance (
        const full_object_detection& det
    )
    {
        dlib::vector<double,2> l, r;
        double cnt = 0;
        // Find the center of the left eye by averaging the points around 
        // the eye.
        for (unsigned long i = 36; i <= 41; ++i) 
        {
            l += det.part(i);
            ++cnt;
        }
        l /= cnt;
    
        // Find the center of the right eye by averaging the points around 
        // the eye.
        cnt = 0;
        for (unsigned long i = 42; i <= 47; ++i) 
        {
            r += det.part(i);
            ++cnt;
        }
        r /= cnt;
    
        // Now return the distance between the centers of the eyes
        return length(l-r);
    }
    

    Same way you can access any facial features More info about the feature numbers can be found in dlib/image_processing/render_face_detections.h