Prerequisite

  • Ubuntu 18.04
  • Nvidia Driver with corresponding CUDA and cuDNN installed

Build

1
2
# Install minimal prerequisites (Ubuntu 18.04 as reference)
sudo apt update && sudo apt install -y cmake g++ wget unzip
1
2
3
4
5
# Download and unpack sources
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/master.zip
unzip opencv.zip
unzip opencv_contrib.zip
1
2
3
4
# Create build directory and switch into it
mkdir -p build && cd build
# Configure (remember to flag: WITH_CUDA=ON)
cmake -DWITH_CUDA=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master
1
2
# Build
cmake --build .

It should take a long while to build.

1
2
#Install (or just `make install` if you are in root)
sudo make install

Reference

OpenCV - Installation in Linux

OpenCV configuration options reference