In this tutorial, we are compiling and install OpenCV 4.5.1
and OpenCV Contrib 4.5.1
with CUDA 10.2
and cuDNN 7.6.5
. Other versions should aslo work.
- Download and extract the source code of
OpenCV 4.5.1
andOpenCV Contrib 4.5.1
. Assume that the root directory for each is$opencv-4.5.1
and$opencv_contrib-4.5.1
. - Install
CUDA 10.2
andcuDNN 7.6.5
following NVIDIA's guide. Assume that the root directory for CUDA is/usr/local/cuda-10.2
.
See build_with_cuda.sh
and modify accordingly.
make -j
make install
After compiling and installing, there should be a file named cv2.cpython-38-x86_64-linux-gnu.so
in $CMAKE_INSTALL_PREFIX/lib/python3.8/site-packages/cv2/python-3.8
.
Create a symlink to this file from your Python environment:
cd $PYTHON3_LIBRARY/python3.8/site-packages
ln -s $CMAKE_INSTALL_PREFIX/lib/python3.8/site-packages/cv2/python-3.8/cv2.cpython-38-x86_64-linux-gnu.so cv2.so
Switch to the Python env you just installed OpenCV, then:
python
>>> import cv2
>>> cv2.__version__
`4.5.1`
check : https://gist.github.com/madtunebk/5f20437725eb0e0cfc2a4934153b0ab4