I recently switched to Linux for my Machine Learning experiments, and I did a
post on How to install Keras and
Anaconda Python on
Ubuntu 16.10.
Now, I wanted to install OpenCV on Ubuntu also. Since OpenCV does not have a pre-built package for Linux, it meant I had to compile OpenCV from source.
 |
| OpenCV 3.1 running on Lubuntu 16.10 |
Adrian of
PyImageSearch has recently done a
post about how to compile OpenCV on Ubuntu 16.04 using virtualenv. I followed his steps as a base, but had to make numerous adjustments to some of the packages which gets installed (e.g. libpng-dev, libhdf5-serial-dev) and the build commands due to the changes from Ubuntu 16.04 to 16.10, and because I'm using Anaconda environments rather than virtualenv.
I'll be installing
OpenCV 3.1, and will be using the
Lubuntu 16.10 virtual machine which I used in my earlier post. But the steps and commands will be exactly the same for any flavor of
Ubuntu 16.10.
First, as a habit, get and install the latest updates for Ubuntu,
sudo apt-get update
sudo apt-get upgrade
Then (if you have not done already) install the necessary build tools,
sudo apt-get install build-essential cmake git unzip pkg-config
Then, we install the following packages which allows OpenCV to interact with various image and video formats,
sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev
Note: on Ubuntu 16.04, the package name for libpng was libpng12-dev. But on 16.10, it should be
libpng-dev.