Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FYI] A workaound for cv_bridge_boost's ImportError on Windows #537

Open
sgr-aoba opened this issue Oct 26, 2024 · 1 comment
Open

[FYI] A workaound for cv_bridge_boost's ImportError on Windows #537

sgr-aoba opened this issue Oct 26, 2024 · 1 comment

Comments

@sgr-aoba
Copy link

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

Component Version
Operating System Windows 10 22H2
ROS2 Release Humble Binary installation by following the guide.
vision_opencv Humble branch 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
@sgr-aoba
Copy link
Author

Related issues: #247, ms-iot/ROSOnWindows#371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant