简体   繁体   English

使用 ROS Kinetic 和 Python3 构建 cv_bridge 包而忽略 Cmake 参数

[英]Building cv_bridge Package with ROS Kinetic and Python3 ignoring Cmake Arguments

I'm trying to integrate a ROS package into our system for a research project and the cv_bridge package and python3 is needed in order to get the package working.我正在尝试将 ROS 包集成到我们的研究项目系统中,并且需要 cv_bridge 包和 python3 才能使包正常工作。 Currently I can't get the cv_bridge package to build in python3 despite multiple steps, constantly builds in python2 directory.目前我无法在 python3 中构建 cv_bridge 包,尽管有多个步骤,但在 python2 目录中不断构建。

Working in Ubuntu 16.04 with ROS kinetic.使用 ROS kinetic 在 Ubuntu 16.04 中工作。 Using python3.5使用python3.5

Error Message:错误信息:

[ERROR] [1563897986.999724]: bad callback: <function color_callback at 0x7f00ffa06598>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
  File "/home/rival/Documents/Repos/ROS/src/rcnn_apple_detector/detection.py", line 84, in color_callback
image = bridge.imgmsg_to_cv2(image_msg, "bgr8")
  File "/home/rival/Documents/Repos/ROS/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 163, in imgmsg_to_cv2
dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
  File "/home/rival/Documents/Repos/ROS/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 99, in encoding_to_dtype_with_channels
return self.cvtype2_to_dtype_with_channels(self.encoding_to_cvtype2(encoding))
  File "/home/rival/Documents/Repos/ROS/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

I've tried the steps in this previous question's answer:我已经尝试了上一个问题答案中的步骤:

Unable to use cv_bridge with ROS Kinetic and Python3无法将 cv_bridge 与 ROS Kinetic 和 Python3 一起使用

"You are right, you should build cv_bridge with python3. “你说得对,你应该用python3构建cv_bridge。

You can do it with passing -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so args to cmake.您可以通过将 -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so args 传递给 cmake 来实现。 Or, if you are using catkin to build packages, you can do next steps:"或者,如果您使用 catkin 来构建软件包,则可以执行以下步骤:”

The only variations to the steps is I have to use catkin_make because issues with a bunch of older packages I'm using aren't currently working with catkin build.这些步骤的唯一变化是我必须使用 catkin_make,因为我正在使用的一堆较旧的软件包的问题目前不适用于 catkin build。 I don't know if that is causing it or not.不知道是不是这个原因。 But I pass the cmake arguments into my workspace and still it targets to the ROS python2 directory.但是我将 cmake 参数传递到我的工作区,它仍然指向 ROS python2 目录。

Location cv_bridge is currently still being built:位置 cv_bridge 目前仍在建设中:

/opt/ros/kinetic/lib/python2.7/dist-packages

Version:版本:

apt-cache show ros-kinetic-cv-bridge | grep Version
Version: 1.12.8-0xenial-20190320-142632-0800

catkin config:柳絮配置:

-------------------------------------------------------------------------------------------------------------------------------------------------
Profile:                     default
Extending:             [env] /home/rival/Documents/Repos/ROS/devel:/opt/ros/kinetic
Workspace:                   /home/rival/Documents/Repos/ROS
---------------------------------------------------------------------------------------------------------------------------------------------------
Build Space:        [exists] /home/rival/Documents/Repos/ROS/build
Devel Space:        [exists] /home/rival/Documents/Repos/ROS/devel
Install Space:     [missing] /home/rival/Documents/Repos/ROS/install
Log Space:         [missing] /home/rival/Documents/Repos/ROS/logs
Source Space:       [exists] /home/rival/Documents/Repos/ROS/src
DESTDIR:            [unused] None
---------------------------------------------------------------------------------------------------------------------------------------------------
Devel Space Layout:          linked
Install Space Layout:        merged
---------------------------------------------------------------------------------------------------------------------------------------------------
Additional CMake Args:       -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
---------------------------------------------------------------------------------------------------------------------------------------------------
Whitelisted Packages:        None
Blacklisted Packages:        None
---------------------------------------------------------------------------------------------------------------------------------------------------
Workspace configuration appears valid.

Exact steps taken:采取的具体步骤:

sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge

catkin clean

catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so

cd src/vision_opencv/
git checkout 1.12.8

catkin_make cv_bridge

source devel/setup.bash --extend

I expect cv_bridge to be built with the cmake arguments but it still gets targeted back into the python2 directory.我希望 cv_bridge 使用 cmake 参数构建,但它仍然被定位回 python2 目录。 It seems the cmake args are being ignored/not targeting correctly.似乎 cmake args 被忽略/没有正确定位。

I followed this blog post .我关注了这篇博文

Essentially you need to create new catkin workspace so that its configuration doesn't mess with your original (python2) workspace.本质上,您需要创建新的 catkin 工作区,以便其配置不会与原始 (python2) 工作区混淆。

  1. Install python3 and dependencies.安装 python3 和依赖项。 I like using --user without sudo to make resolving dependency conflicts a little easier.我喜欢使用不带 sudo 的--user来更轻松地解决依赖冲突。

     sudo apt-get install python-catkin-tools python3-dev python3-numpy sudo apt-get install python3-pip python3-yaml pip3 install rospkg catkin_pkg --user
  2. Make a new workspace新建一个工作区

    mkdir py3_catkin_ws cd py3_catkin_ws mkdir src
  3. Init catkin with python3 configured (use your python3x version)配置了 python3 的初始化 catkin(使用你的 python3x 版本)

     catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so catkin config --install
  4. Clone and catkin build vision_opencv in your new workspace. Clone 和catkin在您的新工作区中catkin build vision_opencv Continue as usual.照常继续。 Python3 should now be able to locate cv_bridge . Python3 现在应该能够找到cv_bridge The blog post suggests to source install/setup.bash --extend but it wasn't necessary in my case.博客文章建议source install/setup.bash --extend但在我的情况下没有必要。

I was having the same issue under ROS Melodic, Ubuntu 18.04 and using conda to separate the environments.我在 ROS Melodic、Ubuntu 18.04 和使用 conda 分离环境下遇到了同样的问题。 I started to get some strange errors, like NumPy not being found.我开始遇到一些奇怪的错误,比如没有找到 NumPy。 At this point it was too much of a hassle and a possible waste of time.在这一点上,这太麻烦了,而且可能浪费时间。

This was especially annoying as I could launch my ROS node using Python 3 and OpenCV worked perfectly well, only the transfer from ROS to CV was missing...这特别烦人,因为我可以使用 Python 3 启动我的 ROS 节点,而 OpenCV 运行得非常好,只是缺少从 ROS 到 CV 的传输......

I ended up just copying the lines from cv_brdige that did the translation to my package and made the translation without importing cv_bridge package.我最终只是将cv_brdige中进行翻译的行复制到我的包中,并在没有导入cv_bridge包的情况下进行了翻译。

As ROS is getting more Python 3 friendly , and packages will hopefully follow, this will not be an issue in the future.随着 ROS 对Python 3越来越友好,并且包有望随之而来,这在未来不会成为问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM