网上很多教程都说ros+python3不行,是要建立虚拟空间。但在我这里没什么效果,和不建立虚拟空间报错一样。
[ERROR] [1543892418.353969]: bad callback: >
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/qinhaidong/imagetest/src/subscribe/src/subscribe.py", line 27, in callback
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
File "/opt/ros/kinetic/lib/python2.7/dist-packages/cv_bridge/core.py", line 163, in imgmsg_to_cv2
dtype, n_channels = self.encoding_to_dtype_with_channels(img_msg.encoding)
File "/opt/ros/kinetic/lib/python2.7/dist-packages/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 "/opt/ros/kinetic/lib/python2.7/dist-packages/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)
重点就是这里出问题:
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)
在网上找到一个办法(不需要建立虚拟空间,虚拟空间没什么用)
https://stackoverflow.com/questions/49221565/unable-to-use-cv-bridge-with-ros-kinetic-and-python3
但是他是用catkin build,而且只有在自己建立的workspace里才能打开Python3运行
from cv_bridge.boost.cv_bridge_boost import getCvType
不报错。
所以这里
我们把src文件夹下除了图像发布和接收共2个文件夹外在加一个上面用到过的文件夹vision_opencv,
然后删除掉之前的build,devel文件夹,进行catkin_make(代替了之前的catkin build操作)
这样,就在我们的工作空间里,实现了Python3.5+ros+opencv成功完成了图像发布和接收。