Search code examples
computer-visionface-detectiondlib

Dlib frontal face detection for small faces


I am using Dlib's frontal face detector to detect faces in an images; however, it cannot detect faces smaller than 80 by 80 pixels.

Dlib's example in face_detection_ex.cpp upsamples the input image using pyramid_up() to increase the face sizes. However, it makes the algorithm much slower because it will have to search in a larger image.

I wonder if anyone knows a solution for this problem.


Solution

  • Dlib's face detector is trained to process 80x80 faces. If you want to detect smaller faces, you have two ways:

    1. increase resolution to make faces bigger. you can use pyramid_up or any other way lice cv::resize. And you can increase resultion not 2x, but may be 1.5x will be enough - it's on you
    2. train new face detector that will work on small faces - dlib has samples for training process

    And the next your question is performance of face detector. Yes, it depends on resolution and if you want to detect 20x20 faces on 13 MP image - it will be slow. To make it work fast you have this options:

    1. reduce amount of pixels that should be processed by detector - use the right scale and region of interest
    2. use greyscale images
    3. reduce the amount of scale changes at scanning process
    4. use the recommendations from FAQ . I can only add that MinGW/GCC code works about 20% faster than MSVC and Android/ARM code is not using SIMD instructions
    5. for videos: apply motion detection and detect only changed areas (crop them manually and detect in cropped area) and also run frames in separate threads to consume all CPU cores