1.配置ROS_PACKAGE_PATH环境变量
source ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/user/ORB_SLAM2/Examples/ROS
否则会出错说找不到路径和包
2.进入ORB_SLAM2主路径编译ros节点:
chmod +x build_ros.sh
./build_ros.sh
确保原程序可以编译
可能出来如下问题:/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
- 出错原因为:libboost_system.so 与libboost_filesystem.so找不到链接目录
- 解决方案为
locate boost_system
//查找到目录
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
locate boost_filesystem
//查找到目录
/usr/lib/x86_64-linux-gnu/libboost_filesystem.a
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so
/usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.58.0
将libboost_system.so与libboost_filesystem.so复制到ORB_SLAM2/lib下,并且将ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中加入库目录,具体为
在set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
之后加入${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
3.打开一个终端,运行:roslaunch kinect2_bridge kinect2_bridge.launch
4.再打开另一个终端,输入:rostopic list查看此时Kinect2发布的topic,我用的是/kinect2/qhd/image_color_rect和/kinect2/qhd/image_depth_rect
5.找到源文件ros_rgbd.cc,按照上面的topic修改里面的ros订阅的内容
6.重新编译工程
./build_ros.sh
7.在~/ORB_SLAM2/Examples/ROS$ 目录下,运行
rosrun ORB_SLAM2 RGBD /home/user/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/user/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml
即可得到实时在线轨迹。
![](https://i-blog.csdnimg.cn/blog_migrate/dfe5d9ce02b6dda8b76dd52ff9cedb3b.png)
参考链接: