Real-time Face Detection on Raspberry Pi

A step-by-step guide to implement real-time face detection on a Raspberry Pi running 24 frames per second

Sabina Pokhrel
Dec 8, 2019 · 3 min read
Image showing detected faces

In this post, i will guide you through a step-by-step process of implementing a real-time face detection on a Raspberry Pi, running 24 frames per second on a single core.

I will use a Raspberry Pi 3B+, with Raspbian Buster as the operating system and a Pi camera.

For the face detection, I will use Xailient FaceSDK.

Step 1: Install Python 3.7.3

python --version

Step 2: Install tflite for Python 3.7

pip3 install https://dl.google.com/coral/python/tflite_runtime-1.14.0-cp37-cp37m-linux_armv7l.whl

Step 3: Install OpenCV

sudo apt install -y python3-opencv

or

pip3 install opencv-python

Step 4: Download Xailient FaceSDK and Unzip

Go to SDK tab, where you will find instructions for downloading and installing Face SDK.

Xailient SDK page to download Python Face SDK.
Xailient SDK page to download Python Face SDK.

For Raspberry Pi 3B+, download the ARM32 version of the SDK. You can either open the link from your Raspberry Pi’s browser to download it directly to it or you can use the following wget command:

wget -O sdk.tar.gz "SDK Link"

Unzip the downloaded FaceSDK.

Step 5: Add Shared Library to Path

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$<Python_SDK path/Shared_arm32>

You can add library path to bashrc script so that you dont need to export everytime you login.

echo “export LD_LIBRARY_PATH=$LD_LIBRABRY_PATH:$<pathofSDK>/Shared_arm32” >> .bashrc

Step 6: Download config file

wget -O config.json "Config Link"

Copy the config.json file into the FaceSDK folder.

Step 7: Install Xailient FaceSDK

./Install.sh

For more details on the installation process, you can refer to the Readme file that comes along with the FaceSDK.

Step 8: Run sample Face Detection code

Go to samples folder and run the picam_streaming_demo.py script to run real-time face detection.

Running Xailient FaceSDK on a Raspberry Pi 3B+

You now have a real-time face detection running on a Raspberry Pi.


Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Sabina Pokhrel

Written by

AI Specialist | Machine Learning Engineer | Writer and Editorial Associate at Towards Data Science

Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade