Step 1: Install dependancies
sudo apt -y update && sudo apt -y full-upgrade
sudo apt install build-essential \
cmake \
gfortran \
git \
wget \
curl \
graphicsmagick \
libgraphicsmagick1-dev \
libatlas-base-dev \
libavcodec-dev \
libavformat-dev \
libboost-all-dev \
libgtk2.0-dev \
libjpeg-dev \
liblapack-dev \
libswscale-dev \
pkg-config \
python3-dev \
python3-numpy \
python3-pip \
zip \
python3-picamera
Step 2: Updates
sudo pip3 install --upgrade picamera[array]
Step 3: Increase the swap file size so we can build dlib
sudo nano /etc/dphys-swapfile
Find CONF_SWAPSIZE
and change its value from 100 to 1024. Save
and exit then run this command:
sudo /etc/init.d/dphys-swapfile restart
Step 4: Build and install dlib
cd
git clone -b 'v19.6' --single-branch https://github.com/davisking/dlib.git
cd ./dlib
sudo python3 setup.py install --compiler-flags "-mfpu=neon"
This may take a significant time to run (Raspberry Pi 4 took about 30 minutes)
Step 5: Revert the swap size
sudo nano /etc/dphys-swapfile
Find CONF_SWAPSIZE
and change its value from 1024 to 100. Save
and exit then run this command:
sudo /etc/init.d/dphys-swapfile restart
Step 6: Install face_recognition
and examples
sudo pip3 install face_recognition
You're done!
An important amendment to my comment above which I neglected to include: Be sure to create your virtual environment with the
--system-site-packages
flag or else you won't have access to e.g.libcamera
inside the venv.I just installed this on a Pi zero 2 W with a Lite install of Bookworm on it. Basically the same as my previous comment except:
I think that if you are using picamera2 you don't need to do step 2. There is not an extra feature in picamera2 called array so the install doesn't work if you try to do
pip3 install --upgrade picamera2[array]
anyway. I'm not sure here, but I had trouble with the install and just skipped this step and everything else worked.Step six,
sudo pip3 install face_recognition
appears to want more memory than the Pi zero has (it just comes with 0.5GB) so do step 5, reverting the swap size) after step six instead of before. It takes a while but eventually the installation goes all the way through.Impressively, the Pi zero 2 can do at least basic face detection. I got the examples from
git clone --single-branch https://github.com/ageitgey/face_recognition.git
and updatedface_recognition/examples python3 facerec_on_raspberry_pi.py
to use picamera2 and cut out the recognition part so it just looks for generic faces and it can do it! I had the image size set to 640 x 480 and it processes about one image every five seconds. When I dropped that down to 320 x 240 it peps up and can do about one image per second.Thanks again!