Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wuthmone/b9b0b0fa4041455c36f1f046350f28f4 to your computer and use it in GitHub Desktop.
Save wuthmone/b9b0b0fa4041455c36f1f046350f28f4 to your computer and use it in GitHub Desktop.
OpenCV 3.3.0 with Python 3.5 installation on Ubuntu 17.04
# OpenCV 3.3.0 with Python 3.5 installation on Ubuntu 17.04
# Last Tested Date: 26th Oct 2017 12:23 PM
# Authour : Wut Hmone Hnin Hlaing
# Update and Upgrade required library
sudo apt-get update
sudo apt-get upgrade
# Necessary packages
sudo apt-get install build-essential cmake git pkg-config
sudo apt-get install libjpeg8-dev libtiff5-dev
echo "deb http://us.archive.ubuntu.com/ubuntu/ yakkety universe" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install libjasper-dev
echo "deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/ xenial main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install libpng-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 python3-pip
# Check for python configration
python3.5-config --includes
-I/usr/include/python3.5m -I/usr/include/python3.5m
# Intall virtualenv to create seperate Virtual Env to workon
sudo pip3 install virtualenv virtualenvwrapper
# Update the Virtual Env to the Ubuntu Env
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
sudo vi ~/.bashrc
source ~/.bashrc
# Create OpenCV virtualenvs
mkvirtualenv OpenCV
# Install required dev packages
sudo apt-get install python3.5-dev
sudo pip3 install -U numpy
## Download the version of opencv you wanna install (replace the vrsion number)
cd ~/opencv-3.3.0
mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
-D BUILD_EXAMPLES=ON ..
sudo make -j $(nproc --all)
sudo make install
sudo ldconfig
# Check you have cv2.*.so in your that directory
cd /usr/local/lib/python3.5/dist-packages
ls
# If you have it, then you are good to go.. if not better restart from beginning
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 the envs
deactivate
# Testing your OpenCv lib
workon OpenCV
import cv2
cv2.__version__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment