Install Precompiled Dlib on Raspberry Pi

Install Precompiled Dlib on Raspberry Pi

Dlib is an open-source library that provides machine learning algorithms and tools for solving classification, regression, and clustering problems. This tutorial demonstrates how to install precompiled Dlib on Raspberry Pi.

    Install Dlib

    Connect to Raspberry Pi via SSH. Download the .deb package from releases page of the repository using the following command:

    curl -sSLo dlib.deb https://github.com/prepkg/dlib-raspberrypi/releases/latest/download/dlib-aarch64-linux-gnu.deb

    Once the download is complete, run the command to install Dlib:

    sudo apt install -y ./dlib.deb

    The .deb package is no longer necessary, remove it:

    rm -rf dlib.deb

    Testing Dlib

    To test program compilation, install GNU C++ compiler:

    sudo apt install -y g++

    Download a test image from the Internet:

    curl -sSLo test.jpg https://raw.githubusercontent.com/ageitgey/face_recognition/master/examples/two_people.jpg

    Create a main.cpp file:

    nano main.cpp

    Add the following code:

    #include <dlib/image_processing/frontal_face_detector.h>
    #include <dlib/image_io.h>
    
    using namespace dlib;
    
    int main() {
        array2d<rgb_pixel> img;
        load_image(img, "test.jpg");
    
        frontal_face_detector detector = get_frontal_face_detector();
        std::vector<rectangle> bboxes = detector(img);
    
        for (unsigned int i = 0; i < bboxes.size(); i++) {
            draw_rectangle(img, bboxes[i], rgb_pixel(0, 255, 0), 3);
        }
    
        save_jpeg(img, "result.jpg");
    
        return 0;
    }

    The code is used to detect faces in an image and draw a bounding box around the detected faces. The final image is saved to a file.

    Execute the following command to compile a code:

    g++ main.cpp -o test -O3 -Wno-psabi -ldlib

    Run a program:

    ./test

    Here is result:

    Detected faces in image using Dlib on Raspberry Pi

    Uninstall Dlib

    If decided to completely remove Dlib and related dependencies, run the following command:

    sudo apt purge --autoremove -y dlib

    Leave a Comment

    Cancel reply

    Your email address will not be published.