树莓派上搭建python脸部识别环境

  1. 更新

    1
    2
    sudo apt update
    sudo apt upgrade
  2. 设置树莓派

    1
    sudo raspi-config
    • 开启摄像头
    • gpu memory 设置为16
  3. 安装依赖

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    sudo apt-get install build-essential \
    cmake \
    gfortran \
    git \
    wget \
    curl \
    graphicsmagick \
    libgraphicsmagick1-dev \
    libatlas-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
    sudo apt-get clean
  4. 安装python的摄像头操作模块

    1
    2
    sudo apt-get install python3-picamera
    sudo pip3 install --upgrade picamera[array]
  5. 暂时增大交换内存

    1
    2
    3
    4
    5
    sudo nano /etc/dphys-swapfile

    < change CONF_SWAPSIZE=100 to CONF_SWAPSIZE=1024 and save / exit nano >

    sudo /etc/init.d/dphys-swapfile restart
  6. 下载安装dlib

    1
    2
    3
    4
    mkdir -p dlib
    git clone -b 'v19.6' --single-branch https://github.com/davisking/dlib.git dlib/
    cd ./dlib
    sudo python3 setup.py install --compiler-flags "-mfpu=neon"
  7. 安装face_recognition

    1
    sudo pip3 install face_recognition
  8. 恢复交换内存

1
2
3
4
5
sudo nano /etc/dphys-swapfile

< change CONF_SWAPSIZE=1024 to CONF_SWAPSIZE=100 and save / exit nano >

sudo /etc/init.d/dphys-swapfile restart