Compile OpenCV for Conda

You can use the following command to configure opencv 4.5:

cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/opt/anaconda3 -DWITH_CUDA=ON -DENABLE_FAST_MATH=1 -DWITH_CUDNN=ON -DOPENCV_DNN_CUDA=ON -DCUDA_FAST_MATH=1 -DWITH_CUBLAS=1 -DCUDA_FAST_MATH=1 -DOPENCV_ENABLE_NONFREE=ON -DINSTALL_PYTHON_EXAMPLES=ON -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_opencv_python3=ON -D HAVE_opencv_python3=ON -DPYTHON3_EXECUTABLE=/opt/anaconda3/bin/python -DPYTHON3_DEFAULT_EXECUTABLE=/opt/anaconda3/bin/python -DPYTHON3_LIBRARIES=/opt/anaconda3/lib/libpython3.8.so -DPYTHON3_INCLUDE_DIRS=/opt/anaconda3/include/python3.8 -D__INSTALL_PATH_PYTHON3=/opt/anaconda3/lib/python3.8/site-packages -DBUILD_EXAMPLES=ON -DWITH_OPENGL=ON -DWITH_QT=ON ..
  • I have my conda installation under /opt/anaconda3, so please change accordingly.
  • Make sure you have downloaded the opencv-contrib to enable CUDA-related tools.