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...

Assumptions
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.
 
Caveats
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:

Installation
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:

2 comments:

  1. thanks this post really helped. I was painfully trying out different options for a week or so.

    ReplyDelete
  2. I appreciate everything you have added to my knowledge base.Admiring the time and effort you put into your blog and detailed information you offer.Thanks. my website

    ReplyDelete