Installed as a package (by git submodule). And set the environment variable OpenCV_DIR.
boost
1.74.0 (msvc-14.2-64)
Binary installation from sourceforge. And set the environment variable BOOST_ROOT.
Steps to reproduce issue
Create a python node using CvBridge
Build (colcon build)
Run
Expected behavior
Nodes using CvBridge work as expected.
Actual behavior
Nodes using CvBridge will exit with the following error.
ImportError: DLL load failed while importing cv_bridge_boost: The specified module could not be found.
Workaround
It need to add DLL paths explicitly.
Add the following snippet before importing CvBridge.
import platform
if platform.system() == 'Windows':
import os
from pathlib import Path
from ament_index_python.packages import get_package_prefix
dll_dir: Callable[[Path], Path] = lambda p: next(p.rglob('*.dll')).parent
for d in [
Path(os.environ.get('BOOST_ROOT')),
Path(os.environ.get('OPENCV_DIR')),
Path(get_package_prefix('cv_bridge')),
]:
os.add_dll_directory(dll_dir(d))
from cv_bridge import CvBridge, CvBridgeError
This is a workaround for cv_bridge_boost's ImportError with ROS2 on Windows (humble). I hope this helps anyone encountering the same error.
Environment
OpenCV_DIR
.BOOST_ROOT
.Steps to reproduce issue
Expected behavior
Nodes using CvBridge work as expected.
Actual behavior
Nodes using CvBridge will exit with the following error.
Workaround
It need to add DLL paths explicitly. Add the following snippet before importing CvBridge.