python3 cv_bridge以及tf使用问题

参考资料:

https://stackoverflow.com/questions/49221565/unable-to-use-cv-bridge-with-ros-kinetic-and-python3?rq=1
https://github.com/ros-perception/vision_opencv
https://github.com/ros/geometry
https://github.com/ros/geometry2

github上下载cv_bridge的源码

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

注意!!!下面是默认的环境

cd .. && catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
catkin config --install
catkin build cv_bridge
source install/setup.bash --extend

这里我使用的是conda的环境

# 修改后的方法
catkin config -DPYTHON_EXECUTABLE=/home/znfs/anaconda3/envs/detectron/bin/python3 -DPYTHON_INCLUDE_DIR=/home/znfs/anaconda3/envs/detectron/include/python3.6m -DPYTHON_LIBRARY=/home/znfs/anaconda3/envs/detectron/lib/libpython3.6m.so
catkin_make -DPYTHON_EXECUTABLE=/home/znfs/anaconda3/envs/detectron/bin/python3

Valid: 验证

from cv_bridge.boost.cv_bridge_boost import getCvType

需要将PYTHONPATH环境变量中,我们编译的这个cv_bridge的lib放到前面。

PYTHONPATH=/home/znfs/project_ws/dynamic_grasp/devel/lib/python3/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages:/home/znfs/project_ws/baxter/devel/lib/python2.7/dist-packages

Tips: 这里介绍一种方法在程序中重新设置环境变量,使用此方法可以将我们想要的环境置前

import os
# print(os.environ['PYTHONPATH'])
python_env = os.environ['PYTHONPATH'].split(':')
print('PYTHON_ENV change before:', python_env)
sort_pe = ':'.join(sorted(python_env, key=lambda k: 'python3' in k, reverse=True))
print('PYTHON_ENV change after:', sort_pe)
os.environ['PYTHONPATH']=sort_pe
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值