Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Installing OpenCV

Brian Amin edited this page Oct 28, 2017 · 1 revision

OpenCV

So we use OpenCV 3 here for RMC. Note that some of the tutorials might be for OpenCV2, if so let me (Brian) know and I'll come back through to help.

You wanted tutorials?

PyImageSearch is a goto here:

  1. Distance to a beacon
  2. Identify Shapes
  3. Identify Cats with some machine learning
  4. Detect People
  5. Calibrate a Camera

Linux Installation

For Ubuntu 16.04

Update Packages
sudo apt-get update
sudo apt-get upgrade

Install Dependencies

sudo apt-get install build-essential checkinstall cmake pkg-config yasm gfortran git
sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev

sudo apt-get install libtiff5-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get install libxine2-dev libv4l-dev
sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get install libqt4-dev libgtk2.0-dev libtbb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev
sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get install x264 v4l-utils

sudo apt-get install libprotobuf-dev protobuf-compiler
sudo apt-get install libgoogle-glog-dev libgflags-dev
sudo apt-get install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen

Installing Python Dependencies

sudo apt-get install python-dev python-pip

Download opencv from Git

git clone https://github.com/opencv/opencv.git
cd opencv 
git checkout 3.3.1
cd ..

git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.0
cd ..

Compile and Build

cd opencv
mkdir build
cd build

Run Cmake

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..

Compile and Build

# find out number of CPU cores in your machine
nproc
# substitute 4 by output of nproc
make -j4
sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig