当前位置: 代码迷 >> 综合 >> Ubuntu20.04 —— 新系统从头安装ORB-SLAM3过程(2022年)
  详细解决方案

Ubuntu20.04 —— 新系统从头安装ORB-SLAM3过程(2022年)

热度:95   发布时间:2023-12-16 23:02:53.0

这里写目录标题

  • 写在前面:
  • 一、准备工作:
    • 1.安装git
    • 2.安装vi编辑器
    • 3.安装c++编译器
    • 4.安装CMake-3.18.4
    • 5.下载ORB-SLAM3源码
  • 二、安装各种依赖库
    • 1.Eigen3.3.4安装
    • 2.Pangolin安装
    • 3.OpenCV3.3.5安装
    • 4.安装Python & libssl-dev
    • 5.安装boost库
  • 三、安装ORB-SLAM3
    • 编译可能报错:
  • 四、数据集测试
    • 1.数据集下载
    • 2.修改数据集
  • 五、结果展示
  • 七、可能的报错

写在前面:

本来是想在Ubuntu18.04上跑ORB-SLAM3的,但是不知道是那一步错了,在编译的最后一步出了好多错误,网上找了好多解决办法都不行,因为以前在Ubuntu18.04上跑了高博的slambook2的例程,安装了多个版本的库自己感觉是不同的库之间相互影响,索性直接安装Ubuntu20.04从头开始搭建运行环境,Ubuntu18.04上的错误以后再想办法。
(几天后补:不是我安装的问题,可能masterv1.0-release版出现了bug恰好让我赶上了,最终安装v0.4-beta版成功了!!!)
错误代码:

$ ./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml ./dataset/MH_01_easy ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt
num_seq = 1
Loading images for sequence 0...LOADED!-------ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.Input sensor was set to: Monocular
Loading settings from ./Examples/Monocular/EuRoC.yaml
Camera1.k3 optional parameter does not exist...-Loaded camera 1-Loaded image info-Loaded ORB settings
Viewer.imageViewScale optional parameter does not exist...-Loaded viewer settings
System.LoadAtlasFromFile optional parameter does not exist...
System.SaveAtlasToFile optional parameter does not exist...-Loaded Atlas settings
System.thFarPoints optional parameter does not exist...-Loaded misc parameters
----------------------------------
SLAM settings: -Camera 1 parameters (Pinhole): [ 458.65399169921875 457.29598999023438 367.21499633789062 248.375 ]-Camera 1 distortion parameters: [  -0.28340810537338257 0.073959067463874817 0.00019359000725671649 1.7618711353861727e-05 ]-Original image size: [ 752 , 480 ]-Current image size: [ 600 , 350 ]-Camera 1 parameters after resize: [  365.94735717773438 333.44500732421875 292.99069213867188 181.10678100585938 ]-Sequence FPS: 20-Features per image: 1000-ORB scale factor: 1.2000000476837158-ORB number of scales: 8-Initial FAST threshold: 20-Min FAST threshold: 7Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!Initialization of Atlas from scratch 
Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name: 
There are 1 cameras in the atlas
Camera 0 is pinhole
First KF:0; Map init KF:0
New Map created with 346 points
ShutdownSaving trajectory to CameraTrajectory.txt ...
There are 1 maps in the atlasMap 0 has 299 KFsEnd of saving trajectory to CameraTrajectory.txt ...Saving keyframe trajectory to KeyFrameTrajectory.txt ...

Ubuntu18.04 —— 新系统从头安装ORB-SLAM3过程
下面的安装过程正确请放心
环境说明:
虚拟机VMware + Ubuntu20.04 + Win10(i5-8500)

一、准备工作:

终端与主机复制粘贴

sudo apt-get autoremove open-vm-tools
sudo apt-get install open-vm-tools-desktop

在这里插入图片描述
重启虚拟机VMware
安装好vmtools之后的重启是通过右上角设置按钮那边重启,而不是通过vmware左上角的重启。

1.安装git

sudo apt-get install git

2.安装vi编辑器

先卸载旧的vim,再装新的。

sudo apt-get remove vim-common
sudo apt-get install vim

3.安装c++编译器

sudo apt install g++

4.安装CMake-3.18.4

sudo apt install build-essential libssl-dev
wget https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4.tar.gz
tar -zxvf cmake-3.18.4.tar.gz
cd cmake-3.18.4
./bootstrap
make
sudo make install
# 查看版本
cmake -version

