Install OpenCV

OpenCV is a program library containing over 2000 algorithms for image processing and machine vision. Open CV can be used in Python, for example.

Open CV contains modules for various applications. Here are some examples:

  • object recognition
  • face recognition
  • gesture recognition
  • motion detection and prediction
  • segmentation

There are several ways to install OpenCV on your RevPi Core. For us, the following path is the easiest one.

In this example we install Open CV 3.1.0 to use it with Python 2.7.

Prerequisites:

  • RevPi Core is ready for use and has internet connection
  • You use the image Jessi
  • 8 GB USB stick
  • You have a Github account

Let’s go

  • Plug the USB stick into a free slot of your RevPi Core.
  • Start your RevPi Core.
  • Log in with your login data.
  • Enter the following command:
fdisk -l

You will now see all available devices.

  • Format your USB stick:
sudo mkfs.ext4 /dev/sda
  • Confirm the entry with “Y”.

Your USB stick is now formatted in Linux format “Ext4”.

  • Mount your USB stick:
sudo maunt /dev/sda /mnt
  • Change the user rights so that you can write data to the USB stick:
sudo chmod 777/ mnt
  • Open your USB drive:
cd/mnt
  • Update the information about the available packages:
sudo apt-get update
  • Install the following packages. These packages contain basic image processing functions Enter each command individually:
sudo apt-get install build-essential git cmake pkg-config
sudo apt-get install libjpeg8-dev libtiff4-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev
NOTICE
The package versions change with new features in openCV.
If an error message appears, you have to adjust the package version according to the error message.

Download packages for the basic library

  • Select the location for the base library:
cd /mnt
  • Select the location for the base library:
git clone https://github.com/Itseez/opencv.git
  • Open the desired location.
cd opencv
  • Safe the package.
git checkout 3.1.0
  • Enter the path to the desired location:
cd /mnt

Install plugins for openCV

  • Download the plugins:
git clone https://github.com/Itseez/opencv_contrib.git
  • Select the desired location:
cd opencv_contrib
  • Install the plugins:
git checkout 3.1.0

Install PIP and NumPy

NumPy is a program library for Python. It allows the use of openCV in Python. PIP is a package management tool to manage Python modules (such as NumPy).

  • Download PIP :
wget https://bootstrap.pypa.io/get-pip.py
  • Install PIP:
sudo python get-pip.py
  • Install NumPy:
pip install numpy

Compile and install Open CV

  • Select the installation location for openCV and install it:
cd opencv
mkdir build
"cd build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \-D CMAKE_INSTALL_PREFIX=/usr/local \-D INSTALL_C_EXAMPLES=OFF \-D INSTALL_PYTHON_EXAMPLES=OFF \-D OPENCV_EXTRA_MODULES_PATH= ../../opencv_contrib/modules \-D BUILD_EXAMPLES=OFF ..
  • Check in the output message whether Python has been installed.
  • Compile open CV:
make -j4

 

NOTICE

A little patience!
This process takes quite a while.

  • Enter the following command:
sudo make install
  • Enter the following command:
sudo ldconfig

Integrate Open CV into Python

  • Open Python.
  • Import open CV.
import cv2
cv2.__version__

You can now use Open CV in Python.