How to make catkin_make use correct opencv version ?

asked 2023-04-02 08:15:45 -0500

elpidiovaldez gravatar image

I am using ROS Noetic on Lubuntu 20.04. I am trying to compile a small node that uses opencv, but it appears to be linking with an incorrect version of opencv.

There is a version of opencv 4.2.0 installed in /usr/lib/x86_64-linux-gnu. This is the version installed by the package libopencv-dev, and I believe this is the version that ROS should use.

dpkg -L libopencv-dev | grep cmake
/usr/lib/x86_64-linux-gnu/cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig-version.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVConfig.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVModules-release.cmake
/usr/lib/x86_64-linux-gnu/cmake/opencv4/OpenCVModules.cmake

But when I inspect the executable produced by catkin_make, it appears to be linking to another version of opencv in/usr/local.

ldd esp32cam_to_ros_node | grep opencv
libopencv_videoio.so.4.2 => /usr/local/lib/libopencv_videoio.so.4.2 (0x00007fd1a9199000)
libopencv_core.so.4.2 => /usr/local/lib/libopencv_core.so.4.2 (0x00007fd1a7e05000)
libopencv_imgcodecs.so.4.2 => /usr/local/lib/libopencv_imgcodecs.so.4.2 (0x00007fd1a76c4000)
libopencv_imgproc.so.4.2 => /usr/local/lib/libopencv_imgproc.so.4.2 (0x00007fd1a58a0000)

It appears that many versions of opencv are (or were) installed:

locate libopencv_core
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/STGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/STGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/STGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2.0
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TGZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2.0
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2
/home/paul/.local/share/Trash/expunged/3321726000/OpenCVSrc/opencv/build/_CPack_Packages/Linux/TZ/OpenCV-4.2.0-dirty-x86_64/lib/libopencv_core.so.4.2.0
/snap/libreoffice/265/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2
/snap/libreoffice/265/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2.0
/snap/libreoffice/270/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.5.4d
/snap/libreoffice/270/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.5d
/usr/lib/x86_64-linux-gnu/libopencv_core.a
/usr/lib/x86_64-linux-gnu/libopencv_core.so
/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2
/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2.0
/usr/local/lib/libopencv_core.so
/usr/local/lib/libopencv_core.so.4.2.0

I think the version in /usr/local/lib resulted from an attempt to compile opencv from source with gstreamer and cuda, but it cannot load because it says gstreamer is missing a component.

I don ... (more)

edit retag flag offensive close merge delete