This repo solves the problem where multiple versions of OpenCV has to coexist, typical cases of failure:
-
Potentially conflicting .so lib versions
- To reproduce, do not use this repo, then compile your packages that depend on both cv_bridge and libopencv-dev
-
Multiple versions of OpenCV libs are loaded together, you can see that both
/lib/aarch64-linux/gnu/libopencv_imgcodecs.so.4.2
andlib/aarch64-linux/gnu/libopencv_imgcodecs.so.4.5
are loaded, similar for other OpenCV libs- To reproduce, do not install OpenCV from source, then
mon launch
your node, start gdb debugger, and doinfo sharedlibrary
- To reproduce, do not install OpenCV from source, then
-
Put this package under your catkin workspace
-
Build OpenCV from source and install under
/usr/local
(default location ofsudo make install
)- Set
OpenCV_DIR="/usr/local/lib/cmake/opencv4/"
in/etc/environment
to set environment variable,source
or logout and login for it to take effect. You can alsoexport
for temporary tests or set it in your~/.bashrc
sudo ldconfig
- You can also build a .pc package-config and manually install it using
pkg-config
to formalize the process
- Set
-
Modify the package.xml and CMakeLists.txt of your packages that require both OpenCV and cv_bridge
-
package.xml: replace all dependency of
cv_bridge
withcv_bridge_customize
-
CMakeLists.txt: replace
find_package(catkin REQUIRED COMPONENTS cv_bridge <other packages ...>)
withfind_package(catkin REQUIRED COMPONENTS cv_bridge_customize <other packages ...>)
-
-
Typically, the cv_bridge shipped with the official ROS Melodic depends on OpenCV 3.2.0, and the default version of libopencv-dev on Ubuntu 18.04 is 4.1.1
- On Xavier NX, the library .so files of these are mixed in the same directory:
/usr/lib/aarch64-linux-gun/
, the exact architecture varies depending on your platform, but can be referenced in cmake using${CMAKE_LIBRARY_ARCHITECTURE}
- On Xavier NX, the library .so files of these are mixed in the same directory:
-
When your package requires both libraries (cv_bridge and opencv), they will reference link libraries .so files at compile time and load them at runtime
- Using this cv_bridge_customize eliminates the compile-time warning, because now the OpenCV version depency is unified
- Installing OpenCV from source in a separate directory solves the runtime problems, because .so files with the same name under the same directory will all be loaded at runtime. You'll find that they are mostly symlinked. In the case of OpenCV, it's usually
libopencv_imgcodecs.so*
andlibopencv_imgproc.so*
. Locally built and installed OpenCV will have .so libraries in/usr/local/lib/
instead of/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/
, thus are quarantined from the mixed version OpenCV libs
-
So it's necessary to make sure that the dependencies and the package itself uses the same version of a library
- The low level data structure of these open source libraries may change across different releases
-
This repo is created from a clone of the noetic branch of vision_opencv. It changes the name in package.xml and CMakeLists.txt to make explicit distinction from the official package
- Feel free to upgrade this repo if you find new releases/modifications in the official repo.