Build opencv 4.3.0 with cuda on Jeson Xavier NX

Hi, I would like to build opencv 4.3 with cuda on Jeson Xavier NX, in order to use videostab library, is there any scripts or guide to build it?

Although named “nano build opencv”, this works on Xavier AGX and NX as well: GitHub - mdegans/nano_build_opencv: Build OpenCV on Nvidia Jetson Nano

Thank you! But there are some errors in install_dependencies step:

nvidia@jetsonnx:~/Projects/opencv-4.3$ bash ./install_opencv.sh 4.3.0
It appears an existing build exists in /tmp/build_opencv
Do you wish to remove temporary build files in /tmp/build_opencv ?
(Doing so may make running tests on the build later impossible)
Y/N y
Installing build dependencies.
Get:1 file:/var/cuda-repo-10-2-local-10.2.89 InRelease
Ign:1 file:/var/cuda-repo-10-2-local-10.2.89 InRelease
Get:2 file:/var/visionworks-repo InRelease
Ign:2 file:/var/visionworks-repo InRelease
Get:3 file:/var/visionworks-sfm-repo InRelease
Ign:3 file:/var/visionworks-sfm-repo InRelease
Get:4 file:/var/visionworks-tracking-repo InRelease
Ign:4 file:/var/visionworks-tracking-repo InRelease
Get:5 file:/var/cuda-repo-10-2-local-10.2.89 Release [574 B]
Get:5 file:/var/cuda-repo-10-2-local-10.2.89 Release [574 B]
Get:6 file:/var/visionworks-repo Release [2,001 B]
Get:6 file:/var/visionworks-repo Release [2,001 B]
Get:7 file:/var/visionworks-sfm-repo Release [2,005 B]
Get:7 file:/var/visionworks-sfm-repo Release [2,005 B]
Get:8 file:/var/visionworks-tracking-repo Release [2,010 B]
Get:8 file:/var/visionworks-tracking-repo Release [2,010 B]
Hit:15 Index of /ubuntu-ports bionic InRelease
Hit:13 https://repo.download.nvidia.cn/jetson/common r32.4 InRelease
Hit:14 https://repo.download.nvidia.cn/jetson/t194 r32.4 InRelease
Reading package lists… Done
Reading package lists… Done
Building dependency tree
Reading state information… Done
Calculating upgrade… Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists… Done
Building dependency tree
Reading state information… Done
build-essential is already the newest version (12.4ubuntu1).
build-essential set to manually installed.
cmake is already the newest version (3.10.2-1ubuntu2).
libcanberra-gtk3-module is already the newest version (0.30-5ubuntu1).
libcanberra-gtk3-module set to manually installed.
libv4l-dev is already the newest version (1.14.2-1).
pkg-config is already the newest version (0.29.1-0ubuntu2).
pkg-config set to manually installed.
python-dev is already the newest version (2.7.15~rc1-1).
python-numpy is already the newest version (1:1.13.3-2ubuntu1).
python3-numpy is already the newest version (1:1.13.3-2ubuntu1).
python3-numpy set to manually installed.
zlib1g-dev is already the newest version (1:1.2.11.dfsg-0ubuntu2).
zlib1g-dev set to manually installed.
libeigen3-dev is already the newest version (3.3.4-4).
libeigen3-dev set to manually installed.
libtbb-dev is already the newest version (2017~U7-8).
libtbb2 is already the newest version (2017~U7-8).
qv4l2 is already the newest version (1.14.2-1).
v4l-utils is already the newest version (1.14.2-1).
v4l2ucp is already the newest version (2.0.2-4build1).
libgstreamer-plugins-base1.0-dev is already the newest version (1.14.5-0ubuntu1~18.04.1).
libgstreamer1.0-dev is already the newest version (1.14.5-0ubuntu1~18.04.1).
git is already the newest version (1:2.17.1-1ubuntu0.5).
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
gfortran : Depends: gfortran-7 (>= 7.3.0-12~) but it is not going to be installed
libavcodec-dev : Depends: libavutil-dev (= 7:3.4.2-2) but it is not going to be installed
Depends: libswresample-dev (= 7:3.4.2-2) but it is not going to be installed
libavformat-dev : Depends: libavformat57 (= 7:3.4.2-2) but it is not going to be installed
Depends: libavutil-dev (= 7:3.4.2-2) but it is not going to be installed
Depends: libswresample-dev (= 7:3.4.2-2) but it is not going to be installed
libavresample-dev : Depends: libavutil-dev (= 7:3.4.2-2) but it is not going to be installed
Depends: libavresample3 (= 7:3.4.2-2) but 7:3.4.6-0ubuntu0.18.04.1 is to be installed
libgstreamer-plugins-good1.0-dev : Depends: libgstreamer-plugins-good1.0-0 (= 1.14.0-1ubuntu1) but 1.14.5-0ubuntu1~18.04.1 is to be installed
libgtk-3-dev : Depends: libgtk-3-0 (= 3.22.30-1ubuntu1) but 3.22.30-1ubuntu4 is to be installed
Depends: gir1.2-gtk-3.0 (= 3.22.30-1ubuntu1) but 3.22.30-1ubuntu4 is to be installed
Depends: libpango1.0-dev (>= 1.40.5) but it is not going to be installed
Depends: libatk-bridge2.0-dev but it is not going to be installed
Depends: libcairo2-dev (>= 1.14.0) but it is not going to be installed
Depends: libxkbcommon-dev but it is not going to be installed
libjpeg-turbo8-dev : Depends: libjpeg-turbo8 (= 1.5.2-0ubuntu5) but 1.5.2-0ubuntu5.18.04.3 is to be installed
libpng-dev : Depends: libpng16-16 (= 1.6.34-1) but 1.6.34-1ubuntu0.18.04.2 is to be installed
Recommends: libpng-tools but it is not going to be installed
libpostproc-dev : Depends: libavutil-dev (= 7:3.4.2-2) but it is not going to be installed
Depends: libpostproc54 (= 7:3.4.2-2) but 7:3.4.6-0ubuntu0.18.04.1 is to be installed
libswscale-dev : Depends: libavutil-dev (= 7:3.4.2-2) but it is not going to be installed
Depends: libswscale4 (= 7:3.4.2-2) but 7:3.4.6-0ubuntu0.18.04.1 is to be installed
libtiff-dev : Depends: libtiff5-dev (>= 4.0.9-1) but it is not going to be installed
python3-dev : Depends: python3 (= 3.6.5-3) but 3.6.7-1~18.04 is to be installed
Depends: libpython3-dev (= 3.6.5-3) but it is not going to be installed
Depends: python3.6-dev (>= 3.6.5-2~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

AastaLLL has provided a script.

Thanks warren, I have tried AastaLL’s script earlier. Since some packages were not installed correctly, I can’t use GUI like imshow. How can I fix broken packages above?

I don’t really know. Other than a sudo apt update, reinstall sdk, or clearing cache.

There is a message about The following packages have unmet dependencies: so maybe try installing those.

I have tried apt update and installed dependencies, but it didn’t work, I decide to reinstall sdk and build opencv with AastaLL’s script.

1 Like

I’m running into the same error trying to install libgtk-3-dev package. apt-get update plus a later upgrade didn’t help.
Any ideas what’s wrong with the libgtk-3 packages?

This might provide some insight:

zeus@zeus-desktop:~$ apt-cache policy libgtk-3-0
libgtk-3-0:
  Installed: 3.22.30-1ubuntu4
  Candidate: 3.22.30-1ubuntu4
  Version table:
 *** 3.22.30-1ubuntu4 100
        100 /var/lib/dpkg/status
     3.22.30-1ubuntu1 500
        500 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 Packages

zeus@zeus-desktop:~$ sudo apt-get install -s libgtk-3-0=3.22.30-1ubuntu1
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libgnome-autoar-0-0
Use 'sudo apt autoremove' to remove it.
Recommended packages:
  libgtk-3-bin
The following packages will be REMOVED:
  libgail-3-0 libgtk-3-bin nautilus nautilus-share ubuntu-desktop
The following packages will be DOWNGRADED:
  libgtk-3-0
0 upgraded, 0 newly installed, 1 downgraded, 5 to remove and 0 not upgraded.
Remv ubuntu-desktop [1.417.4]
Remv nautilus-share [0.7.3-2ubuntu3]
Remv nautilus [1:3.26.4-0~ubuntu18.04.5]
Remv libgail-3-0 [3.22.30-1ubuntu4]
Remv libgtk-3-bin [3.22.30-1ubuntu4]
Inst libgtk-3-0 [3.22.30-1ubuntu4] (3.22.30-1ubuntu1 Ubuntu:18.04/bionic [arm64])
Conf libgtk-3-0 (3.22.30-1ubuntu1 Ubuntu:18.04/bionic [arm64])

zeus@zeus-desktop:~$ apt-cache policy libgtk-3-dev
libgtk-3-dev:
  Installed: (none)
  Candidate: 3.22.30-1ubuntu1
  Version table:
     3.22.30-1ubuntu1 500
        500 http://ports.ubuntu.com/ubuntu-ports bionic/main arm64 Packages

Not sure how to solve this conflict but it seems like it’s got something to do with the two different versions in the version table of the libgtk-3-0 package.

If anyone else encounters this issue with the libgtk-3-dev package, here’s the solution I found today:

Edit /etc/apt/sources.list and add the following:

deb Index of /ubuntu-ports bionic-updates main

With this I could finally install libgtk-3-dev version 3.22.30-1ubuntu4.

1 Like