ros中python3与cv_bridge问题

ROS——在Ubuntu18.04下基于ROS Melodic编译python3的cv_bridge

环境

  • Ubuntu18.04
  • python3.6.13
  • ROS Melodic
  • nvidia xavier

1.安装环境

sudo apt-get install  python3-dev python3-numpy python3-yaml ros-melodic-cv-bridge python3-rospkg-modules
pip3 install pip --update
pip3 install rosdep rosinstall catkin_pkg

2.基于python3环境编译cv_bridge
(1)初始化cv_bridge_ws编译工作空间

mkdir -p cv_bridge_ws/src && cd cv_bridge_ws/src
catkin_init_workspace

(2)将cv_bridge源码拉取到本地

git clone https://github.com/ros-perception/vision_opencv.git

(3)编译cv_bridge

cd ../
catkin_make install -DPYTHON_EXECUTABLE=/usr/bin/python3

编译报错解决
问题1:

 解决方法:
1. 查看你的libbost_python*文件(我这里的arm的ubuntu,如果你的是x86,就在/usr/lib/x86-64-linux-gnu这个文件夹)

cd /usr/lib/aarch64-linux-gnu/
ls libboost_python*

2. 进入报错文件vision_opencv/cv_bridge/CMakeLists.txt,将11行的python37改成python3,然后重新编译即可。


(4)编译成功

 

 


(5)将编译生成的文件加入环境变量
使我们在使用python3时可以,默认调用:(这里一定要改成自己的编译后的路径!!)

source /home/nvidia/AGV/cv_bridge_ws/install/setup.bash --extend

将其添加至.bashrc文件的最后一行

(6)测试
重新打开一个终端:运行python3

import cv_bridge
from cv_bridge.boost.cv_bridge_boost import getCvType

 如果报错,记得source

source /home/nvidia/AGV/cv_bridge_ws/install/setup.bash --extend

都import成功说明已经成功编译了基于python3的cv_bridge,现在就可以直接在ROS中编写python3的代码即可,节点会自动调用对应python版本的cv_bridge!
--------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------------------------

上述过程可以通过python+文件名运行节点,但是通过rosrun报错

source ./devel/setup.bash && rosrun image_processing image_process.py
python src/image_processing/scripts/image_process.py

你可能感兴趣的:(ROS,自动驾驶,ubuntu,人工智能)