Forked from Asymptote/Python 3.4+ with OpenCV 3.1.0 Binding on Ubuntu 14.04
Created
May 19, 2018 18:04
-
-
Save jorgeas80/8ee60bdf7d00bb75fc86c8d9a1022b4c to your computer and use it in GitHub Desktop.
Python 3.4+ with OpenCV 3.1.0 Binding on Ubuntu 14.04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I have followed PyImageSearch tutorial http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/ | |
# Ubuntu upgrade & update current libraries | |
sudo apt-get update | |
sudo apt-get upgrade | |
# Install dependancies | |
sudo apt-get install build-essential cmake git 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 | |
# Setup Python 3 .. | |
# Install pip | |
wget https://bootstrap.pypa.io/get-pip.py | |
sudo python3 get-pip.py | |
# Using virtualenv and virtualenvwrapper | |
sudo pip3 install virtualenv virtualenvwrapper | |
############################################### | |
# | |
# export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 | |
# export WORKON_HOME=$HOME/.virtualenvs | |
# source /usr/local/bin/virtualenvwrapper.sh | |
# | |
# You have to update ~/.bashrc file (place at the bottom of the file): | |
################################################# | |
# Reflecting the changes inside ~/.bashrc | you can exit and login terminal again | |
source ~/.bashrc | |
# Creating a virtual Environment for working | |
mkvirtualenv cv3 | |
# Installing python3.4-dev | |
sudo apt-get install python3.4-dev | |
#Install NumPy | |
pip install numpy | |
# Build and install OpenCV 3.0 with Python 3.4+ bindings | |
# Download Open CV 3.0.0 from source code // Checkout Takes long time | |
cd ~ | |
git clone https://github.com/Itseez/opencv.git | |
cd opencv | |
git checkout 3.1.0 | |
# Download Open CV _contrib from source code // Checkout Takes long time | |
cd ~ | |
git clone https://github.com/Itseez/opencv_contrib.git | |
cd opencv_contrib | |
git checkout 3.1.0 | |
# Install open CV ver 3.1 with insuring the binding with _contribute | |
cd ~/opencv | |
mkdir build | |
cd build | |
cmake -D CMAKE_BUILD_TYPE=RELEASE \ | |
-D CMAKE_INSTALL_PREFIX=/usr/local \ | |
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \ | |
-D BUILD_opencv_python3=ON .. | |
# Build and compile the source code // Takes looooong time > ~30 minute | |
# I got an error here, and Its solution was to enlarge the memory size as vagrant's default memory alloc. was 256M, give it 4G | |
make -j4 | |
# Installation for OpenCV | |
sudo make install | |
sudo ldconfig | |
## Insuring the binding between OpenCV & Python | |
ls -l /usr/local/lib/python3.4/site-packages/ | |
# It would print similar to the following line | |
# -rw-r--r-- 1 root staff 1893192 May 18 12:20 cv2.cpython-34m.so | |
cd ~/.virtualenvs/cv3/lib/python3.4/site-packages/ | |
ln -s /usr/local/lib/python3.4/site-packages/cv2.cpython-34m.so cv2.so | |
# For Testing the Environment setup | |
workon cv3 | |
python | |
# /** Python Code ----- | |
>>> import cv2 | |
>>> cv2.__version__ | |
'3.1.0' | |
# Python Code ----- **/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment