Building cv_bridge Package with ROS Kinetic and Python3 ignoring Cmake Arguments

。_饼干妹妹 提交于 2021-01-27 18:17:52

问题


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. Currently I can't get the cv_bridge package to build in python3 despite multiple steps, constantly builds in python2 directory.

Working in Ubuntu 16.04 with ROS kinetic. Using 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

"You are right, you should build cv_bridge with python3.

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. Or, if you are using catkin to build packages, you can do next steps:"

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. 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.

Location cv_bridge is currently still being built:

/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. It seems the cmake args are being ignored/not targeting correctly.


回答1:


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.

  1. Install python3 and dependencies. I like using --user without sudo to make resolving dependency conflicts a little easier.

    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)

    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. Continue as usual. Python3 should now be able to locate cv_bridge. The blog post suggests to source install/setup.bash --extend but it wasn't necessary in my case.




回答2:


I was having the same issue under ROS Melodic, Ubuntu 18.04 and using conda to separate the environments. I started to get some strange errors, like NumPy not being found. 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...

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.

As ROS is getting more Python 3 friendly, and packages will hopefully follow, this will not be an issue in the future.



来源:https://stackoverflow.com/questions/57168989/building-cv-bridge-package-with-ros-kinetic-and-python3-ignoring-cmake-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!