Real Time Face Detection on Raspberry Pi 4



Let's see 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.

using a Raspberry Pi 4, with Raspbian Buster as the operating system and a Pi camera.

  • Install tflite for Python 3.7
To install tflite for Python 3.7, enter following pip3 install command in your terminal.

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

  • Install OpenCV
Install OpenCV if it is not already installed. You can either use apt install or pip3 install OpenCV on your Raspberry Pi.

sudo apt install -y python3-opencv

or

pip3 install opencv-python

  • Download Xailient FaceSDK and Unzip
Go to Xailient SDK page and register as a new user and login.

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


For Raspberry Pi 4, 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.


  • Add Shared Library to Path
This is required as the library depends on some dynamically loaded shared Libraries.

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


  • Download config file


From the Xailient SDK page, download the config file by either opening the link from your Raspberry Pi’s browser to or using the following wget command:

wget -O config.json "Config Link"

Copy the config.json file into the FaceSDK folder.


  • Install Xailient FaceSDK
To install the Xailient FaceSDK, run the Install.sh file that is inside the SDK folder. Go to the FaceSDK folder from your terminal and run the following command:

./Install.sh

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


  • Run sample Face Detection code
The FaceSDK comes with sample code that demonstrates how to use and
interact with the Xailient Face Detector Python library.

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

You might get error regarding the file not found of libboost_python-py37.so.1.62.0

just simply run the sudo apt install libboost_python-py37.so.1.62.0

Now, re-runthe demo file.



Post a Comment

0 Comments