ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

前言

我的环境是ubuntu18.04+ros-melodic+python3.8
以下是使用过程的代码:

bridge = CvBridge()
img = bridge.imgmsg_to_cv2(img_msg)

会出现下面错误,产生错误原因无非是ros对python3的兼容性不友好。

File "/opt/ros/melodic/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)

解决办法

以下是我的解决方法(亲测有效):

sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge
# Create catkin workspace
mkdir catkin_ws
cd catkin_ws
catkin init
# Instruct catkin to set cmake variables
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/aarch64-linux-gnu/libpython3.6m.so
# Instruct catkin to install built packages into install place. It is $CATKIN_WORKSPACE/install folder
catkin config --install
# Clone cv_bridge src
git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
# Find version of cv_bridge in your repository
apt-cache show ros-melodic-cv-bridge | grep Version
# Version: 1.13.0-0bionic.20220127.152918
cd src/vision_opencv/
git checkout 1.13.0
cd ../../
# Build
# catkin clean --yes
catkin build cv_bridge
# Extend environment with new package
source install/setup.bash --extend

其他解决方法,有人推荐用numpy/ros_numpy代替cv_bridge去实现,大家也可以去尝试下。

import numpy as np
img = np.frombuffer(image_data.data, dtype=np.uint8).reshape(image_data.height, image_data.width, -1)
# Beautiful solution is to use ros_numpy. It is similar to the function of cv_bridge, but without the dependency on cv2:
import ros_numpy
np_img = ros_numpy.numpify(ros_img_msg)
  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ywfwyht

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值