---
# System prepended metadata

title: Ubuntu CUDA OpenCV Installation
tags: [' opencv', ' linux', tutorial]

---

---
tags: tutorial, opencv, linux
---

# Ubuntu CUDA OpenCV Installation

- [Official Doc](https://docs.opencv.org/4.5.2/db/d05/tutorial_config_reference.html): cmake option reference

## Step (OpenCV Version: 4.5.0)

```bash=
sudo apt-get update

sudo apt-get install libjpeg-dev libpng-dev \
libtiff-dev libavcodec-dev libavformat-dev \
libswscale-dev libv4l-dev libxvidcore-dev \
libx264-dev libatlas-base-dev 

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.0.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.0.zip

unzip opencv.zip
unzip opencv_contrib.zip
mv opencv-4.5.0 opencv
mv opencv_contrib-4.5.0 opencv_contrib

mkdir -p opencv/build/ && cd opencv/build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_PYTHON_EXAMPLES=OFF \
      -D INSTALL_C_EXAMPLES=OFF \
      -D BUILD_opencv_python3=ON \
      -D WITH_CUDA=ON \
      -D WITH_CUDNN=ON \
      -D OPENCV_DNN_CUDA=ON \
      -D ENABLE_FAST_MATH=1 \
      -D CUDA_FAST_MATH=1 \
      -D CUDA_ARCH_BIN=7.0 \
      -D WITH_CUBLAS=1 \
      -D OPENCV_ENABLE_NONFREE=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=OFF ..
      
      
make -j4
sudo make install
```
