Real Time Face Detection on the RaspberryPi-4




Introduction: Real Time Face Detection on the RaspberryPi-4

In this Instructable we are going to perform real time face-detection on Raspberry Pi 4 with Shunya O/S using the Shunyaface Library. You can achieve a detection frame rate of 15-17 on the RaspberryPi-4 by following this tutorial.


1. Raspberry Pi 4B (any variant)

2. Raspberry Pi 4B compliant power supply

3. 8GB or bigger micro SD card

4. Monitor

5. micro-HDMI Cable

6. Mouse

7. Keyboard

8. laptop or another computer(Ubuntu-16.04 preferably) to program the memory card

9. USB Webcam

Step 1: Install Shunya OS on Raspberry Pi 4

You will need a laptop or computer(preferably with Ubuntu-16.04) and a micro SD card reader/adapter to load the micro SD card with Shunya OS.

1) Download Shunya OS from the official release site

2) Flash Shunya OS on the SD-card using the steps given below:

i) Right click on the zip file downloaded and select Extract here

ii) Once the image is unzipped double click on the unzipped image folder in which you will find the image and release info

iii) Right click on the image(.img file)

iv) Select Open with -> Disk image writer

v) Choose Destination as SD Card Reader

vi) Enter your password

This will start flashing the SD-card. Be patient and wait for the Sd-card to be flashed completely(100%)

Step 2: Setup and Connections

As shown in the picture above you need to do the following things:

1) Insert micro SD card into Raspberry Pi 4.

2) Connect mouse & keyboard to Raspberry Pi 4.

3) Connect Monitor to Raspberry Pi 4 via micro-HDMI

4) Connect the USB Webcam to the Raspberry Pi 4

5) Connect the power cable and Power ON the Raspberry Pi 4.

This will boot up Shunya OS on the RaspberryPi-4. The first boot might take time as the filesystem resizes so as to occupy the entire SD-card. After the OS boots up you should see a login screen. Here are the login details:

Username: shunya

Password: shunya

Step 3: Install Shunyaface(face Detection/recognition Library)

To install Shunyaface we need to connect the RaspberryPi-4 to the lan or wifi

1. To connect the RPI-4 to the wifi use the following command:

$ sudo nmtui

2. To install shunyaface and cmake (a dependency) for compilation of the codes and git(for downloading the actual code), enter the following command:

$ sudo opkg update && sudo opkg install shunyaface cmake git

Note: Installing might take about 5-6 mins depending on your internet speed.

Step 4: Download the Code

The code is available on github. You can download it using the following command:

$ git clone

Code explanation:

The given code captures frames continuously using Opencv's VideoCapture function. These frames are given to the detect function of Shunyaface which in turn returns the frames with bounding box plotted on the face and dots plotted on the eyes, nose and end points of the lips. To quit the code press the "q" button. After pressing "q" the Output FPS is displayed on the terminal.

Step 5: Compile the Code

To compile the code use the following command:

$ cd examples/example-facedetect

$ ./

Step 6: Run the Code

Once, you have compiled the code you can run it using the command.

$ ./build/facedetect

You should now see a window open. Whenever a face is in front of the camera, it will plot the bounding box and it will be visible to the user on the window that opened.

Congratulations. You have now successfully completed read-time face-detection on the RaspberryPi-4 using deep-learning. If you like this tutorial please like, share the tutorial and star our github repository given here.

Be the First to Share


    • Unusual Uses Contest

      Unusual Uses Contest
    • Halloween Contest

      Halloween Contest
    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge


    jvan dalen
    jvan dalen

    2 years ago

    Are you not just using opencv to detect faces? What is the difference with opencv?


    Reply 2 years ago

    ok I let the secret out . It uses MTCNN (modified version for speed)


    2 years ago

    Wonderful project! What’s the simplest way to add a mask over the face recognition? Can you give me some hints? Thanks in advance


    2 years ago

    Will it run well in Raspberry 3B+ ?


    Reply 2 years ago

    It will definitely. You can expected about 9-10 FPS.


    Question 2 years ago on Step 6

    What is Shunya OS? Wouldn't it just be a Raspbian image with your libraries installed?


    Answer 2 years ago

    Btw it supports Debian, Ubuntu commands out of the box so there is no learning curve to use Shunya if you are a debian or Ubuntu or Fedora user.


    Answer 2 years ago

    Shunya OS is a new lightweight IOT and AI O/S meant for arm based devices. It isn't a Debian, Fedora or Raspbian fork. It has some really cool features which will allow developers to create projects/products easily on embedded devices. Check us out at: