Installing Face Recognition Library on Raspberry Pi 4

Ever wanted to use face recognition on your Raspberry Pi 4?

Well, look no further. We’re talking about using your Raspberry Pi to identify users’ profiles and many more. In our example, we have the face recognition library controlling our home appliances. By the end of this article, you would have installed Dlib and face_recognition libraries onto your Pi.

Want to skip all the steps? Download the face recognition Raspberry Pi image.

Note: Although this module may work on previous pi models, the Raspberry Pi 4 is recommended

Applications of Face Recognition

Smart Mirror Touchscreen - Face ID
Face Recognition Module

Smart Mirror Touchscreen - Face ID turning on IoT Home Appliances
Controlling Smart Plug Home Appliances

Follow the below terminal command to install the library dependencies for face recognition on Raspberry Pi.
Note: We recommend the Raspberry Pi 4 for the face recognition library. Older Pi Models may not be as responsive

1) Copy and Paste the following (Install one at a time):  

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
sudo apt-get install cmake
sudo apt-get install gfortran
sudo apt-get install git
sudo apt-get install wget
sudo apt-get install curl
sudo apt-get install graphicsmagick
sudo apt-get install libgraphicsmagick1-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libavcodec-dev
sudo apt-get install libavformat-dev
sudo apt-get install libboost-all-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libjpeg-dev
sudo apt-get install liblapack-dev
sudo apt-get install libswscale-dev
sudo apt-get install pkg-config
sudo apt-get install python3-dev
sudo apt-get install python3-numpy
sudo apt-get install python3-pip
sudo apt-get install zip
sudo apt-get clean

2) Install the following:

sudo apt-get install python3-picamera
sudo pip3 install --upgrade picamera[array]

3) Increase the SWAP FILE:

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024 and save / exit nano

If the below step produces an error, restart you Pi. (Same Equivalent)

sudo /etc/init.d/dphys-swapfile 

4) Git clone and Install dlib library

mkdir -p dlib
git clone -b 'v19.6' --single-branch https://github.com/davisking/dlib.git dlib/
cd ./dlib
sudo apt-get install cmake
mkdir build; cd build; cmake .. ; cmake --build 

Install dlib via pip3

pip3 install dlib

5) Decrease the SWAP Size:

sudo nano /etc/dphys-swapfile

Change CONF_SWAPSIZE=1024 to CONF_SWAPSIZE=100 and save / exit nano

If the step fails follow the same as Step 3

6) Install supporting dlib libraries:

pip3 install numpy
pip3 install scikit-image
sudo apt-get install python3-scipy
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install python3-pyqt5
sudo apt install libqt4-test
pip3 install opencv-python==3.4.6.27
pip3 install face_recognition 

7) Clone the Face recognition library

git clone --single-branch https://github.com/ageitgey/face_recognition.git
cd ./face_recognition/examples && python3 facerec_on_raspberry_pi.py
python3 facerec_on_raspberry_pi.py

2 thoughts on “Installing Face Recognition Library on Raspberry Pi 4”

Leave a comment