(1)创建conda环境
conda create -n ros python=3.6 conda activate ros pip install --upgrade pip pip install rosdep rosinstall catkin_pkg rospkg numpy pyyaml opencv-python
(2)初始化工作空间并获取vision_opencv
mkdir -p ros_cv_bridge/src && cd ros_cv_bridge/src catkin_init_workspace git clone https://gitee.com/irvingao/vision_opencv.git
(3)编译cv_bridge
这里的python解释器选择conda的python路径,如果不知道可以用下面的指令查询一下:
whereis python
我的python解析器路径为:/home/sjh/anaconda3/envs/omron_grasp/bin/python3.6
将下边命令中的解释器路径改为你的路径:
cd ../ export CPLUS_INCLUDE_PATH=/home/sjh/anaconda3/envs/omron_grasp/bin/python3.6m catkin_make install -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF -DPYTHON_EXECUTABLE=/home/sjh/anaconda3/envs/omron_grasp/bin/python3.6
编译成功:
(4)将编译生成的文件加入环境变量
sudo gedit ~/.bashrc
在最后添加:
source ~/ros_cv_bridge/install/setup.bash --extend
退出,然后source一下:
source ~/.bashrc
(5)测试
检查是否安装成功:
python import cv_bridge from cv_bridge.boost.cv_bridge_boost import getCvType
如果出现报错,请参考此链接:https://blog.csdn.net/qq_45779334/article/details/124421639