【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2

Table of Contents

0. 写在前面

1. Ubuntu16.04的安装

2. Ubuntu的配置

3. ROS的安装

4. 依赖项的安装

5. ORB SLAM2的安装

6. Monocular Examples(单目数据集测试)

7. ROS Examples(笔记本摄像头测试)


 

0. 写在前面

在完成这项工作之前走了不少的弯路,白白花费了不少的时间。起初我是在虚拟机中搭建ORB_SLAM2,但是每次到编译ORB_SLAM2过程中,编译Optimizer.cc.o这一项时就会莫名其妙的卡住停滞不前,等了一个晚上也没有结果。

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第1张图片

查找了很多资料,试了很多方法,各种软件包的不同版本搭配适用,甚至不同源的镜像14、16都换了又换,都没有奏效,白白花了两天的时间(之前编译G2O时也发生了类似的情况)。最后决定试一试直接安装Ubuntu系统,看看会不会奏效,因为网上说在虚拟机中会发生很多未知的状况。

安装Ubuntu也是一路坎坷,撸来了女朋友落灰的联想IdeaPadS410试用。按照教程准备镜像文件制作启动U盘,然而每次到安装的时候都会发生分钟各样的花式错误,要么是uncompressed error,system halted要么是end kernel,panic not syncing,No working init found,试了4种不同制作启动U盘的软件都没有成功,总之各种崩溃,一度让我以为电脑是不是被我搞坏了。最后,换了个闪迪的8G的U盘,一路绿灯装好。。。之前用的U盘是16G的海康威视发的纪念品,一直随身使用的。。。悔不该贪图小便宜,又浪费了两天的时间。

 

1. Ubuntu16.04的安装

网上的教程很多,不过多赘述,可参考:Ubuntu16.04安装

 

2. Ubuntu的配置

(1) 基础工具

安装vim、cmake、git、gcc、g++:

sudo apt-get install vim git cmake 
sudo apt-get install gcc g++ 

(2)配置软件源

将镜像源更改为清华的镜像源:

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第2张图片

使用下面的命令添加清华的ROS软件源:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第3张图片

 (3)设置密钥

使用下面的命令:

sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

 若输出以下信息则说明成功:

--recv-key
421C365BD9FF1F717815A3895523BAEEB01FA116
gpg: requesting key B01FA116 from hkp server ha.pool.sks-keyservers.net
gpg: key B01FA116: public key "ROS Builder " imported
gpg: Total number processed: 1
gpg:               imported: 1

但是本人获取后下面更新时一直不成功,所以获取密钥的方法更换如下(参考:ROS安装使用中遇到的问题及解决办法(包括ubuntu)):

wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

(4)更新索引

sudo apt-get update

 

3. ROS的安装

(1)安装ROS

安装桌面完整版的ROS:

sudo apt-get install ros-kinetic-desktop-full

(2)初始化 rosdep

sudo rosdep init
rosdep update

(3)设置环境

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc

关于环境变量的解释如下:ROS中为什么设置环境变量,如何设置?

(4)安装 rosinstall

rosinstall是一个常用的命令行工具,可以通过一个命令为 ROS 包简单地下载许多源码树。

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential 

(5)测试ROS

启动ROS:

roscore

 若打印出以下,则说明安装成功:

started roslaunch server http://xiaolong-Lenovo-IdeaPad-S410:39383/
ros_comm version 1.12.14


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES

auto-starting new master
process[master]: started with pid [3499]
ROS_MASTER_URI=http://xiaolong-Lenovo-IdeaPad-S410:11311/

setting /run_id to 9272dfb2-8f75-11e9-a926-28e347a51611
process[rosout-1]: started with pid [3512]
started core service [/rosout]

重新打开一个t终端,要启动海龟仿真器:

rosrun turtlesim turtlesim_node

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第4张图片

重新打开一个终端,通过上下左右方向键控制运行:

rosrun turtlesim turtle_teleop_key

 

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第5张图片

(5)创建工作环境

mkdir -p ~/SLAM/src
cd ~/SLAM/src
catkin_make

echo "source ~/SLAM/devel/setup.bash" >> ~/.bashrc  
source ~/.bashrc

 

4. 依赖项的安装

本人安装的ORB_SLAM2时间为2019.06.15,自述文件中依赖库的安装描述如下:

**13 Jan 2017**: OpenCV 3 and Eigen 3.3 are now supported.

We have tested the library in **Ubuntu 12.04**, **14.04** and **16.04**, but it should be easy to compile in other platforms. A powerful computer (e.g. i7) will ensure real-time performance and provide more stable and accurate results.

## C++11 or C++0x Compiler
We use the new thread and chrono functionalities of C++11.

