Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
106 lines (106 sloc) 4.1 KB
# Update any available packages
$ sudo apt-get update
$ sudo apt-get upgrade
# Installer from earlier release
$ echo "deb http://us.archive.ubuntu.com/ubuntu/ yakkety universe" | sudo tee -a /etc/apt/sources.list
$ echo "deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/ xenial main" | sudo tee -a /etc/apt/sources.list
$ sudo apt-get update
# Install developer tools for compiling OpenCV 3.0
$ sudo apt-get install -y build-essential cmake git python3.5-dev libatlas-base-dev gfortran python3-pip libgtk2.0-dev pkg-config libjpeg8-dev libtiff5-dev libjasper-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libgphoto2-dev gstreamer1.0-dev libdc1394-22 ffmpeg libavresample-dev
# To fix videodev.h missing error
# Generate a symbolic link
$ sudo ln -s /usr/include/libv4l1-videodev.h /usr/include/linux/videodev.h
# Fix python.h missing error
# Copy headers from python3.5m to include folder
$ sudo cp /usr/include/python3.5m/* /usr/include/
# Install dependencies for setting up a virtual environment
# Install OpenCV 3.0 and Python 3.4+ on UbuntuShell
$ sudo pip3 install virtualenv virtualenvwrapper
# Update ~/.bashrc file
# virtualenv and virtualenvwrapper
$ sudo nano ~/.bashrc
# Paste the following
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Reload ~./bashrc file for enforcing the changes
$ source ~/.bashrc
# Create a virtual environment called OpenCV
$ mkvirtualenv OpenCV
# Install numpy for math calculations
$ sudo rm -rf ~/.cache/pip/
$ pip install numpy
---OR---
$ sudo pip3 install -U numpy
# Clone the github OpenCV repository
$ cd ~
$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ git checkout 3.1.0
---OR---
# For the latest version from GitHub
$ git checkout
# Clone the github OpenCV contribute repository for access to standard keypoint detectors and local invariant descriptors (such as SIFT, SURF, etc.) and newer OpenCV 3.0 features like text detection
$ cd ~
$ git clone https://github.com/opencv/opencv_contrib.git
$ cd opencv_contrib
$ git checkout 3.1.0
---OR---
# For the latest version from GitHub
$ git checkout
# Build the OpenCV installer using CMake
$ cd ~/opencv
$ mkdir build
$ cd build
$ sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
# For installation without GTK and explicit python location pointers
$ sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_GTK=OFF \
-D WITH_GTK3=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON_EXECUTABLE=/usr/bin/python3.5 \
-D PYTHON_PACKAGES=/usr/local/lib/python3.5/dist-packages/ \
-D PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1 \
-D PYTHON_INCLUDE_DIR=/usr/include/python3.5m/ \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_PROTOBUF=OFF \
-D UPDATE_PROTO_FILES=ON \
-D BUILD_EXAMPLES=ON ..
# Install OpenCV in /usr/local/lib/python3.5/dist-packages/ folder
$ sudo make -j $(nproc --all)
$ sudo make install
$ sudo ldconfig
# Rename the site package to cv2 for import into python as cv2
cd /usr/local/lib/python3.5/dist-packages
ls
# Get the file name for python binding file. It looks something like: cv2.cpython-35m-x86_64-linux-gnu.so
$ cd ~/.virtualenvs/OpenCV/lib/python3.5/site-packages/
$ ln -s /usr/local/lib/python3.5/dist-packages/cv2.cpython-35m-x86_64-linux-gnu.so cv2.so
$ deactivate
$ workon OpenCV
# Miscellaneous instructions
# Get linux version
lsb_release -a
# To generate a symbolic link
$ sudo ln -s [source_location] [target_location]
# Install gtk3 and all-dev packages
$ sudo apt-get install libgtk-3-dev
$ libpython3-all-dev
# Install ccache
$ sudo apt-get install -y ccache
# Prepend ccache into the PATH
$ echo 'export PATH="/usr/lib/ccache:$PATH"' | tee -a ~/.bashrc
# Source bashrc to test the new PATH
$ source ~/.bashrc && echo $PATH
# Python3 find inlude path
$ python3
>>> from distutils.sysconfig import get_python_inc
>>> get_python_inc()
>>> ctrl+D or exit()