OpenCV 4.0 Build with Conda

Build from source to install opencv 4 and compatible with conda:

Dependencies

[compiler] sudo apt-get install build-essential
[required] sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
[optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

Clone Repo

Create a temporary directory, which we denote as , where you want to put the generated Makefiles, project files as well the object files and output binaries and enter there.

cd ~/<my_working_directory>
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git

And build:

cd ~/<my_working_directory>/opencv
mkdir build
cd build

configure the build:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

make the project:

sudo make -j8 install

If you are building under conda environment, there might be an error telling you libtiff5 library missing:

/usr/bin/ld: warning: libzstd.so.1.3.7, needed by //home/XXX/miniconda3/lib/libtiff.so.5, not found (try using -rpath or -rpath-link)

simply do the following:

sudo apt install libtiff5-dev
sudo cp /usr/lib/x86_64-linux-gnu/libtiff.so.5 /home/XXX/miniconda3/lib/

then build again, opencv4 should be successfully installed in your system with updated python in your conda.

Written on February 14, 2019