- download OpenCV 3.3.1 and unzip.
# download opencv 3.3.1
# https://codeload.github.com/opencv/opencv/zip/3.3.1
unzip opencv-3.3.1.zip
cd opencv-3.3.1
mkdir build
cd build
- configure and build
# specify CUDA_ARCH_BIN to speed up building
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV/usr/local -D PYTHON3_EXECUTABLE=$VIRTUAL_ENV/bin/python -D BUILD_opencv_python3=ON -DCUDA_ARCH_BIN="6.1" ..
make -j7
make install
if you just want to install in /usr/local
instead if virtual environment, run the following command:
cmake -D CMAKE_BUILD_TYPE=Release -D PYTHON3_EXECUTABLE=$(which python3) -D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -D PYTHON3_LIBRARY=$(python3 -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))") -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -D BUILD_opencv_python3=ON -DCUDA_ARCH_BIN="6.1" ..
- add path
# take care of python version
# add this to your bash/zsh profile
export PYTHONPATH="$VIRTUAL_ENV/usr/local/lib/python3.6/site-packages:$PYTHONPATH"
export PKG_CONFIG_PATH="$VIRTUAL_ENV/usr/local/lib/pkgconfig/"
export LD_LIBRARY_PATH="$VIRTUAL_ENV/usr/local/lib/:$LD_LIBRARY_PATH"