1.激活虚拟环境 source activate PointRCNNTest
2.python3中的opencv和ros自带的opencv版本冲突,屏蔽掉ros中的opencv路径。
def ImageRecevierCallback(data):
ros_cv2_path = '/opt/ros/kinetic/lib/python2.7/dist-packages'
from cv_bridge import CvBridge
if ros_cv2_path in sys.path: sys.path.remove(ros_cv2_path)
import cv2
bridge = CvBridge()
img = bridge.imgmsg_to_cv2(data, 'bgr8')
cv2.imshow('HKVISION',img)
cv2.waitKey(3)
return 0
这样可以临时只使用anaconda中的opencv。
3.使用cv_bridge如果出现ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost),则按照下面步骤对cv_bridge进行重新编译,原因在于Ros自带python2的版本,需要编译成python3的版本。
(1)sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge
(2)mkdir catkin_workspace
(3)cd catkin_workspace
(4)catkin init
(5)虚拟环境的python换成自己对应的版本。
catkin config -DPYTHON_EXECUTABLE=/home/yokybank/anaconda3/envs/PointRCNNTest/bin/python -DPYTHON_INCLUDE_DIR=/home/yokybank/anaconda3/envs/PointRCNNTest/include/python3.6m -DPYTHON_LIBRARY=/home/yokybank/anaconda3/envs/PointRCNNTest/lib/libpython3.6m.so
(6)catkin config --install
(7)git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
(8)catkin build cv_bridge
(9)source devel/setup.bash
或者写入.bashrc里面source /home/yokybank/catkin_workspace/devel/setup.bash
(10)编译过程中如果遇到:
将src/vision_opencv/cv_bridge/CMakeLists.txt的
find_package(Boost REQUIRED python3)改为
find_package(Boost REQUIRED python-py35)
(11)如果遇到以下问题,可以不用管,此时在devel下已经生成了python3版本的cv_bridge