ROS2之OpenCV的windows和linux差异在哪里

Posted zhangrelay

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ROS2之OpenCV的windows和linux差异在哪里相关的知识,希望对你有一定的参考价值。

本质上并没有差异,但是环境配置上有很多小区别。


如果是python程序通常可以直接使用的。

但是如何是C++,则有可能出现编译不通过的情况。

案例如下:

windows出错

C:\\ros_ws\\opencv_cam>colcon build --event-handlers console_cohesion+
[2.135s] root DEBUG Using proactor: IocpProactor
Starting >>> ros2_shared
--- output: ros2_shared
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22616.
-- Found ament_cmake: 0.9.8 (C:/opt/ros/foxy/x64/share/ament_cmake/cmake)
-- Using PYTHON_EXECUTABLE: C:/opt/ros/foxy/x64/python.exe
-- Configuring done
-- Generating done
-- Build files have been written to: C:/ros_ws/opencv_cam/build/ros2_shared
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.9.0+5e4b48a27
版权所有(C) Microsoft Corporation。保留所有权利。

  Checking Build System
  Building Custom Rule C:/ros_ws/opencv_cam/src/ros2_shared/CMakeLists.txt
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/include
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/include/ros2_shared
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/include/ros2_shared/context_macros.hpp
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/include/ros2_shared/param_macros.hpp
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/include/ros2_shared/string_printf.hpp
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ament_index/resource_index/package_run_dependencies/ros2_shared
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ament_index/resource_index/parent_prefix_path/ros2_shared
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/environment/ament_prefix_path.bat
-- Installing: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/environment/ament_prefix_path.dsv
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/environment/path.bat
-- Installing: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/environment/path.dsv
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/local_setup.bat
-- Installing: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/local_setup.dsv
-- Installing: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/package.dsv
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ament_index/resource_index/packages/ros2_shared
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/cmake/ament_cmake_export_include_directories-extras.cmake
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/cmake/ros2_sharedConfig.cmake
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/cmake/ros2_sharedConfig-version.cmake
-- Up-to-date: C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/package.xml
---
Finished <<< ros2_shared [6.11s]
Starting >>> opencv_cam
--- output: opencv_cam
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.22616.
-- Found OpenCV version 4.3.0
-- Found ament_cmake: 0.9.8 (C:/opt/ros/foxy/x64/share/ament_cmake/cmake)
-- Using PYTHON_EXECUTABLE: C:/opt/ros/foxy/x64/python.exe
-- Found camera_calibration_parsers: 2.3.0 (C:/opt/ros/foxy/x64/share/camera_calibration_parsers/cmake)
-- Using all available rosidl_typesupport_c: rosidl_typesupport_fastrtps_c;rosidl_typesupport_introspection_c
-- Found rosidl_adapter: 1.2.0 (C:/opt/ros/foxy/x64/share/rosidl_adapter/cmake)
-- Using all available rosidl_typesupport_cpp: rosidl_typesupport_fastrtps_cpp;rosidl_typesupport_introspection_cpp
-- Found rmw_implementation_cmake: 1.0.2 (C:/opt/ros/foxy/x64/share/rmw_implementation_cmake/cmake)
-- Using RMW implementation 'rmw_fastrtps_cpp' as default
-- Found class_loader: 2.0.1 (C:/opt/ros/foxy/x64/share/class_loader/cmake)
-- Found rclcpp_components: 2.3.0 (C:/opt/ros/foxy/x64/share/rclcpp_components/cmake)
-- Found ros2_shared: 0.1.0 (C:/ros_ws/opencv_cam/install/ros2_shared/share/ros2_shared/cmake)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/ros_ws/opencv_cam/build/opencv_cam
用于 .NET Framework 的 Microsoft (R) 生成引擎版本 16.9.0+5e4b48a27
版权所有(C) Microsoft Corporation。保留所有权利。

  Checking Build System
  Building Custom Rule C:/ros_ws/opencv_cam/src/opencv_cam/CMakeLists.txt
  opencv_cam_node.vcxproj -> C:\\ros_ws\\opencv_cam\\build\\opencv_cam\\Release\\opencv_cam_node.dll
  Building Custom Rule C:/ros_ws/opencv_cam/src/opencv_cam/CMakeLists.txt
  subscriber_node.vcxproj -> C:\\ros_ws\\opencv_cam\\build\\opencv_cam\\Release\\subscriber_node.dll
  Building Custom Rule C:/ros_ws/opencv_cam/src/opencv_cam/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\\opencv_cam_node.lib' [C:\\ros_ws\\opencv_cam\\build\\opencv_cam\\ipc_test_main.vcxproj]
  Building Custom Rule C:/ros_ws/opencv_cam/src/opencv_cam/CMakeLists.txt
LINK : fatal error LNK1181: cannot open input file 'Release\\opencv_cam_node.lib' [C:\\ros_ws\\opencv_cam\\build\\opencv_cam\\opencv_cam_main.vcxproj]
---
Failed   <<< opencv_cam [8.31s, exited with code 1]

