How to install cuda and open-cv in jetson nano

my jetpack is 4.6 (rev 3)
when i tried installing components from SDK manager it led to failure in VPI ON HOST
I need to install cuda , open cv on jetson nano
i started with cuda
i tried installing manually
after flashing i copied these files from sdk_downloads into the device
image

sudo dpkg -i cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
Selecting previously unselected package cuda-repo-l4t-10-2-local.
(Reading database ... 160662 files and directories currently installed.)
Preparing to unpack cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb ...
Unpacking cuda-repo-l4t-10-2-local (10.2.460-1) ...
Setting up cuda-repo-l4t-10-2-local (10.2.460-1) ...

The public CUDA GPG key does not appear to be installed.
To install the key, run this command:
sudo apt-key add /var/cuda-repo-l4t-10-2-local/7fa2af80.pub

sudo dpkg -i cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb
(Reading database ... 160711 files and directories currently installed.)
Preparing to unpack cuda-repo-l4t-10-2-local_10.2.460-1_arm64.deb ...
Unpacking cuda-repo-l4t-10-2-local (10.2.460-1) over (10.2.460-1) ...
Setting up cuda-repo-l4t-10-2-local (10.2.460-1) ...

sudo dpkg -i cuda-repo-cross-aarch64-ubuntu1804-10-2-local_10.2.460-1_all.deb
Selecting previously unselected package cuda-repo-cross-aarch64-ubuntu1804-10-2-local.
(Reading database ... 160711 files and directories currently installed.)
Preparing to unpack cuda-repo-cross-aarch64-ubuntu1804-10-2-local_10.2.460-1_all.deb ...
Unpacking cuda-repo-cross-aarch64-ubuntu1804-10-2-local (10.2.460-1) ...
Setting up cuda-repo-cross-aarch64-ubuntu1804-10-2-local (10.2.460-1) ...
```------------------------------------------------------------------------------------------------

sudo dpkg -i cuda-repo-ubuntu1804-10-2-local_10.2.460-450.115-1_amd64.deb
dpkg: error processing archive cuda-repo-ubuntu1804-10-2-local_10.2.460-450.115-1_amd64.deb (–install):
package architecture (amd64) does not match system (arm64)
Errors were encountered while processing:
cuda-repo-ubuntu1804-10-2-local_10.2.460-450.115-1_amd64.deb


what is the issue with this

Hi,

Do you need OpenCV with CUDA acceleration or just OpenCV (CPU) and CUDA on a Jetson?

OpenCV with CUDA acceleration

What I do is install CUDA with the SDK Manager and build OpenCV from source. I build OpenCV as a Debian package so that it can be easily used on multiple boards.

  1. Flash the board and install CUDA with the SDK manager

  2. Enlarge memory swap (Only needed on Jetson Nano)

Setup dphys-swapfile

# install dphys-swapfile
sudo apt install -y dphys-swapfile nano
# enlarge the boundary (CONF_MAXSWAP=4096)
sudo nano /sbin/dphys-swapfile
# give the required memory size (CONF_SWAPSIZE=4096)
sudo nano /etc/dphys-swapfile
# reboot afterwards
sudo reboot

Check the swap size and available disk space

# Swap: 6074
free -m
# You need 24GB of disk space
df -h
  1. Install dependencies

Remove previous OpenCV and unnecessary packages to clean up some space

sudo apt update
sudo apt purge -y libreoffice* thunderbird* opencv-* libopencv*

Set CUDA location

cd ~
sudo sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf"
sudo ldconfig

Install OpenCV dependencies

sudo apt install -y \
build-essential cmake git unzip pkg-config zlib1g-dev libjpeg-dev libjpeg8-dev libjpeg-turbo8-dev \
libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libglew-dev libgtk2.0-dev \
libgtk-3-dev libcanberra-gtk* python-dev python-numpy python-pip python3-dev python3-numpy \
python3-pip libxvidcore-dev libx264-dev libgtk-3-dev libtbb2 libtbb-dev libdc1394-22-dev \
libxine2-dev gstreamer1.0-tools libv4l-dev v4l-utils qv4l2  libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev libavresample-dev libvorbis-dev libxine2-dev libtesseract-dev \
libfaac-dev libmp3lame-dev libtheora-dev libpostproc-dev libopencore-amrnb-dev libopencore-amrwb-dev \
libopenblas-dev libatlas-base-dev libblas-dev liblapack-dev liblapacke-dev libeigen3-dev gfortran \
libhdf5-dev protobuf-compiler libprotobuf-dev libgoogle-glog-dev libgflags-dev

Install Debian dependencies

sudo apt install -y devscripts build-essential lintian
  1. Download OpenCV and OpenCV contrib

Download the latest version (I use OpenCV 4.6, but this can be changed)

wget -O opencv.zip https://github.com/opencv/opencv/archive/4.6.0.zip 
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.6.0.zip 
unzip opencv.zip 
unzip opencv_contrib.zip
rm opencv.zip
rm opencv_contrib.zip

Move the folders into /home/nvidia/opencv. You will need to edit debian/rules if you use a different route.

mkdir ~/opencv
mv opencv-4.6.0 ~/opencv/opencv
mv opencv_contrib-4.6.0 ~/opencv/opencv_contrib
  1. Uncompress the debian folder attached into the opencv folder (It is a modified version from the one available at Debian in Launchpad)

debian.tar.gz (33.2 KB)

Using the default folder structure:

cd ~/opencv
tar -xf debian.tar.gz
  1. Build the debian

This command will run clean, configure, make, make install to a tmp folder, and generate the debian packages. It will take several hours

cd ~/opencv/opencv
debuild -b -us -uc

If you want to skip the clean step (In case something failed in the last steps) you can uncomment the clean and autoclean lines in debian/rules

--- #override_dh_auto_clean:
+++ override_dh_auto_clean:
 
--- #override_dh_clean:
+++ override_dh_clean:

You may need to edit the script /usr/bin/dpkg-shlibdeps to disable dependency check:

--- my $ignore_missing_info = 0;
+++ my $ignore_missing_info = 1;

If you just want to build OpenCV for your current board instead of a debian package, you can skip steps 5. and 6. and instead run the build command with these cmake flags:

CMAKE_FLAGS = \
	-DCMAKE_BUILD_TYPE=RELEASE \
	-DCMAKE_INSTALL_PREFIX=/usr \
	-DOPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules \
	-DEIGEN_INCLUDE_PATH=/usr/include/eigen3 \
	-DWITH_OPENCL=OFF \
	-DWITH_CUDA=ON \
	-DCUDA_ARCH_BIN="5.3,6.2,7.2" \
	-DCUDA_ARCH_PTX="" \
	-DWITH_CUDNN=ON \
	-DWITH_CUBLAS=ON \
	-DENABLE_FAST_MATH=ON \
	-DCUDA_FAST_MATH=ON \
	-DOPENCV_DNN_CUDA=ON \
	-DENABLE_NEON=ON \
	-DWITH_QT=OFF \
	-DWITH_OPENMP=ON \
	-DBUILD_TIFF=ON \
	-DWITH_FFMPEG=ON \
	-DWITH_GSTREAMER=ON \
	-DWITH_TBB=ON \
	-DBUILD_TBB=ON \
	-DBUILD_TESTS=OFF \
	-DWITH_EIGEN=ON \
	-DWITH_V4L=ON \
	-DWITH_LIBV4L=ON \
	-DOPENCV_ENABLE_NONFREE=ON \
	-DINSTALL_C_EXAMPLES=OFF \
	-DINSTALL_PYTHON_EXAMPLES=OFF \
	-DPYTHON3_PACKAGES_PATH=/usr/lib/python3/dist-packages \
	-DOPENCV_GENERATE_PKGCONFIG=ON \
        -DCMAKE_BUILD_TYPE=Release \
        -DBUILD_WITH_DEBUG_INFO=OFF \
        -DENABLE_PROFILING=OFF \
	-DBUILD_EXAMPLES=OFF

Note: The debian folder and the flags I sent are for JetPack 4.6.1, for a more recent JetPack you will need to edit DCUDA_ARCH_BIN to match your device arch.

Note 2: The instructions and the flags are based on this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.