Skip to content

Instantly share code, notes, and snippets.

@aredden
Last active October 3, 2021 18:41
Show Gist options
  • Save aredden/90306bfcb065a5781d3cb026f47ab871 to your computer and use it in GitHub Desktop.
Save aredden/90306bfcb065a5781d3cb026f47ab871 to your computer and use it in GitHub Desktop.
Shell script for installing opencv with cuda features enabled into a linux conda environment with python~3.8, numpy and cudatoolkit 11.4.
export CPLUS_INCLUDE_PATH=$CONDA_PREFIX/lib/python3.8
export NVIDIA_ARCH_CAPABILITY=8.6 #Change this to your gpu's compute capability
# This script requires a directory structure which looks like the following,
# with opencv-master from git, opencv_contrib-master from git, and a build directory
# with only this script inside. You must execute this shell script from inside the build
# directory, with your desired conda environment activated.
# The initial setup is copied from here: https://docs.opencv.org/3.4.15/d7/d9f/tutorial_linux_install.html
# With steps 2-5 replaced with this shell script.
# ├── build
# ├── opencv-master
# └── opencv_contrib-master
cmake -G"Unix Makefiles"\
-D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D CMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
-D PYTHON3_LIBRARY=$CONDA_PREFIX/lib/python3.8 \
-D PYTHON3_INCLUDE_DIR=$CONDA_PREFIX/include/python3.8 \
-D PYTHON3_NUMPY_INCLUDE_DIRS==$CONDA_PREFIX/lib/python3.8/site-packages/numpy/core/include \
-D PYTHON3_EXECUTABLE=$CONDA_PREFIX/bin/python \
-D PYTHON3_PACKAGES_PATH=$CONDA_PREFIX/lib/python3.8/site-packages \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CUDA_ARCH_BIN=NVIDIA_ARCH_CAPABILITY \
-D CUDA_FAST_MATH=ON \
-D OPENCV_DNN_CUDA=ON \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D WITH_CUBLAS=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
../opencv-master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment