jetson-containers icon indicating copy to clipboard operation
jetson-containers copied to clipboard

Galactic image opencv issues

Open enricosutera opened this issue 2 years ago • 14 comments

Hello there, I'm trying to build a ros2 project using this image dustynv/ros:foxy-ros-base-l4t-r34.1.1 on a Nvidia Jetson NX with JP 4.6.1. I did not build the image, I used the already built one. Unfortunately I have issues with dependencies concerning opencv. I can't manage to install a lot of ros2 packages because the root dependency are libopencv and libopencv-dev. Of course they are not being installed because actually openCV is already installed (4.5.0) but not recognized. What am I missing? This is the output of fix --broken

$apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  librhash0 libuv1
Use 'apt autoremove' to remove them.
The following additional packages will be installed:
  libopencv libopencv-dev
The following NEW packages will be installed:
  libopencv libopencv-dev
0 upgraded, 2 newly installed, 0 to remove and 20 not upgraded.
261 not fully installed or removed.
Need to get 12.5 MB of archives.
After this operation, 70.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://repo.download.nvidia.com/jetson/common r34.1/main arm64 libopencv arm64 4.5.4-8-g3e4c170df4 [11.3 MB]
Get:2 https://repo.download.nvidia.com/jetson/common r34.1/main arm64 libopencv-dev arm64 4.5.4-8-g3e4c170df4 [1,247 kB]                                                        
Fetched 12.5 MB in 11s (1,108 kB/s)                                                                                                                                             
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 103043 files and directories currently installed.)
Preparing to unpack .../libopencv_4.5.4-8-g3e4c170df4_arm64.deb ...
Unpacking libopencv (4.5.4-8-g3e4c170df4) ...
dpkg: error processing archive /var/cache/apt/archives/libopencv_4.5.4-8-g3e4c170df4_arm64.deb (--unpack):
 trying to overwrite '/usr/share/opencv4/haarcascades/haarcascade_eye.xml', which is also in package opencv-libs 4.5.0
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Preparing to unpack .../libopencv-dev_4.5.4-8-g3e4c170df4_arm64.deb ...
Unpacking libopencv-dev (4.5.4-8-g3e4c170df4) ...
dpkg: error processing archive /var/cache/apt/archives/libopencv-dev_4.5.4-8-g3e4c170df4_arm64.deb (--unpack):
 trying to overwrite '/usr/bin/opencv_annotation', which is also in package opencv-dev 4.5.0
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libopencv_4.5.4-8-g3e4c170df4_arm64.deb
 /var/cache/apt/archives/libopencv-dev_4.5.4-8-g3e4c170df4_arm64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Hope to find some help!

enricosutera avatar Jun 14 '22 16:06 enricosutera

Hi @enricosutera, can you try running it like this:

DEBIAN_FRONTEND=noninteractive apt --fix-broken -y install

Or maybe you need to remove previous OpenCV first with apt-get purge -y '*opencv*'

dusty-nv avatar Jun 14 '22 16:06 dusty-nv

Hi @dusty-nv. I purged before running rosdep and everything worked fine! Thank you To be honest I'm not sure which the issue is

enricosutera avatar Jun 15 '22 10:06 enricosutera

I have the same issue with ROS Humble. It seems opencv is being installed from a private binary: https://github.com/dusty-nv/jetson-containers/blob/be0dca3d19b30e64d129c92e93425c9ede40d65f/Dockerfile.ros.galactic#L85 Is there any reason why we are not using the default debian package opencv-dev from APT ?

CourchesneA avatar Jun 21 '22 15:06 CourchesneA

Is there any reason why we are not using the default debian package opencv-dev from APT ?

The OpenCV packages from ubuntu apt are not built with CUDA enabled. Also depending on the Ubuntu distro, they can be older versions of OpenCV.

Instead, I install the OpenCV 4.5 that I built with CUDA enabled, and then compile ROS so that it is built to use that version of OpenCV. ROS is built from source and the apt packages are not used. ROS Humble is based on 22.04 while the JetPack 5.0 containers use 20.04 so the apt packages aren't able to be used anyways.

dusty-nv avatar Jun 21 '22 16:06 dusty-nv

I have a similar error showing up when I try to apt upgrade. I am using the dustynv/ros:foxy-ros-base-l4t-r35.1.0 image. Purging the opencv does not seem to be the best option. I want to use the CUDA enabled OpenCV.

This did not work out either:

DEBIAN_FRONTEND=noninteractive apt --fix-broken -y install

Here is the error that I am facing:

Preparing to unpack .../libopencv_4.5.4-8-g3e4c170df4_arm64.deb ...
Unpacking libopencv (4.5.4-8-g3e4c170df4) ...
dpkg: error processing archive /var/cache/apt/archives/libopencv_4.5.4-8-g3e4c170df4_arm64.deb (--unpack):
 trying to overwrite '/usr/share/opencv4/haarcascades/haarcascade_eye.xml', which is also in package opencv-libs 4.5.0
dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
Errors were encountered while processing:
 /var/cache/apt/archives/libopencv_4.5.4-8-g3e4c170df4_arm64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

tsadarsh avatar Oct 26 '22 20:10 tsadarsh

Hi @tsadarsh, can you try having apt-mark or dpkg hold/pin the package so it's not tried to be upgraded? https://askubuntu.com/a/99780

dusty-nv avatar Oct 26 '22 23:10 dusty-nv

That should solve the problem. Thank you @dusty-nv for the help.

tsadarsh avatar Oct 27 '22 16:10 tsadarsh

That should solve the problem. Thank you @dusty-nv for the help.

@tsadarsh Were you able to update and install rosdeps by not letting libopencv package to be upgraded?

fettahyildizz avatar Nov 03 '22 08:11 fettahyildizz

Hi @fettahyildizz. I did not try doing it that way.

You could try working by pulling this image (note the tag): docker pull tsadarsh/jetson:nano This image uses the CUDA cores of Jetson. It also has ROS 2 Foxy and libopencv package pre-installed.

Let me know if it solves your problem.

tsadarsh avatar Nov 04 '22 17:11 tsadarsh

Hello @tsadarsh, unfortunately our working environment is ROS Noetic. but thanks anyway. Could you provide your dockerfile so I can find out how you install cv2

fettahyildizz avatar Nov 04 '22 21:11 fettahyildizz

Our goal was to have a container that had PyTorch (Python >= 3.8 and CUDA cores enabled) along with ROS 2 Foxy. @waseemR02 did a lot of work in compiling many packages from source. It was basically a hit and trial approach. Compile, run, fix, repeat. Once we got all the necessary packages installed we pushed the image to DockerHub. Hence no Dockerfile was made.

I am sure @waseemR02 can be of some help.

You can still use our image and install ROS noetic in it.

tsadarsh avatar Nov 04 '22 22:11 tsadarsh

I used the image nvcr.io/nvidia/l4t-base:r32.7.1 as a base and later installed pytorch and foxy. You can try installling noetic after you solve the opencv dependency issue, basically a brute force method but it will atleast ensure that you are able to use CUDA cores. This gist might help you with that.

waseemR02 avatar Nov 07 '22 13:11 waseemR02

2 years later I stumbled upon this issue as well using the humble images

Hi @tsadarsh, can you try having apt-mark or dpkg hold/pin the package so it's not tried to be upgraded? https://askubuntu.com/a/99780

@dusty-nv would it make sense to add this to the dockerfiles after installing the cuda-enabled opencv?

tonynajjar avatar Jan 23 '24 13:01 tonynajjar

I've also stumbled upon this issue with humble when trying to build ros-humble-desktop

crytpy avatar Feb 02 '24 00:02 crytpy