Summary: 1 package finished [14.8s]
  1 package failed: opencv_cam

linux正常:

colcon build
Starting >>> ros2_shared
-- Install configuration: ""
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/include
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/include/ros2_shared
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/include/ros2_shared/param_macros.hpp
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/include/ros2_shared/string_printf.hpp
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/include/ros2_shared/context_macros.hpp
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ament_index/resource_index/package_run_dependencies/ros2_shared
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ament_index/resource_index/parent_prefix_path/ros2_shared
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/environment/ament_prefix_path.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/environment/ament_prefix_path.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/environment/path.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/environment/path.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/local_setup.bash
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/local_setup.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/local_setup.zsh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/local_setup.dsv
-- Installing: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/package.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ament_index/resource_index/packages/ros2_shared
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/cmake/ament_cmake_export_include_directories-extras.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/cmake/ros2_sharedConfig.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/cmake/ros2_sharedConfig-version.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/ros2_shared/share/ros2_shared/package.xml
Finished <<< ros2_shared [0.14s]
Starting >>> opencv_cam
[ 50%] Built target opencv_cam_node
[ 50%] Built target subscriber_node
[100%] Built target ipc_test_main
[100%] Built target opencv_cam_main
-- Install configuration: ""
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/library_path.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/library_path.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/ament_index/resource_index/package_run_dependencies/opencv_cam
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/ament_index/resource_index/parent_prefix_path/opencv_cam
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/ament_prefix_path.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/ament_prefix_path.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/path.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/environment/path.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/local_setup.bash
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/local_setup.sh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/local_setup.zsh
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/local_setup.dsv
-- Installing: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/package.dsv
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/ament_index/resource_index/packages/opencv_cam
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/ament_index/resource_index/rclcpp_components/opencv_cam
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/export_opencv_cam_nodeExport.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/export_opencv_cam_nodeExport-noconfig.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/export_subscriber_nodeExport.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/export_subscriber_nodeExport-noconfig.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/ament_cmake_export_dependencies-extras.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/ament_cmake_export_include_directories-extras.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/ament_cmake_export_targets-extras.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/ament_cmake_export_libraries-extras.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/opencv_camConfig.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/cmake/opencv_camConfig-version.cmake
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/package.xml
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/lib/libopencv_cam_node.so
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/lib/libsubscriber_node.so
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/lib/opencv_cam/opencv_cam_main
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/lib/opencv_cam/ipc_test_main
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/launch
-- Up-to-date: /home/zhangrelay/ros_ws/opencv_camc/install/opencv_cam/share/opencv_cam/launch/composition_launch.py
Finished <<< opencv_cam [0.29s]

如何解决这类报错,后续更新。

一个提示:

ROS2 is comfortably using Python3, so let that alleviate your concerns.

The error you see wnen using rosdep install is just rosdep telling you that it doesn't know what "opencv2" is for your given OS and so it can't install something that satisfies the requirement listed in the package.xml of your cv_basics pacakge. As for resolutions, I'll refer you to question #232795 which does a good job of explaining how rosdep works and what you can do next.

If you've installed OpenCV2 yourself and have confirmed that the version you've installed matches the version expected by whichever package has the dependency, then you should be okay to ignore the error. You can ignore errors when by adding -r to your rosdep call. This allows rosdep to continue installing dependencies, despite errors.

If you'd rather fix the error, then you probably want to change "opencv2" in your package.xml to "opencv-python" so that rosdep can find it. opencv-python points to OpenCV 4.5.3.56 so it should be what you're looking for.

 

ROS2 可以轻松地使用 Python3,因此可以减轻顾虑。

使用 rosdep install 看到 wnen 的错误只是 rosdep 告诉它不知道给定操作系统的“opencv2”是什么,因此它无法安装满足 cv_basics pacakge 的 package.xml 中列出的要求的东西.至于解决方案,建议参考问题#232795,该问题很好地解释了 rosdep 的工作原理以及您接下来可以做什么。

如果自己安装了 OpenCV2 并确认您安装的版本与任何具有依赖项的软件包所期望的版本相匹配,那么应该可以忽略该错误。通过在 rosdep 调用中添加 -r 可以忽略错误。这允许 rosdep 继续安装依赖项,尽管出现错误。

如果想修复错误,那么可能希望将 package.xml 中的“opencv2”更改为“opencv-python”,以便 rosdep 可以找到它。 opencv-python 指向 OpenCV 4.5.3.56 所以它应该是要找的。


以上是关于ROS2之OpenCV的windows和linux差异在哪里的主要内容,如果未能解决你的问题,请参考以下文章

ROS2+Gazebo+OpenCV之mobot仿真视觉传感器

ROS2之OpenCV的微笑入门资料篇

ROS2之OpenCV怎么理解一段代码

ROS2之OpenCV基础代码对比foxy~galactic~humble

ROS2+Gazebo11+Car+OpenCV巡线识别和速度转向控制学习

ROS2 在 Windows 上功能齐全吗?