We just need to know how many cores our CPU has available.
If CMake exited without any errors, we are ready to compile OpenCV. Compile OpenCV with GPU acceleration support That indicates that the pre-build was succesful. Configuring done - Generating done - Build files have been written to: /home/j/opencv/build NVIDIA CUDA: YES (ver 11.6, CUFFT CUBLAS) - NVIDIA GPU arch: 61 - NVIDIA PTX archs: - cuDNN: YES (ver 8.3.2). General configuration for OpenCV 4.5.5-dev =. The CXX compiler identification is GNU 9.4.0. You should have an output similar to the following one. The following command is equivalent to that one: $ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_CUDA=ON -D WITH_CUDNN=ON -D WITH_CUBLAS=ON -D WITH_TBB=ON -D OPENCV_DNN_CUDA=ON -D OPENCV_ENABLE_NONFREE=ON -D CUDA_ARCH_BIN=6.1 -D OPENCV_EXTRA_MODULES_PATH=$HOME/opencv_contrib/modules -D BUILD_EXAMPLES=OFF -D HAVE_opencv_python3=ON. The \ tell the console to expect a new line inside the same command. Run CMake with the following flags: $ cmake \ -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_CUDA=ON \ -D WITH_CUDNN=ON \ -D WITH_CUBLAS=ON \ -D WITH_TBB=ON \ -D OPENCV_DNN_CUDA=ON \ -D OPENCV_ENABLE_NONFREE=ON \ -D CUDA_ARCH_BIN=6.1 \ -D OPENCV_EXTRA_MODULES_PATH=$HOME/opencv_contrib/modules \ -D BUILD_EXAMPLES=OFF \ -D HAVE_opencv_python3=ON \. Prepare the build directory: $ cd ~/opencv $ mkdir build $ cd build You can find a detailed reference of these at the end of this article. We will be using a bunch of CMake flags to compile OpenCV. Prepare to compile with CUDA and cuDNN support This is the NVIDIA GPU architecture version, which will be the value for the CMake flag: CUDA_ARCH_BIN=6.1. Next to the model name, you will find the Comput Capability of the GPU. To set the flag correctly, let’s first determine the NVIDIA GPU model using the nvidia-smi -L command: If this flag is not set correctly, the final use of the binaries would fail. Determine the CUDA architecture versionĬMake needs a CUDA_ARCH_BIN flag to be set in order to compile the binaries with the correct CUDA architecture. These modules are required to use the CUDA funcionality with OpenCV. We will also be downloading the OpenCV’s extra modules (CMake flag -D OPENCV_EXTRA_MODULES_PATH) repository.
Now, download the OpenCV repository using Git: $ git clone
formats: $ sudo apt install libpng-dev libjpeg-dev libopenexr-dev libtiff-dev libwebp-dev The next dependencies are optional but add the latest support for PNG, JPEG, JPEG2000, TIFF, WebP, etc. GTK is requried for GUI features, Camera support (v4l), Media Support (ffmpeg, gstreamer…), etc.: $ sudo apt install libavcodec-dev libavformat-dev libswscale-dev $ sudo apt install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev $ sudo apt install libgtk-3-dev To support Python 3 installations, we need Python (it comes pre-installed with most Ubuntu versions), Python-devel and Numpy: $ sudo apt install python3 python3-dev python3-numpy DependenciesĬMake and GCC are required to configure the installation and compile the project: $ sudo apt install cmake $ sudo apt install gcc g++
Once you are set, let’s continue with the dependencies.