## Pangolin
We use [Pangolin](https://github.com/stevenlovegrove/Pangolin) for visualization and user interface. Dowload and install instructions can be found at: https://github.com/stevenlovegrove/Pangolin.

## OpenCV
We use [OpenCV](http://opencv.org) to manipulate images and features. Dowload and install instructions can be found at: http://opencv.org. **Required at leat 2.4.3. Tested with OpenCV 2.4.11 and OpenCV 3.2**.

## Eigen3
Required by g2o (see below). Download and install instructions can be found at: http://eigen.tuxfamily.org. **Required at least 3.1.0**.

## DBoW2 and g2o (Included in Thirdparty folder)
We use modified versions of the [DBoW2](https://github.com/dorian3d/DBoW2) library to perform place recognition and [g2o](https://github.com/RainerKuemmerle/g2o) library to perform non-linear optimizations. Both modified libraries (which are BSD) are included in the *Thirdparty* folder.

## ROS (optional)
We provide some examples to process the live input of a monocular, stereo or RGB-D camera using [ROS](ros.org). Building these examples is optional. In case you want to use ROS, a version Hydro or newer is needed.

根据上述要求下载安装

(1)Pangolin

安装Pangolin,用于可视化和用户接口,首先安装依赖如下:

sudo apt-get install libglew-dev libboost-dev libboost-thread-dev libboost-filesystem-dev 

下载Pangolin:

cd ~/SLAM/src
git clone https://github.com/stevenlovegrove/Pangolin

编译并安装Pangolin:

cd Pangolin
mkdir build
cd build
cmake ..
make
sudo make install

(2)OpenCV

本人下载使用的是opencv3.2版本。

安装编译工具:

sudo apt-get install build-essential 

安装依赖包:

sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 

下载opencv3.2安装包,有tar.gz或者zip可以选择,本人是用的是tar.gz:https://github.com/opencv/opencv/releases/tag/3.2.0

将下载完毕的压缩包放入~/SLAM/src目录中并进行解压:

tar -xzvf opencv-3.2.0.tar.gz

编译并安装opencv3.2:

cd opencv-3.2.0/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. 
make
sudo make install

(3)Eigen

由于当前使用的orb_slam2支持eigen3.3,所以直接apt-get方式下载安装即可(实际已经在之前的步骤中安装完毕):

sudo apt-get install libeigen3-dev

 

5. ORB SLAM2的安装

下载:

cd ~SLAM/src
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2

编译前需要打开build.sh文件,将所有的make -j改为make之后修改文件权限并运行编译

chmod +x build.sh
./build.sh

此时编译成功,不会出现开头编译Optimizer.cc.o卡住之一情况:

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第6张图片

 

6. Monocular Examples(单目数据集测试)

自述文件中介绍了,在单目测试中可以使用TUM Dataset、KITTI Dataset、EuRoC Dataset三种数据集进行测试,以TUM Dataset为例,自述文件中原文如下:

## TUM Dataset

1. Download a sequence from http://vision.in.tum.de/data/datasets/rgbd-dataset/download and uncompress it.

2. Execute the following command. Change `TUMX.yaml` to TUM1.yaml,TUM2.yaml or TUM3.yaml for freiburg1, freiburg2 and freiburg3 sequences respectively. Change `PATH_TO_SEQUENCE_FOLDER`to the uncompressed sequence folder.
```
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUMX.yaml PATH_TO_SEQUENCE_FOLDER
```

登录http://vision.in.tum.de/data/datasets/rgbd-dataset/download,下载freiburg1_xyz数据集并解压,执行如下命令:

./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml ~/SLAM/src/ORB_SLAM2/rgbd_dataset_freiburg1_xyz

 运行过程如下:

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第7张图片

freiburg2_xyz巨大,下载太慢,就不进行测试了。

 

7. ROS Examples(笔记本摄像头测试)

自述文件中原文如下:

### Building the nodes for mono, monoAR, stereo and RGB-D
1. Add the path including *Examples/ROS/ORB_SLAM2* to the ROS_PACKAGE_PATH environment variable. Open .bashrc file and add at the end the following line. Replace PATH by the folder where you cloned ORB_SLAM2:

  ```
  export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/SLAM/src/ORB_SLAM2/Examples/ROS
  ```
 
2. Execute `build_ros.sh` script:

  ```
  chmod +x build_ros.sh
  ./build_ros.sh
  ```

(1)下载安装usb_cam

cd ~/SLAM/src
git clone https://github.com/bosch-ros-pkg/usb_cam.git
mkdir build
cd build
cmake ..
make
make install

 执行下面的命令,若无错误,则说明安装成功。

roscd usb_cam

(2)编译build_ros.sh

首先,打开文件gedit ~/.bashrc,在文件末尾添加(根据自己的路径):

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/SLAM/src/ORB_SLAM2/Examples/ROS

编译前需要打开build_ros.sh文件,将make -j改为make之后修改文件权限并运行编译

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'
/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:213: 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
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

解决方法参考:

ubuntu16.04编译ORBSLAM2问题解决

需复制libboost_system.so、libboost_filesystem.so、libboost_system.so.1.58.0、libboost_filesystem.so.1.58.0四个文件,即可编译成功如下:

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第8张图片

(3)运行Demo

使用笔记本摄像头运行的demo(单目),可运行的的demo有两个,一个是slam,其文件路径为~/SLAM/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_mono.cc;外一个是AR,其文件路径为~/SLAM/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ros_mono_ar.cc。两者操作相同,以前者为例。

修改摄像头输入:

打开~/SLAM/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_mono.cc文件,

ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);

修改为

ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);

更新环境变量:

source ~/.bashrc

重新编译ros内核:

./build_ros.sh

打开ros内核:

roscore

重新开启一个终端,输入:

roslaunch usb_cam usb_cam-test.launch

重新开启一个终端,输入以下命令即可运行demo:

rosrun ORB_SLAM2 Mono /home/xiaolong/SLAM/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/xiaolong/SLAM/src/ORB_SLAM2/Examples/Monocular/TUM1.yaml 

TUM1.yaml是参数设置文件,主要是相机的内参,可以直接使用例程中的TUM1.yaml。

效果图如下^ ^:

【ORB_SLAM2】1——Ubuntu16.04系统下搭建ORB_SLAM2_第9张图片

 

未完待续~

你可能感兴趣的:(ORB_SLAM2,ORB,SLAM2,UBUNTU16,笔记本摄像头,单目摄像头,Monocular)