Cat detector code updated for Raspian Buster. I used lite. A few things have changed since the last time. The code is here.
Download Raspian
I got Raspbian Buster Lite (from https://www.raspberrypi.org/downloads/raspbian/ )
Burn it onto a SD card.
touch /Volumes/boot/ssh
nano /Volumes/boot/wpa_supplicant.conf
The file should containing something like:
country=GB ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="foo" psk="bar" }
then eject the card and put it in the pi.
ssh into it from your laptop
pi@raspberrypi.local
password: raspberry
sudo nano /etc/hosts
sudo nano /etc/hostname
Reboot
sudo reboot
Set up a virtualenv for python
This is not strictly necessary but keeps things tidy. You can also just use the built in python, just make sure you are using python3 and pip3 if so.
ssh into the pi again, then:
sudo apt update sudo apt-get install python3-pip sudo pip3 install virtualenv virtualenv env source env/bin/activate
(env) pi@birdbot:~ $ python --version Python 3.7.3 # or similar
Enable the camera
sudo raspi-config # and enable camera under 'interfacing'; reboot
Install Tensorflow
Increase the swap size:
sudo nano /etc/dphys-swapfile
The default value in Raspbian is:
CONF_SWAPSIZE=100
We will need to change this to:
CONF_SWAPSIZE=1024
Restart the service that manages the swapfile own Raspbian:
sudo /etc/init.d/dphys-swapfile restart
Install tensorflow dependencies
sudo apt-get install libatlas-base-dev sudo apt-get install git pip install --upgrade tensorflow
(this takes a few minutes)
Test that tensorflow installed ok:
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
You may see an error about hadoop –
HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory.
See also tensorflow/tensorflow#36141 and tensorflow/tensorflow#36141. That doesn’t seem to matter.
You could try some user built tensorflow binaries – I tried this one, which seemed to corrupt my SD card, but not tried this one. Tensorflow 2 would be better to learn (the apis all changed between 1.4 and 2).
Install OpenCV
sudo apt-get install libjasper-dev libqtgui4 libqt4-test libhdf5-dev libharfbuzz0b libilmbase-dev libopenexr-dev libgstreamer1.0-dev libavcodec-dev libavformat-dev libswscale5 pip install opencv-contrib-python==3.4.3.18 #(see this)
test
python -c 'import cv2; print(cv2.__version__)'
Install camera dependencies
pip install imutils picamera
Install speaking dependencies
sudo apt-get install espeak-ng
Finally:
git clone https://github.com/libbymiller/cat_loving_robot cd cat_loving_robot python classify_image.py
If you want to add the servos and so on for cat detecting and running towards cats, or start it up automatically, there’s more info in github.
One thought on “Pi / openCV / Tensorflow again”
Comments are closed.