ubuntu16.04跑orbslam2数据集及在kinetic下实时获取轨迹

ubuntu系统崩了,在老师的要求下,再次搭建orbslam平台

环境:ubuntu16.04,     ros版本  kinetic   ,相机  kinect2

假设此时安装好kinect2驱动能获取图像,opencv,eigen,pangolin已安装好(我的是opencv3.2,eigen至少3.1版本)

以上环境若没有准备好,自行百度,网上很多教程

准备工作

orbslam2可以在非ROS环境下运行,也可以在ROS运行,鉴于后面要用kinect2跑实时在线的数据,所以把orbslam2程序放在ros工作空间,工作空间名注意换成自己的

1  建立ros工作空间

mkdir -p ~/orbslam2/src
cd ~/orbslam2/src
catkin_init_workspace
cd ~/orbslam2/
catkin_make

ros空间建立若报错自行百度谷歌

2 下载orbslam2程序

在orbslam2/src文件夹下,运行:

git clone http://github.com/raulmur/ORB_SLAM2.git

1  跑RGBD数据集

1.1  下载rgbd数据集

下载数据集,http://vision.in.tum.de/data/datasets/rgbd-dataset/download

将数据集提取放在Examples/RGBD文件夹下面

1.2  生成association.txt文件

在src/ORB-SLAM2/Examples/RGB-D目录下,运行

python associate.py PATH_TO_SEQUENCE/rgb.txt PATH_TO_SEQUENCE/depth.txt > associations.txt

若出现以下错误:

解决办法:下载associate.py脚本至RGB-D,https://vision.in.tum.de/data/datasets/rgbd-dataset/tools

并运行

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2/Examples/RGB-D$ touch associate.py

生成associations.txt文件,运行

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2/Examples/RGB-D$ python associate.py rgbd_dataset_freiburg1_xyz/rgb.txt rgbd_dataset_freiburg1_xyz/depth.txt > associations.txt

1.3 跑数据集

在RGB-D目录下运行,此处注意要改为你自己的路径

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUMX.yaml PATH_TO_SEQUENCE_FOLDER ASSOCIATIONS_FILE

我的为:

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2$ ./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml Examples/RGB-D/rgbd_dataset_freiburg1_xyz Examples/RGB-D/associations.txt

单目双目跑数据集详见官方文档

2 在ros下实时在线跑自己的数据

2.1 为确保源程序顺利编译,进行如下步骤:

source ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/xiaochezu/src/ORB_SLAM2/Examples/ROS
上面这个一定要做,否则会出错说找不到路径和包
之后在src/ORB_SLAM2目录下:
chmod +x build_ros.sh 
./build_ros.sh
编译过程中遇到的错误及解决办法

在ORB—SLAM2所在目录下:

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2$ chmod +x build_ros.sh
xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2$ ./build_ros.sh

若出现如下错误:

/usr/bin/ld: CMakeFiles/RGBD.dir/src/ros_rgbd.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/RGBD.dir/build.make:215: recipe for target '../RGBD' failed
make[2]: *** [../RGBD] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
/usr/bin/ld: CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:215: recipe for target '../Stereo' failed
make[2]: *** [../Stereo] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
[ 55%] Built target Mono
[ 77%] Built target MonoAR
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

出错原因为:libboost_system.so 与libboost_filesystem.so找不到链接目

解决方案:

xiaochezu@xiaochezu:~$ 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
xiaochezu@xiaochezu:~$ 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、libboost_system.so.1.58.0、libboost_filesystem.so.1.58.0复制到ROS/ORB_SLAM2/lib下,并且将ORBSLAM2/Examples/ROS/ORBSLAM2下的Cmakelists.txt中加入库目录,具体为

${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}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system

重新运行这一步。

2.2 开启kinect2

打开一个终端,运行:

roslaunch kinect2_bridge kinect2_bridge.launch

2.3 查看此时Kinect2发布的topic

打开另一个终端,运行

rostopic list

2.4 根据上一步发布的topic,更改ros里面订阅的内容

将ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc的内容更改为

message_filters::Subscriber rgb_sub(nh, "/kinect2/qhd/image_color_rect", 1);  
  message_filters::Subscriber depth_sub(nh, "/kinect2/qhd/image_depth_rect", 1); 

2.5 重新编译工程

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2$ chmod +x build_ros.sh
xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2$ ./build_ros.sh

查看话题链接  输入:   rqt_graph

2.6  运行,此处注意改为自己的路径

rosrun ORB_SLAM2 RGBD /home/xiaochezu/orbslam2/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/xiaochezu/orbslam2/src/ORB_SLAM2/Examples/RGB_D/kinect2_qhd.yaml

我踩的坑,刚开始运行的是以下,然后报错

xiaochezu@xiaochezu:~/orbslam2/src/ORB_SLAM2/Examples/ROS$ rosrun ORB_SLAM2 RGBD /home/xiaochezu/orbslam2/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/xiaochezu/orbslam2/src/ORB_SLAM2/Examples/RGB_D/TUM1.yaml

ORB-SLAM2 Copyright (C) 2014-2016 Raul Mur-Artal, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.

Input sensor was set to: RGB-D
Failed to open settings file at: /home/xiaochezu/orbslam2/src/ORB_SLAM2/Examples/RGB_D/TUM1.yaml

 解决办法:在Example/RGB-D目录下,重新写一个类似TUM.yaml的文件,命名为kinect2_qhd.yaml,运行

rosrun ORB_SLAM2 RGBD /home/xiaochezu/orbslam/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/xiaochezu/orbslam/src/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml

成功

kinect2_qhd.yaml为自己的kinect2的参数的文件夹,所以在运行这个程序之前最好做好kinect2的标定工作

第一次写一个完整的实验记录,有不完善的地方请指正

你可能感兴趣的:(SLAM,orbslam,ubuntu16.04,ros,kinectic)