Installing OpenCv on the Pi3 with python3 (and usb webcam)

opencv is one of the most difficult python package to install. it’s not a pip install easy package issue. in this post, we’ll see how to painlessly install it.

Target Os

we are using noobs see here

Target Pi

pi3

Existing Instructions

there are two posts which i found to be nice :

[pyimagesearch] and [manmade2.com]

this tutorial is an explanationless one, refer to these two for explanations

pyimagesearch notes

pyimagesearch is the reference post, however, here are some notes:

  1. you don’t need to expand the filesystem if you are using noobs (the beginner setup)
  2. misses qt packages
  3. misses python path in ~/.profile
  4. uses weird way to modify ~/.profile
  5. uses multi-core compiling
  6. no working script to test

manmade2.com notes

  1. included wrong make command and reinstall instructions (what if a confused user compiles open cv twice (brr))
  2. missed qt packages install
  3. misses python path in ~/.profile

Install instructions

the install process can be divided into these parts

  1. install raspbian packages including the qt one
  2. unzip cv sources
  3. setup pip and virtual env
  4. compile cv
  5. fix rename bug
  6. verify installation
  7. test snippet

install raspbian packages including the qt one

unzip cv sources

setup pip and virtual env

find python path with

open ~/.profile with

write at the end

then

compile cv

fix rename bug

verify installation

should be 3.3.0

test snippet

still inside the environment. create a new test file called cvtest.py

write in it :

run with

i tetsted it with a usb webcam

Further notes

if you are following pyimage search, changing swap size then /etc/dphysswapfile is a file without extentions, not  a directory

if you are getting function not implemented don’t forget sudo apt install qtbase5-dev

if you can’t open ~/.profile with nano, make sure you put sudo before i.e. sudo nano ~/.profile

if you are getting

virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

make sure you set the python path as above (the which python part)

 

 

 

Lives in Mauritius, cruising python waters for now.