How to set up a Raspberry Pi environment for image processing applications.

Leonardo Dalcin
Sep 6, 2018 · 4 min read

Raspberry Pi is being used in many computer vision applications, such as surveillance, object detecting, process improvement and industrial automation. In any software development having a robust environment is the key starting point for success, scalability, maintenability and fun.

In this tutorial, I will guide you through how I did to establish a Raspberry Pi environment for computer vision applications.

My setup example using two servo motors for camera pan/tilt and external signal for camera triggering.

Overview

First, I will give an overview of the environment and explain the choices I made.

Our OS will be Raspbian installed with NOOBS (yes, with NOOBS), some might affirm that NOOBS will only take extra space on the secondary memory, but many computer vision applications require 24/7 availability and if a power loss happens, a pure Raspbian install may corrupt our whole file system. (see https://www.raspberrypi.org/forums/viewtopic.php?t=190650).

Our programming language will be Python, because of its easy of use and high productivity. Also, Python has many libraries that could help to process images. We will also use Miniconda (https://conda.io/docs/index.html) for Python dependency management.

Our system will be remote accessible through VNC (see https://www.realvnc.com), real VNC comes with Raspbian and let us setup up to 5 devices to connect over the internet for free.

In the end our stack will look like this: Raspbian + Python + Conda + OpenCV + PiCamera.

Installing Raspbian with NOOBS and configuration.

Go to https://www.raspberrypi.org/downloads/noobs/ to download our OS and put all the files in an SD card.

Boot your Raspberry Pi with a display, keyboard, mouse and ethernet cable (if you do not have Wi-Fi available) and select Raspbian as the operating system you want to install.

NOOBS will install Raspbian and boot into it, it will display a message to update the system, follow the instructions and update it.


In the main Raspbian menu, go to system preferences and enable the Camera, VNC and SSH interfaces.

After you reboot the system, you will be able to log to your Real VNC account by clicking the VNC icon on the Raspbian top bar.

There are many extensive tutorials that will cover Raspbian installation and interface enabling, but with this you should be good to go.

Creating a Conda Environment

Python has two main package managers: PIP and Conda. We will be using Conda, because it builds non python packages and it is easy to setup and manage a programming environment with it.

To install Miniconda run the following commands. It should download and install Miniconda.

wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
bash Miniconda3-latest-Linux-armv7l.sh

Now, lets create our Python environment, we will be using Python 2.7 which comes with Raspberry Pi.

conda create -n myenv python=2.7.1

Now, lets activate our environment with:

source activate myenv

We will be installing some Python packages:

conda install -c gaiar picamera
conda install -c poppy-project opencv3

Picamera is a Python camera wrapper for the Raspberry Pi camera module, it will allow us to control our camera throught Python scripts and OpenCV is the most known computer vision package. You can learn more about OpenCV at https://www.learnopencv.com/.

Coding your own solutions

Now we have a simple and controlled environment and we can start coding our own solutions.

Anatomy of an Image Classifier (https://www.learnopencv.com/image-recognition-and-object-detection-part1)

I made an open source project that has classes which will wrap OpenCV and PiCamera functionalities, it will also provide us an interface to RPi GPIO to control servos and receive external signals to trigger functions internal functions.

This will give you a quick start in the input image pipeline stage, so you can focus on what matters.

Check it out at https://github.com/leonardodalcin/cvbootstrap.

Thanks for reading!

That’s it! If you reached this point, you have a stable working environment for your own CV application.

If you liked this article, please share it and follow me on Twitter, Github and LinkedIn! Feel free to reach me out if you have any doubts and to show what you did with this environment.

Leonardo Dalcin

Written by

CS student @ UFRGS | Software/Vision Engineer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade