个人博客:http://www.chenjianqu.com/
原文链接:http://www.chenjianqu.com/show-99.html
前几天一直再装RGBD-SLAM2,死活装不上,于是转移目标,安装ORB-SLAM2。ORB-SLAM是非常经典的一个SLAM系统,本文记录其在Ubuntu16.04上的编译安装过程。
源码下载
ORB-SLAM2下载:
git clone https://github.com/raulmur/ORB_SLAM2.git
依赖安装
一、OpenCV3编译安装
参阅
二、Pangolin编译安装
过程如下,若缺少依赖则按照进行https://github.com/stevenlovegrove/Pangolin安装。
git clone https://github.com/stevenlovegrove/Pangolin.git cd Pangolin mkdir build cd build cmake .. make -j4 sudo make install
三、DBow2编译
DBow2的源码已经在ORB-SLAM2的Thirdparty目录下了,编译即可,无需安装。
d Thirdparty/DBoW2 mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j4
四、g2o编译
同DBoW2。
编译ORB-SLAM2
在ORB-SLAM2源码目录下:
mkdir build cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j4
不会这么顺利的,报错了:
报错 1
ws/ORB_SLAM2/src/LoopClosing.cc: In member function ‘void ORB_SLAM2::LoopClosing::Run()’: /ws/ORB_SLAM2/src/LoopClosing.cc:84:20: error: ‘usleep’ was not declared in this scope usleep(5000); ^ /ws/ORB_SLAM2/src/LocalMapping.cc: In member function ‘void ORB_SLAM2::LocalMapping::Run()’: /ws/ORB_SLAM2/src/LocalMapping.cc:94:28: error: ‘usleep’ was not declared in this scope usleep(3000); ^ /ws/ORB_SLAM2/src/LocalMapping.cc:108:20: error: ‘usleep’ was not declared in this scope usleep(3000);
解决:打开相应的代码(大多数.cc文件),在头文件里面添加usleep 的头文件unistd.h。
重新make -j4后我就编译完成了。
接下来编译ORB-SLAM的ROS工程,首先将该工程添加至ROS_PACKAGE_PATH,即:
sudo gedit ~/.bashrc #在最后一行输入 export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:(ORB_SLAM的存放目录)/ORB_SLAM2/Examples/ROS #完了后刷新bash: source ~/.bashrc
然后打开该工程,进行cmake:
mkdir build cd build cmake .. -DROS_BUILD_TYPE=Release
果然报错了。
报错 2
[rosbuild] Building package ORB_SLAM2 [rosbuild] Error from directory check: /opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py /home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2 1 Traceback (most recent call last): File "/opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py", line 46, inraise Exception Exception CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/private.cmake:102 (message): [rosbuild] rospack found package "ORB_SLAM2" at "", but the current directory is "/home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2". You should double-check your ROS_PACKAGE_PATH to ensure that packages are found in the correct precedence order. Call Stack (most recent call first): /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:177 (_rosbuild_check_package_location) CMakeLists.txt:4 (rosbuild_init) -- Configuring incomplete, errors occurred! See also "/home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/CMakeFiles/CMakeOutput.log".
解决:报错说是没找到该路径,可我明明已经。。。于是换一种方法,在ros默认的目录下建立软链接:
sudo ln -s /home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2 /opt/ros/kinetic/share/ORB_SLAM2
再次进行cmake .. -DROS_BUILD_TYPE=Release,成功!
接下来编译这个ros项目:
make -j4
怎么又报错了。。。
报错 3
/home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc: In member function ‘void ORB_SLAM2::ViewerAR::Run()’: /home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc:233:9: error: ‘usleep’ was not declared in this scope usleep(mT*1000); ^~~~~~ /home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc:233:9: note: suggested alternative: ‘fseek’ usleep(mT*1000); ^~~~~~ fseek [ 77%] Linking CXX executable ../RGBD [ 88%] Linking CXX executable ../Stereo
解决:fuck,原来是前面出现过的问题,在/home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc添加unistd.h头文件即可。
好的,再来:
make -j4
报错 4
[ 77%] Built target MonoAR /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: 无法添加符号: DSO missing from command line collect2: error: ld returned 1 exit status CMakeFiles/RGBD.dir/build.make:219: 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: 无法添加符号: DSO missing from command line collect2: error: ld returned 1 exit status CMakeFiles/Stereo.dir/build.make:219: 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 Makefile:127: recipe for target 'all' failed make: *** [all] Error 2
解决:报错的原因是libboost_system未被包含。因此修改该ROS工程的CMakelists.txt,在${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so的下一行添加 -lboost_system ,即可得到解决。
再来!
make -j4
成功编译!!!!!!
运行ORB-SLAM2
编译完成后,添加该工程的setup.bash路径到.bashrc文件并刷新:
sudo gedit ~/.bashrc #输入source /home/chen/slam/orbslam/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/devel/setup.bash #然后刷新一下: source ~/.bashrc
启动ORBSLAM的单目SLAM需要两个参数:
PATH_TO_VOCABULARY,回环检测的字典文件,在ORB_SLAM2/Vocabulary目录下,将其解压即可
PATH_TO_SETTINGS_FILE,相机参数设置文件,需要对camera进行标定,或者使用ORB_SLAM2/Examples/ROS/ORB_SLAM2中已有的参数文件Asus.yaml
启动ORB-SLAM后,播放数据集rgbd_dataset_freiburg1_desk.bag(下载地址:https://vision.in.tum.de/data/datasets/rgbd-dataset/download),命令如下:
#启动ros roscore #启动ORB_SLAM2 rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/Asus.yaml #播放数据集,ORB-SLAM默认订阅的话题为/camera/image_raw,因此进行映射 rosbag play /media/chen/我的文档/Linux系统备份/数据集/rgbd_dataset_freiburg1_desk.bag /camera/rgb/image_color:=/camera/image_raw
成功~~~~ 我飘了,这可比RGBDSLAM-V2简单多了。。。
ORBSLAM在rgbd_dataset_freiburg1_desk.bag这个数据集的运行效果如下:
ORB-SLAM2还提供了AR功能,运行:
roscore rosrun ORB_SLAM2 MonoAR Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/Asus.yaml rosbag play /media/chen/我的文档/Linux系统备份/数据集/rgbd_dataset_freiburg1_desk.bag /camera/rgb/image_color:=/camera/image_raw
效果:
在平面上放置Cube。