在这里插入图片描述

5.下载ORB-SLAM3源码

先新建一个目录,用于放源码。

mkdir orb_slam3
cd orb_slam3
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git

到这一步准备工作已基本完成,接下来就是安装其他库了。

二、安装各种依赖库

1.Eigen3.3.4安装

#github 有个mirror,版本3.3.4 from 2017
git clone https://github.com/eigenteam/eigen-git-mirror#安装
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install#安装后,头文件安装在/usr/local/include/eigen3/

在这里插入图片描述

2.Pangolin安装

安装Pangolin所需依赖
sudo apt install libgl1-mesa-dev
sudo apt install libglew-dev
//sudo apt install cmake //注意以前装了就不需要安装了
sudo apt install libpython2.7-dev
//sudo apt install python-pip
//sudo python -mpip install numpy pyopengl Pillow pybind11
sudo apt install pkg-config
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols
//sudo apt install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev
//sudo apt install libdc1394-22-dev libraw1394-dev
//sudo apt install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev
# 默认git版本为0.6
//git clone https://github.com/stevenlovegrove/Pangolin.git 
//坑呀!太坑了!不能安装Pangolin master 版本
git clone https://github.com/stevenlovegrove/Pangolin/tree/v0.6.git    
cd Pangolin
mkdir build && cd build
cmake ..
make -j4
sudo make install

检查是否安装成功:

cd examples/HelloPangolin
./HelloPangolin

在这里插入图片描述

3.OpenCV3.3.5安装

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-devsudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev

在这里我出现了一个错误:

获取:1 http://202.199.28.2/files/4135000001411F7F/http.kali.org/kali focal/main amd64 m4 amd64 1.4.18-4 [199 kB]
错误:1 http://202.199.28.2/files/4135000001411F7F/http.kali.org/kali focal/main amd64 m4 amd64 1.4.18-4文件尺寸不符(202872 != 199128)。您使用的镜像正在同步中? [IP: 202.199.28.2 80]Hashes of expected file:- SHA256:1ffa955ebb58829f3ab0debf7ad57b150887f6a44769edbaef68b8da9d95f306- SHA1:e65ec1a9d9c7ee858f50b3408bfedb9f675b1069 [weak]- MD5Sum:3785537d21012e0e481f0fea152b04a1 [weak]- Filesize:199128 [weak]
E: 无法下载 http://202.199.28.2/files/4135000001411F7F/http.kali.org/kali/pool/main/m/m4/m4_1.4.18-4_amd64.deb  文件尺寸不符(202872 != 199128)。您使用的镜像正在同步中? [IP: 202.199.28.2 80]Hashes of expected file:- SHA256:1ffa955ebb58829f3ab0debf7ad57b150887f6a44769edbaef68b8da9d95f306- SHA1:e65ec1a9d9c7ee858f50b3408bfedb9f675b1069 [weak]- MD5Sum:3785537d21012e0e481f0fea152b04a1 [weak]- Filesize:199128 [weak]
E: 有几个软件包无法下载,要不运行 apt-get update 或者加上 --fix-missing 的选项再试试?

换了好多源都不行,最后发现是 libgtk2.0-dev这个依赖项的问题

sudo apt install libgtk2.0-dev --fix-missing

下载OpenCV3.3.5
然后进入解压后的文件夹,在终端打开
接下来在命令行输入:

# 配置并编译
mkdir build&& cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

注意:执行上面指令后,终端会自动下载一个必需的ippicv加速库。
如果电脑配置了vpn并进入外网,便会卡住一会进行下载;
在这里插入图片描述
解决办法:下载离线的ippicv库

//包ippicv下载过慢,则中断安装后,自己下载
https://github.com/opencv/opencv_3rdparty/tree/ippicv/master_20180723
//我将包ippicv放在/home/sfann2/sfann/software/包ippicv"file:///##/##/下载/" #(仅供参考,根据自己的路径填写)
//我将"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/" 
//替换为"file:///home/sfann2/sfann/software/ippicv/" 注意分号//重新编译
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install

替换过程:
在这里插入图片描述
重新编译之后:
在这里插入图片描述
到此,OpenCV就安装好了,然后我们配置一下环境

#添加库路径
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'#更新系统库
sudo ldconfig
#配置bash
sudo gedit /etc/bash.bashrc# 1. 在末尾粘贴如下两行代码
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH # 2. 保存,执行如下命令使得配置生效:
source /etc/bash.bashrc 

在这里插入图片描述

#更新
apt-get install mlocate
sudo updatedb  
#opencv版本检测
pkg-config --modversion opencv

在这里插入图片描述

4.安装Python & libssl-dev

sudo apt install libpython2.7-dev
sudo apt-get install libssl-dev

5.安装boost库

Boost 是一个功能强大、构造精巧、跨平台、开源并且完全免费的 C++ 程序库。
进入boost官网:https://www.boost.org/
或者和我下载一样的下载的是1.75.0
在这里插入图片描述
解压后运行

sudo ./bootstrap.sh
sudo ./b2 install

三、安装ORB-SLAM3

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

如果编译失败,可以进入build.sh分步骤自己逐个进行编译,就是速度慢点,时间长点;

echo "Configuring and building Thirdparty/DBoW2 ..."cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
makecd ../../g2oecho "Configuring and building Thirdparty/g2o ..."mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
makecd ../../../echo "Uncompress vocabulary ..."cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd..echo "Configuring and building ORB_SLAM3 ..."mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make//不行的话可以换成了 make -j4 来执行

在这里插入图片描述

编译可能报错:

make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:89:CMakeFiles/ORB_SLAM3.dir/src/LocalMapping.cc.o] 错误 1make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:349:CMakeFiles/ORB_SLAM3.dir/src/CameraModels/KannalaBrandt8.cpp.o] 错误 1

解决办法:
在报错的文件里,如KannalaBrandt8.cpp,LocalMapping.cc

在include之后加上如下代码

namespace cv
{
    
template<typename _Tp, int m, int n> static inline
Matx<_Tp, m, n> operator / (const Matx<_Tp, m, n> &a, float alpha)
{
    
return Matx<_Tp, m, n>(a, 1.f / alpha, Matx_ScaleOp());
}
}

在这里插入图片描述
在这里插入图片描述

四、数据集测试

1.数据集下载

方法一:
数据集下载地址下载ASL格式
方法二:
阿里云盘MH01

2.修改数据集

  1. 从官网下载Euroc数据集,ASL格式;
  2. 路径:ORB_SLAM3/dataset/MH_##/mav0(举例:MH01解压后文件名为mav0,在dataset文件夹中新建MH01文件夹,将mav0放入,不要直接修改文件名!!!)
  3. 双击打开ORB-SLAM3源码中的脚本“euroc_examples.sh“,找到包含MH01的指令
./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml "$pathDatasetEuroc"/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono
//修改数据集路径
./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml ./dataset/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt

五、结果展示

在这里插入图片描述
运行结果:

$ ./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml ./dataset/MH_01_easy ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt
num_seq = 1
Loading images for sequence 0...LOADED!-------ORB-SLAM3 Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
ORB-SLAM2 Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.Input sensor was set to: MonocularLoading ORB Vocabulary. This could take a while...
Vocabulary loaded!Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name: Camera Parameters: 
- Camera: Pinhole
- fx: 458.65399169921875
- fy: 457.29598999023438
- cx: 367.21499633789062
- cy: 248.375
- k1: -0.28340810537338257
- k2: 0.073959067463874817
- p1: 0.00019359000725671649
- p2: 1.7618711353861727e-05
- fps: 20
- color order: RGB (ignored if grayscale)ORB Extractor Parameters: 
- Number of Features: 1000
- Scale Levels: 8
- Scale Factor: 1.2000000476837158
- Initial Fast Threshold: 20
- Minimum Fast Threshold: 7
Framebuffer with requested attributes not available. Using available framebuffer. You may see visual artifacts.First KF:0; Map init KF:0
New Map created with 315 points
Point distribution in KeyFrame: left-> 315 --- right-> 0
TRACK_REF_KF: Less than 15 matches!!
KF in map: 278
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Fail to track local map!
Relocalized!!
Fail to track local map!
Fail to track local map!
Relocalized!!
MakeCurrent: Not available with non-pangolin window.Saving trajectory to CameraTrajectory.txt ...End of saving trajectory to CameraTrajectory.txt ...Saving keyframe trajectory to KeyFrameTrajectory.txt ...

七、可能的报错

在这里插入图片描述

在这里插入图片描述

解决办法:重新下载数据集

  相关解决方案