SaraKIT is an easy-to-use face analysis solution for Raspberry Pi 4 CM4, powered by state-of-the-art algorithms based on MediaPipe from Google. It provides robust functionality for face detection, face landmark detection, and face mesh processing, specifically optimized for the Raspberry Pi 64-bit platform.


MediaPipe Face Landmarker

The MediaPipe Face Landmarker task enables the detection of face landmarks and facial expressions in real-time images and videos. It empowers various applications such as facial expression analysis, facial filters and effects, and virtual avatar creation. This task outputs 3D face landmarks, blendshape scores (coefficients representing facial expressions), and transformation matrices for seamless real-time rendering of detailed facial surfaces.

To utilize SaraKIT for face analysis, follow these steps:

  1. Clone repository, compile the code by running the command 'make' and execute the program:
    git clone FaceDetection
    cd FaceDetection

  2. The program captures frames from the camera, processes them, and sends the output.
  3. Preview the operation in your web browser by accessing the Raspberry Pi's IP address followed by port 7777 (e.g., http://raspberrypi:7777/ or
    If you have the Linux Desktop version and want to display the image from the camera in a window, change this line:
    init_viewer(ViewMode::Camera0,ViewMode::Processed, 1, true, false);
  4. The browser preview displays one or two images side by side, where the content of each image can be customized. By default, the left image shows the camera preview, while the right image displays the detected face along with face landmarks. Refer to the video below for a similar visualization.

Both the standard Raspberry Pi MMAL functions and OpenCV (slightly slower) functions can be used to capture frames from the camera.

#include <iostream>
#include <signal.h>
#include <stdio.h>
#include <math.h>
#include <arm_neon.h>
#include "unistd.h"

#include "struct.hpp"
#include "lib/viewer/viewer.hpp"
#include "lib/mediapipe/Mediapipe.hpp"

using namespace std;
cv::Mat frame0, frame0Gray, frame0GrayHalf, frame0GrayHalfEdge; // cam0
cv::Mat frame1, frame1Gray, frame1GrayHalf, frame1GrayHalfEdge; // cam1
cv::Mat imgProcessed;

ViewerStatus viewStatus;

void ctrlc_handler(sig_atomic_t s){
    printf("\nCaught signal %d\n",s);

int main(int argc, char** argv){

    imgProcessed=cv::Mat(camheight, camwidth, CV_8UC3);

    init_camera(0, camwidth, camheight, false, false, true, true, true);
    //init_camera(1, camwidth, camheight, false, camOpenCV, true, true, true);

    //init_viewer(ViewMode::Camera0, ViewMode::Camera1, 1, false, true);

    std::vector<std::vector<cv::Point2f>> faceLandmarks;
    std::vector<mpface::Face> faces;

    //for Face Mesh
    MediapipeFaceMesh mfm;
    FrameResultSynchroniser meshSync(100);

    printf("Start Loop\n");
    do {
        // Get frame to frame,frameGray,frameGrayHalf
        if (GetFrame()==0) { //GetFrame()==1 (new frame from cam0 ==1, ==2 from cam1, ==3 from cam0 & cam 1)

            //here you have time to do anything


        std::vector<std::vector<cv::Point2f>> faceLandmarks;

        //face Mesh
        int resm=meshSync.getFrameFromId(mfm.getFaceMesh(faceLandmarks),imgProcessed);

        if (resm&&faceLandmarks.size()) {
            std::vector<cv::Rect> facesRects;

        viewStatus = viewer_refresh();
    } while (viewStatus != ViewerStatus::Exit && control_c != true);
    return 1;
You can find C++ and Python code for Raspberry Pi4 in the
SaraKIT Github repository: