1、基础工具安装

        安装cmake、git、gcc、g++。

sudo apt update -y 
sudo apt-get install cmake git gcc g++ -y 
sudo apt install pkg-config -y

2、安装Eigen库

        安装 eigen 3.2.10 版本:

git clone https://gitlab.com/libeigen/eigen.git 
cd eigen 
git checkout 3.2.1
 mkdir build && cd build 
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 
sudo cmake --build . --target install

        卸载方法:eigen3 是仅头部库,没有 uninstall 脚本。

sudo rm -rf /usr/local/share/pkgconfig/eigen3.pc 
sudo rm -rf /usr/local/include/eigen3/

3、安装Pangolin0.6

        版本过高会导致错误,安装依赖项。

sudo apt install libglew-dev -y 
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols -y 
sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev -y 
sudo apt install libdc1394-22-dev libraw1394-dev -y 
sudo apt install libjpeg-dev libpng12-dev libtiff5-dev libopenexr-dev -y

        安装 Pangolin:

git clone https://github.com/stevenlovegrove/Pangolin.git 
cd Pangolin 
git checkout v0.6 
mkdir build && cd build 
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 
sudo cmake --build . --target install

        安装完成后进行测试:

cd Pangolin/examples/HelloPangolin/ 
mkdir build && cd build 
cmake .. 
make ./HelloPangolin

        运行成功会显示一个立方体:

ubuntu20.04运行ORB_SLAM2-LMLPHP

4、安装Opencv3

        添加额外源:

sudo apt-add-repository universe 
sudo apt-get update

        安装依赖:

sudo apt-get install libglew-dev libtiff5-dev zlib1g-dev libjpeg-dev libpng-dev libavcodec-dev libavformat-dev libavutil-dev libpostproc-dev libswscale-dev libeigen3-dev libtbb-dev libgtk2.0-dev pkg-config -y

        安装 opencv:

git clone https://github.com/opencv/opencv.git 
# wget https://github.com/opencv/opencv/archive/refs/tags/3.4.16.zip 
cd opencv 
git checkout 3.4.16 
mkdir build && cd build 
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local 
sudo cmake --build . --target install

添加环境变量:

1、添加库路径

        在 /etc/ld.so.conf.d/ 目录下新建文件 opencv3.conf。并输入以下内容:

/usr/local/lib

2、添加环境变量

        在 /etc/profile.d 新建文件 opencv3.sh。并输入以下内容:

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

3、更新环境变量:

source /etc/profile.d/opencv3.sh

4、验证安装是否成功

        重启并输入命令:

pkg-config --modversion opencv # 输出 # 3.4.16

运行测试程序:

cd opencv/samples/cpp/example_cmake/ 
mkdir build && cd build 
cmake .. 
make 
./opencv_example

5、安装ORB_SLAM2

下载地址:https://github.com/electech6/ORB_SLAM2_detailed_comments

https://github.com/electech6/ORB_SLAM3_detailed_comments

对于orb_slam2,执行如下步骤:

step1、修改build.sh

cd orb_slam2 
chmod +x build.sh 
./build.sh

step2、原版代码报错:

error:static assertion failed:std::map must have the same value_type as its allocator,

解决方法:在ORB_SLAM2的安装路径下打开 /include 文件夹,在 LoopClosing.h 中修改第49-50行,将:

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>, Eigen::aligned_allocator<std::pair<const KeyFrame*, g2o::Sim3> > > KeyFrameAndPose;

改为:

typedef map<KeyFrame*,g2o::Sim3,std::less<KeyFrame*>, Eigen::aligned_allocator<std::pair<KeyFrame* const, g2o::Sim3> > > KeyFrameAndPose;

6、测试

        在ORB_SLAM2文件夹内新建data(名字随意)文件夹,用于存放数据集,将刚刚解压缩后的文件夹拷贝至data文件夹内。

cd orb_slam2 
mkdir data && cd data 
wget https://cvg.cit.tum.de/rgbd/dataset/freiburg1/rgbd_dataset_freiburg1_xyz.tgz 
tar -xvzf rgbd_dataset_freiburg1_xyz.tgz # 运行数据集 
cd orb_slam2 
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml data/rgbd_dataset_freiburg1_xyz

        出现运行结果:

ubuntu20.04运行ORB_SLAM2-LMLPHP

参考资料:

1、ORB_SLAM2编译错误处理

[ORB_SLAM2]运行_编译slam2时出现error: static assertion failed: std::map-CSDN博客

10-14 10:20