Try   HackMD

Object detection on Raspberry PI

  • Install TensorFlow, it also needs the LibAtlas package.
    • libatlas = Automatically Tuned Linear Algebra Software
mkdir tf
cd tf
wget https://www.piwheels.org/simple/tensorflow/tensorflow-1.14.0-cp37-none-linux_armv7l.whl
sudo init 3     # disable desktop environment
pip3 install ./tensorflow-1.14.0-cp37-none-linux_armv7l.whl
sudo init 5     # enable desktop environment
sudo apt-get install libatlas-base-dev

  • Install dependencies that will be used by the TensorFlow Object Detection API.
sudo apt-get install libxml2-dev libxslt1-dev
pip3 install lxml
pip3 install pillow matplotlib cython
sudo apt-get install python-tk

  • dependencies
sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev -y
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev -y
sudo apt-get install libxvidcore-dev libx264-dev -y
sudo apt-get install qt4-dev-tools -y
pip3 install opencv-python==3.4.6.27  # 最新版的opencv在RPI上執行會有問題, 安裝舊版會比較穩定

  • Install Protobuf by apt-get
sudo apt-get install protobuf-compiler

  • Set up TensorFlow Directory
mkdir tensorflow1
cd tensorflow1
git clone --recurse-submodules https://github.com/tensorflow/models.git
  • modify .bashrc
nano ~/.bashrc

# Put the following parameter to .bashrc
export PYTHONPATH=$PYTHONPATH:/home/pi/tensorflow1/models/research:/home/pi/tensorflow1/models/research/slim
# save and exit

source ~/.bashrc

  • Compile the Protocol Buffer
cd /home/pi/tensorflow1/models/research
protoc object_detection/protos/*.proto --python_out=.

  • Move into the object_detection directory
cd /home/pi/tensorflow1/models/research/object_detection
  • Download the SSD_Lite model from the TensorFlow detection model zoo.
wget http://download.tensorflow.org/models/object_detection/ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
tar xzvf ssdlite_mobilenet_v2_coco_2018_05_09.tar.gz
  • Download the Object_detection_picamera.py
# Path location: /home/pi/tensorflow1/models/research/object_detection

wget https://raw.githubusercontent.com/EdjeElectronics/TensorFlow-Object-Detection-on-the-Raspberry-Pi/master/Object_detection_picamera.py

python3 Object_detection_picamera.py 
  • You have to wait for a few minutes, then a new window will pop up
  • Press 'q' to quit