这两天把论文:ORB-SLAM: a Versatile and Accurate Monocular SLAM System中提供的代码跑了下.
出于赠人玫瑰,手有余香的理念,现在把运行的详细过程分享下:
1. 创建ROS工作空间
zhuquan@zhuquan-Precision-5510:~$ mkdir -p ~/orbslam_catkin_ws/src
zhuquan@zhuquan-Precision-5510:~$ cd ~/orbslam_catkin_ws/src
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src$ catkin_init_workspace
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ catkin_make
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
运行以下命令确认你的当前目录是否在环境变量中
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ echo $ROS_PACKAGE_PATH
如果终端输出
/home/zhuquan/orbslam_catkin_ws/src:/opt/ros/indigo/share:/opt/ros/indigo/stacks
则说明ROS工作空间已经搭建好了。
2. Prerequisites (dependencies)
2.1 Boost
We use the Boost library to launch the different threads of our SLAM system.
sudo apt-get install libboost-all-dev
2.2 ROS
We use ROS to receive images from the camera or from a recorded sequence (rosbag), and for visualization (rviz, image_view).
**We have tested ORB-SLAM in Ubuntu 12.04 with ROS Fuerte, Groovy and Hydro; and in Ubuntu 14.04 with ROS Indigo**.
If you do not have already installed ROS in your computer, we recommend you to install the Full-Desktop version of ROS Fuerte (http://wiki.ros.org/fuerte/Installation/Ubuntu).
2.3 OpenCV
We use OpenCV to manipulate images and features. If you use a ROS version older than ROS Indigo, OpenCV is already included in the ROS distribution. In newer version of ROS, OpenCV is not included and you will need to install it. **We tested OpenCV 2.4**. Dowload and install instructions can be found at: http://opencv.org/
2.4 g2o (included in Thirdparty)
We use a modified version of g2o (see original at https://github.com/RainerKuemmerle/g2o) to perform optimizations.
In order to compile g2o you will need to have installed Eigen3 (at least 3.1.0).
sudo apt-get install libeigen3-dev
2.5 DBoW2 (included in Thirdparty)
We make use of some components of the DBoW2 and DLib library (see original at https://github.com/dorian3d/DBoW2) for place recognition and feature matching. There are no additional dependencies to compile DBoW2.
另外blas和lapack安装如下:
sudo apt-get install libblas-dev liblapack-dev
其中,opencv已安装,安装的是2.4.13版的。
3.Installation
3.1 Clone the repository
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src$ git clone https://github.com/raulmur/ORB_SLAM.git ORB_SLAM
3.2 Add the path where you cloned ORB-SLAM to the `ROS_PACKAGE_PATH` environment variable.
To do this, modify your .bashrc (在/home/yourusername/下,按下Ctrl+h复合键就可以见到) and add at the bottom the following line (replace PATH_TO_PARENT_OF_ORB_SLAM):
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH_TO_PARENT_OF_ORB_SLAM
例如:
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/zhuquan/orbslam_catkin_ws/src/
3.3 Build g2o.
Go into `Thirdparty/g2o/` and execute:
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src$ cd ORB_SLAM/Thirdparty/g2o
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o$ mkdir build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o$ cd build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o/build$ cmake .. -DCMAKE_BUILD_TYPE=Release
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o/build$ make
3.4 Build DBoW2.
Go into Thirdparty/DBoW2/ and execute:
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o/build$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/g2o$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty$ cd DBoW2/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2$ mkdir build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2$ cd build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2/build$ cmake .. -DCMAKE_BUILD_TYPE=Release
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2/build$ make
3.5 Build ORB_SLAM.
In the ORB_SLAM root execute:
注意:**If you use ROS Indigo, remove the depency of opencv2 in the manifest.xml.**
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2/build$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty/DBoW2$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Thirdparty$ cd ..
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ mkdir build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ cd build
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/build$ cmake .. -DROS_BUILD_TYPE=Release
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/build$ make
好了,到此ORB-SLAM就安装好了,下面就来跑它了。:-)
4. Usage1: 逐个手动启动各个程序
4.1 打开一个新终端,运行
zhuquan@zhuquan-Precision-5510:~$ roscore
运行结果如下图所示:
4.2 重新打开一个新终端(原来的终端保留),运行:
rosrun ORB_SLAM ORB_SLAM PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE
其中,PATH_TO_VOCABULARY和PATH_TO_SETTINGS_FILE分别是ORB vocabulary 和 settings file的路径,这里的路径必须是绝对路径或者是相对于ORB-SLAM源代码所在目录的相对路径。
例如,这里使用的是相对路径:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src$ cd ORB_SLAM/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ rosrun ORB_SLAM ORB_SLAM Data/ORBvoc.txt Data/Settings.yaml
运行结果如下图:
4.2 The last processed frame is published to the topic `/ORB_SLAM/Frame`. You can visualize it using `image_view`:
rosrun image_view image_view image:=/ORB_SLAM/Frame _autosize:=true;
例如:
重新打开一个新终端(原来的终端保留),运行:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ rosrun image_view image_view image:=/ORB_SLAM/Frame _autosize:=true
运行结果下图所示:
4.3 The map is published to the topic `/ORB_SLAM/Map`, the current camera pose and global world coordinate origin are sent through `/tf` in frames `/ORB_SLAM/Camera` and `/ORB_SLAM/World` respectively. Run `rviz` to visualize the map
注意:
*in ROS Fuerte*:
运行:
rosrun rviz rviz -d Data/rviz.vcg
*in ROS Groovy or a newer version*:
运行:
rosrun rviz rviz -d Data/rviz.rviz
例如:
重新打开一个新终端(原来的终端保留),运行:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src/ORB_SLAM/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ rosrun rviz rviz -d Data/rviz.rviz
运行结果如下图所示:
4.4 ORB_SLAM will receive the images from the topic `/camera/image_raw`. You can now play your rosbag。
5. Usage2: Use a roslaunch to launch `ORB_SLAM`, `image_view` and `rviz` from just one instruction.
We provide an example**:
*in ROS Fuerte*:
roslaunch ExampleFuerte.launch
*in ROS Groovy or a newer version*:
roslaunch ExampleGroovyOrNewer.launch
例如:
5.1 打开一个新终端,运行
zhuquan@zhuquan-Precision-5510:~$ roscore
运行结果如下图所示:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src/ORB_SLAM/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ roslaunch ExampleGroovyOrNewer.launch
运行结果如下图所示:
6. Example Sequence
We provide the settings and the rosbag of an example sequence in our lab. In this sequence you will see a loop closure and two relocalisation from a big viewpoint change.
6,1 Download the rosbag file and uncompress the file.
http://webdiis.unizar.es/~raulmur/orbslam/downloads/Example.bag.tar.gz.
6.2 Once the ORB vocabulary has been loaded, play the rosbag (press space to start):
rosbag play --pause Example.bag
例如:
Usage1:
重新打开一个新终端(原来的终端保留),运行:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src/ORB_SLAM/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ cd Data
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Data$ rosbag play --pause Example.bag
运行结果如下图所示:
Usage2:
重新打开一个终端(原终端保留),运行:
zhuquan@zhuquan-Precision-5510:~$ cd orbslam_catkin_ws/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ source devel/setup.bash
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws$ cd src/ORB_SLAM/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM$ cd Data/
zhuquan@zhuquan-Precision-5510:~/orbslam_catkin_ws/src/ORB_SLAM/Data$ rosbag play --pause Example.bag
运行结果如下图所示:
到此,程序就跑完了~
主要参考:论文源代码中的Readme文档。