Friday, November 03, 2017

installing the latest OpenCV with Python bindings on Linux Mint 18.1

Followed the Ubuntu 16.04 tutorial by Adrian Rosebrock with some changes. Since my installation had python using anaconda, I used conda install instead of pip install. And since my first attempt at creating a virtual environment failed, I went ahead with the installation without a virtual environment. Most of the requirements were already installed. My cmake string also had a different path to the python executable due to anaconda.

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libjpeg8-dev libtiff5-dev libjasper-dev libpng12-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
sudo apt-get install libxvidcore-dev libx264-dev 
sudo apt-get install libgtk-3-dev
sudo apt-get install libatlas-base-dev gfortran
sudo apt-get install python2.7-dev python3.5-dev

OpenCV stable version is now 3.3.1, so

wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.3.1.zip
unzip opencv.zip
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.3.1.zip
unzip opencv_contrib.zip
conda install numpy
cd opencv-3.1.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D INSTALL_C_EXAMPLES=ON \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.1/modules \
    -D PYTHON_EXECUTABLE=/home/mac/anaconda2/bin/python \
    -D BUILD_EXAMPLES=ON ..
cmake rapidly went through its checks, then I had to do the build,
make
which took around half an hour judging by the timestamps - I was doing other things.... and then finally 

sudo make install
sudo ldconfig
Verified by doing

ls -l /usr/local/lib/python2.7/site-packages/
which showed up cv2.so
and finally linked this cv2.so to the site-packages folder, in my case

cd ~/anaconda2/lib/python2.7/site-packages
ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so
Tested by opening a python shell, importing cv2 and checking its version,

python
 >>> import cv2
>>> cv2.__version__
'3.3.1'
>>>

Edit: August 2019 - updated instructions for installing on Ubuntu 18.04 - 
https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/
 


No comments:

Post a Comment