Current OpenCV version only support CUDA 10.1.
Download sources
$ wget https://github.com/opencv/opencv/archive/4.2.0.tar.gz
$ wget https://github.com/opencv/opencv_contrib/archive/4.2.0.tar.gz
Extract the compressed files
$ tar zxf opencv-4.2.0.tar.gz
$ tar zxf opencv_contrib-4.2.0.tar.gz
CMake configuration
$ cd opencv-4.2.0
$ mkdir build
$ cd build
$ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.2.0/modules -DWITH_CUDA=ON -DBUILD_EXAMPLES=ON -DCMAKE_BUILD_TYPE=Release ..
Build
$ make -j8
It takes 15 ~ 20 minutes. And install,
$ sudo make install
Check installations
$ opencv_version
4.2.0
$ python3
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2
<module 'cv2' from '/usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-x86_64-linux-gnu.so'>
>>>
Done.