Raspberry Pi Zero processing images

Machine Learning Raspberry Pi

The Raspberry Pi Zero is great… you can run a GIS on it! I wrote about setting it up via usb on my laptop six months ago. You can revisit it if you like 🙂

QGIS and Raspberry Pi Zero

You can also run GDAL, OpenCV & scikit-learn. Let’s take a look at some examples. First off I ran these commands again once I reconnected my Pi; I had a few updates to install.

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo apt-get install gdal-bin qgis

python shell

Once you are up and running, importing GDAL, QGIS and Numpy all just work. I have spent hours installing GDAL in the past and this was the easiest by far. Installing OpenCV?

sudo apt-get install python-opencv

Trying demo3.py script from my interactive OpenCV tutorial works beautifully. This script will load an image and on left mouse click create a new window of that colour.

raspberry pi opencv imagery Earth observation

In terms of performance I couldn’t see much difference.

 

Raspberry pi opencv earth observation

Machine Learning using RaspberryPi

If OpenCV and GDAL were easy to install I wondered if the same was true with scikit-learn. It is built on Numpy, Scipy and Matplotlib. We need to make sure all these libraries are also installed (I already had Numpy installed).

sudo apt-get install python-scipy
sudo apt-get install python-matplotlib
sudo apt-get install python-sklearn

It does take a bit of time to install these python libraries but it is worth it. Open the python interpreter and import these libraries. No errors? Success!

Machine Learning using RaspberryPi

There is an excellent tutorial on using Support Vector Machines (SVM) with the digits data set.

 

I am copying the code in this video tutorial onto my pi zero, making slight changes such as adding a time call and looping through the images. If you’d like to see the code it’s available on my GitHub page.

And what happens when this is run?

Machine Learning Raspberry Pi

Brilliant! To put that result into context on my own computer (>7 years old now!) it was much faster and took only 1.98 seconds to import the libraries and 0.28 to train and predict. But then, the pi did only cost £4 brand new 😉

 

 

I have grouped all my previous blogs (technical stuff / tutorials / opinions / ideas) are here http://gis.acgeospatial.co.uk

I am @map_andrew on twitter