This guide is based on
https://www.scivision.co/anaconda-python-opencv3/. It is targeted at installing a minimal OpenCV 3.4.4 in an Anaconda environment with Python 3.6 or 3.7.
I assume you already use conda.
Create an environment
Create an environment and activate it. Make sure you install all packages that you will need later (e.g. scikit-image).
conda create -n my-env python=3.7 numpy
conda activate my-env
Get OpenCV
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout tags/3.4.4
Configure CMake
mkdir release-myenv
cd release-myenv
cmake -DBUILD_TIFF=ON -DBUILD_opencv_java=OFF -DWITH_CUDA=OFF -DWITH_OPENGL=ON -DWITH_OPENCL=OFF -DWITH_IPP=OFF -DWITH_TBB=OFF -DWITH_EIGEN=OFF -DWITH_V4L=OFF -DWITH_VTK=OFF -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_python3=yes -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -DPYTHON3_EXECUTABLE=$(which python) -DPYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..
Build & Install
make -j -l 4
make install
Test OpenCV
# Output should be empty
python -c "import cv2"
For a more advanced test, use the example in the article mentioned at the beginning:
https://www.scivision.co/anaconda-python-opencv3/#2-test-opencv
Problems
If the package is not importable, you may have to copy over the .so file to the correct location (e.g. <path/to/anaconda>/envs/<env>/lib/python3.7/site-packages).