Saturday, December 30, 2017

Installing OpenCV 3.3.1 with Python 3.5 bindings on a Raspberry Pi Zero running Raspbian Stretch

I've been experimenting with some basic computer vision concepts on a Raspberry Pi as part of a small mobile robot project. Fundamental to this was getting OpenCV compiled and set up in Python, a process that took 5 or 6 tries over the majority of my Christmas/New Year break. Hopefully this guide will save you some proportion of that time when you have a go at it...

I'm working off the assumption that you are using Python 3.5 and are working within an activated virtual environment for your project. I am also going to use "~/myproject" as a stand in for your specific project path. This means you will have already done something like:

You need to stay in that activated virtual environment for the duration of this guide.
This install will be missing ffmpeg due to a bug in the current version.

Virtual memory
I needed to add more virtual memory to get this to work, using the following steps:

Now, the fun part. These are the steps you need to run, in order. The 'make' step will take 6-ish hours so is a good candidate for leaving overnight.

Virtual memory - again
It is important that you undo the virtual memory change above or you will risk corrupting you SD card. Just revert the value to 100 and start and stop the service.

From here you should be able to import 'cv2' from within the virtual environment's Python, and get on with actual development :)

This guide couldn't have been made without the efforts of:

No comments:

Post a Comment