1.进入conda虚拟环境后,安装相关包
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/wei/miniconda3/envs/py39/bin/python3.9
cd ..
export CPLUS_INCLUDE_PATH=/home/wei/miniconda3/envs/py39/include/python3.9
catkin_make install -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF -DPYTHON_EXECUTABLE=/home/wei/miniconda3/envs/py39/bin/python3.9
出现error:
然后:
vim /home/wei/ros_cv_bridge/src/vision_opencv/cv_bridge/src/module.hpp
,将最后一段(36~40)行:
改成:
删掉原来编译的文件,然后重新编译:
sudo rm -rf build/ devel/
catkin_make install -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF -DPYTHON_EXECUTABLE=/home/wei/miniconda3/envs/py39/bin/python3.9
继续报错:
然后:
vim /home/wei/miniconda3/envs/py39/lib/python3.9/site-packages/numpy/core/include/numpy/__multiarray_api.h
定位到出现问题那行,将结尾的return null;删掉保存,继续重新编译。
删掉原来编译的文件,然后重新编译:
sudo rm -rf build/ devel/
catkin_make install -DCMAKE_BUILD_TYPE=Release -DSETUPTOOLS_DEB_LAYOUT=OFF -DPYTHON_EXECUTABLE=/home/wei/miniconda3/envs/py39/bin/python3.9
成功!
参考链接:
https://www.guyuehome.com/37834
https://blog.csdn.net/shoukequ8359/article/details/120782739