Project

General

Profile

Actions

Building OpenCV

Prerequisites

  1. Install CUDA: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/
  2. Install cuDNN:
    $ sudo apt install libcudnn8 libcudnn8-dev
    
  3. Install OpenCV prereqs:
    $ sudo apt install build-essential cmake git pkg-config libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base-dev python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev libopenexr-dev libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev libvtk7-dev libdc1394-dev
    

Build from source

  1. From a working directory clone the contrib repository:
    $ git clone https://github.com/opencv/opencv_contrib.git
    
  2. Download OpenCV release (currently 4.7.0) to working directory and untar:
    $ wget https://github.com/opencv/opencv/archive/refs/tags/4.7.0.tar.gz
    $ tar xf 4.7.0.tar.gz
    
  3. Create build directory and enter it:
    $ mkdir biuld
    $ cd build
    
  4. Configure build (NOTE: this will set the install directory to /opt/local, change as needed):
    $ cmake -D CMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/opt/local -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_EXTRA_MODULES_PATH=../..//opencv_contrib/modules -DBUILD_opencv_legacy=OFF -DWITH_CUDA=ON -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_opencv_apps=OFF ..
    
  5. Build (this will take a while) then install:
    $ make -j32
    $ sudo make install
    

Miscellaneous

  • To use the OpenCV Python bindings you need to set the PYTHONPATH to include the install directory under /opt/local:
    $ export PYTHONPATH="/opt/local/lib/python3.10/dist-packages" 
    

Updated by over 3 years ago · 1 revisions