Docker OpenCV ROS error

Hi, I am using a JP5.0.1 docker image, and I am getting this error when installing ROS2 packages with opencv dependencies and the docker build fails.

dpkg: error processing archive /tmp/apt-dpkg-install-r5EKMv/293-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

Unpacking libopencv-dev (4.5.4-8-g3e4c170df4) ...
dpkg: error processing archive /tmp/apt-dpkg-install-r5EKMv/303-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

Errors were encountered while processing:
 /tmp/apt-dpkg-install-r5EKMv/293-libopencv_4.5.4-8-g3e4c170df4_arm64.deb
 /tmp/apt-dpkg-install-r5EKMv/303-libopencv-dev_4.5.4-8-g3e4c170df4_arm64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Hi @MrOCW, can you try removing the previous OpenCV packages from the container first with apt-get purge -y '*opencv*' ?

Same issue with JP5.0.1 building ros1 noetic desktop - @dusty_nv suggested fix of removing the OpenCV packages appears to have worked for me (at least I’ve got past the point where the build failed previously).

I added a line to dockerfile.ros.noetic just before the #download/build the ROS source step as follows.
RUN apt-get purge -y '*opencv*'

yes that is my current approach now but I’m worried it will mess up some other dependencies stuff.

If you prefer, you could rebuild the ROS container(s) and comment out this section of the Dockerfiles:

https://github.com/dusty-nv/jetson-containers/blob/be0dca3d19b30e64d129c92e93425c9ede40d65f/Dockerfile.ros.foxy#L83

then it won’t have been installed in the first place (OpenCV will then also not be able to use CUDA)