ORB-SLAM2 detailed installation tutorial (ubuntu18.04)

foreword

paper: https://arxiv.org/pdf/1610.06475.pdf
github: : https://github.com/raulmur/ORB_SLAM2
提示:ORB-SLAM2源码作者推荐在Ubuntu 12.04, 14.04 和16.04上安装运行。
recently stepped on a lot of pits when configuring the ORB-SLAM2 operating environment on ubuntu18.04, during this period After consulting a lot of information and blogs, I want to summarize the installation process, so that I can review it repeatedly and share my experience to avoid repeated pitfalls.
The blogger installed ORB-SLAM2 in the ubuntu18.04 container with docker, and it has been packaged into a docker image file to share with everyone.

# 查看ubuntu版本号
lsb_release -a


Preparation before installation : install cmake, git, gcc and g++

# 更新apt库,更新软件列表
sudo apt-get update

apt-get source modification reference

# 安装git,用于从Github上克隆项目到本地
sudo apt-get install git
# 安装cmake,用于程序的编译
sudo apt-get install cmake
# 安装gcc和g++,安装c和c++编译器
sudo apt-get install gcc g++

1. Install third-party libraries

# 建立一个ORB-SLAM2的文件夹,建议将所有的第三方库以及ORB-SLAM2源码都放入其中
mkdir ORB-SLAM2

1. Install Pangolin

Pangolin is a lightweight OpenGL input/output and video display library that encapsulates OpenGL.
1. Install dependencies

sudo apt-get install libgl1-mesa-dev
sudo apt-get install libglew-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libpython2.7-dev

2. Install Pangolin
Download the Pangolin source code through the link or through git (not recommended, there are many problems)

# 需要科学上网
git clone --recursive https://github.com/stevenlovegrove/Pangolin.git

Strongly recommend Pangolin 0.6 (stable version) extraction code: 45bo

# 解压并重命名为Pangolin
unzip Pangolin-0.6.zip && mv Pangolin-0.6 Pangolin
# 开始编译和安装
cd Pangolin
mkdir build && cd build 
cmake -DCPP11_NO_BOOST=1 ..
sudo make install

3. Verify that the installation is complete

# 验证
cd ../examples/HelloPangolin
mkdir build && cd build
cmake ..
make
./HelloPangolin

If the installation is successful, the following window will pop up:

2. Install OpenCV

You can refer to this link
1. Install dependencies

# 解决:Unmet dependencies.Try'apt--fix-broken install'with no packages(or specify a solution)
sudo apt --fix-broken install
sudo apt-get update
sudo apt-get upgrade

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev
sudo apt-get install libtiff5.dev libswscale-dev

# 解决:add-apt-repository: command not found
sudo apt-get install software-properties-common

sudo apt-get update
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get update
sudo apt-get install libjasper1 libjasper-dev

2. Install OpenCV3.4.5
OpenCV3.4.5 source code extraction code: m27t (the old version of OpenCV can be found in Releases on the right side of the Github warehouse)

# 安装百度云,xxx.deb是自己下载的版本
sudo dpkg -i baidunetdisk_4.17.7_amd64.deb
# 解压并重命名为opencv
tar -xvf opencv-3.4.5.tar.gz && mv opencv-3.4.5 opencv
# 开始编译和安装
cd opencv
mkdir build && cd build 
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
# 4线程数量,根据电脑性能选择合适的数字
make -j4
sudo make install

3. Verify that the installation is complete

# 查询OpenCV版本
pkg-config --modversion opencv
# 查询OpenCV库
pkg-config --cflags opencv
# 查询头文件目录
pkg-config --libs   opencv

# 验证
cd opencv/samples/cpp/example_cmake
cmake .
make
./opencv_example

If the installation is successful, the following window will pop up:

3. Install Eigen

1. To install Eigen3.3.7
, it is recommended to install the source code to download the corresponding files of any version.

# 解压并重命名为opencv
tar -xvf eigen-3.3.7.tar.gz && mv eigen-3.3.7 eigen
# 开始编译和安装
cd eigen
mkdir build && cd build
cmake ..
make
sudo make install

# 在很多程序中include时经常使用#include <Eigen/Dense>而不是使用#include <eigen3/Eigen/Dense>
# 因此安装后需要将头文件从 /usr/local/include/eigen3/ 复制到 /usr/local/include
# 后续小节会有C++测试代码说明
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include

2. Test that the eigen library is installed. Create
a test.cp file in the home directory for testing.

# 建立 test 测试文件
touch test_eigen.cpp
# 用gedit打开此测试文件,添加C++代码用于测试
gedit test_eigen.cpp
# 编译后生成一个test_eigen的可执行文件
g++ test_eigen.cpp -o test_eigen
# 在test_eigen可执行文件目录下执行以下命令,证明eigen库安装完成
./test_eigen

C++ test code added in test_eigen.cpp file.

#include <iostream>
//需要将头文件从 /usr/local/include/eigen3/ 复制到 /usr/local/include
#include <Eigen/Dense>
//using Eigen::MatrixXd;
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture;
using namespace std;
int main()
{
    
    
        cout<<"*******************1D-object****************"<<endl;
        Vector4d v1;
        v1<< 1,2,3,4;
        cout<<"v1=\n"<<v1<<endl;
 
        VectorXd v2(3);
        v2<<1,2,3;
        cout<<"v2=\n"<<v2<<endl;
 
        Array4i v3;
        v3<<1,2,3,4;
        cout<<"v3=\n"<<v3<<endl;
 
        ArrayXf v4(3);
        v4<<1,2,3;
        cout<<"v4=\n"<<v4<<endl;
}

2. Install and run ORB-SLAM2

1. Install and compile ORB-SLAM2

# 通过git下载ORB_SLAM2源码,需要科学上网
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
# 赋予shell文件运行权限
chmod +x build.sh
# 需要科学上网
# 博主根据个人电脑性能将build.sh里的make -j 修改为 make -j8
./build.sh

Common mistakes

If the following errors occur during compilation, add #include <unistd.h> to the corresponding header file

# 下列是需要加上#include <unistd.h>的c++文件
# 在ORB_SLAM2/src文件夹下
LocalMapping.cc	
LoopClosing.cc
System.cc	
Tracking.cc
Viewer.cc
# 在ORB_SLAM2/Examples/RGB-D文件夹下
rgbd_tum.cc
# 在ORB_SLAM2/Examples/Monocular文件夹下
mono_kitti.cc
mono_euroc.cc
mono_tum.cc
# 在ORB_SLAM2/Examples/Stereo/文件夹下
stereo_euroc.cc
stereo_kitti.cc

Or directly add #include <unistd.h> in ORB_SLAM2/include/System.h (strongly recommended)

If there are errors as follows, you can use gedit to open or execute the following command to install xterm

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install xterm

2. Monocular mode operation demonstration case

TUM dataset
data download link , download the following dataset

# 解压数据集
tar -xvf rgbd_dataset_freiburg1_desk.tgz

According to the data set requirements: Examples/Monocular/TUM1.yaml corresponds to freiburg1

and executes the following command to display the effect

./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml /root/Downloads/rgbd_dataset_freiburg1_desk/

3.RGBD mode mode operation demonstration case

It is necessary to download associate.py and add it to the data folder.

Personal understanding: the function is to align the data of RGD and depth, and make a one-to-one correspondence.

Note: can only run in Python2 environment

# associate.py需要numoy包
sudo apt-get install python-pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple numpy

# 在数据文件夹里执行命令
python associate.py rgb.txt depth.txt > associate.txt
python associate.py associate.txt groundtruth.txt > associate_with_groundtruth.txt


Execute the following command to display the effect

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml /root/Downloads/rgbd_dataset_freiburg1_desk/ /root/Downloads/rgbd_dataset_freiburg1_desk/associate.txt

Summarize

The installation process of ORB-SLAM2 is introduced as simple and detailed as possible and the problems that may exist during the installation process are solved. In the follow-up, I will explain the principle and code of ORB-SLAM2 based on the knowledge I have learned and my personal understanding.

Guess you like

Origin blog.csdn.net/yangyu0515/article/details/129014439