OpenCV GPU-CUDA installation on Ubuntu

preview_player
Показать описание
After watching that video, you will be able to use OpenCV accelerated by GPU. You can also use this tutorial for Nvidia Jetson Developer Computers.
#Nvidia #Cuda #OpenCV
Thanks for watching.

This method is tested on my laptop, Jetson TX2, and Jetson Xavier NX
Improved by me :)

1- First, install requirements:

sudo apt update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python-dev python-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get install -y libboost-all-dev

2- Then, download Open-cv files, unzip them, and create a build file

cd opnecv-3.4.1
mkdir build && cd build

3- Create build files

cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="6.2" -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

4- And then, compile the library.
To speed up the compile of the library, we need to specify the number of CPU cores in our system, otherwise, you can just use 1 core with no problems.
For example, I have 8 cores.

nproc
-: 8
make -j8

This step is where you face the errors, usually a quick google search and a re-build fixes most of the errors.

5- Finally, install Opec-CV 3.4.1

sudo make install

Errors:
fatal error: dynlink_nvcuvid.h: No such file or directory
#include (dynlink_nvcuvid.h)

Solution:
Replace step 3 with:
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="6.2" -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -DBUILD_opencv_cudacodec=OFF -D CMAKE_INSTALL_PREFIX=/usr/local ..

And remember to use the appropriate CUDA_ARCH_BIN value for your GPU.
Рекомендации по теме
Комментарии
Автор

how can i install nvidia driver? and is it necessary before install cuda?

landscaper
Автор

Hi there is it possible to install CUDA with anaconda ? I doesn't work for me (Ubuntu 22.04)

eddygonzalez
Автор

Hi,
I need the help of yours on making robots for my college project,
I have to make 4 robots that are controlled by 1 external placed camera module. In this project No sensors for navigation/object detection to be mounted on the robot.
Only 1 external placed camera module will do Live Image Processing and control the robots.
I need your help and valuable suggestions on this, I am planning to use Model predictive control

(hardware- NVIDIA jetson nano for image processing)

RohitSharma-yben