纯小白Ubuntu20.04系统从零运行ORBSLAM3

纯小白Ubuntu20.04系统从零运行ORBSLAM3

前阵子安装ORBSLAM3,怕自己后面还需要,写一个过程当作自我备忘,如果能帮到其他人那就更好了

安装Ubuntu20.04

有很多教程这里就不展开了。

配置环境

新系统的一些准备

安装git

如果是新系统需要先安装git,在终端执行以下指令:

sudo apt-get install git
安装vi编辑器

如果是新系统需要先安装vi编辑器,在终端执行以下指令:

sudo apt-get remove vim-common
sudo apt-get install vim
安装gcc、g++
sudo apt-get install gcc
sudo apt-get install g++
安装cv_bridge

在终端执行以下指令:

sudo apt-get install libopencv-dev
sudo apt-get install ros-noekit-cv-bridge

安装opencv

安装依赖项

在终端执行以下指令:

sudo apt-get install build-essential libgtk2.0-dev libgtk-3-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev
sudo apt install python3-dev python3-numpy
sudo apt install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev
sudo apt install libpng-dev libopenexr-dev libtiff-dev libwebp-dev
下载opencv4.2

在官网(https://opencv.org/releases/page/3/)将下载的opencv4.2解压至主目录,命名应该是opencv-4.2.0
在这里插入图片描述

安装opencv

在终端执行以下指令:

cd opencv-4.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES ..
make
sudo make install
查看版本号

在终端执行以下指令:

pkg-config --modversion opencv4

终端应该会返回4.2.0,代表安装成功

安装各种库

安装EIGEN库

在终端执行以下指令:

sudo apt-get install libeigen3-dev
安装Pangolin库

下载Pangolin0.6,解压到主目录,重命名为Pangolin
在终端执行以下指令安装依赖项:

sudo apt-get install libglew-dev libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libpng-dev

在终端执行以下指令编译安装:

cd Pangolin 
mkdir build && cd build
cmake -DCPP11_NO_BOOST=1 ..
make

再在终端执行以下指令:

sudo make install

再在终端执行以下指令进行验证:

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

再在终端执行以下指令:

make
./HelloPangolin

如果成功会弹出窗口,一个立方体

安装Boost库

在官网http://www.boost.org/users/download/下载boost_1_77_0.tar.gz
解压后在终端执行以下指令进行安装:

tar -xvf boost_1_77_0.tar.gz
cd ./boost_1_77_0
./bootstrap.sh
sudo ./b2 install

安装ORBSLAM3

下载ORBSLAM3

在终端执行以下指令:

git clone https://github.com/electech6/ORB_SLAM3_detailed_comments.git 

下载完成后重命名为ORB-SLAM3

修改文件

首先在orbslam3文件夹下打开CMakeLists.txt
找到find_package(OpenCV 3.2),把版本号3.2改成自己的版本,也就是4.2。
在这里插入图片描述
再找到find_package(Eigen3 3.1.0 REQUIRED),把版本号3.1.0删掉。
在这里插入图片描述
然后进入Thirdparty→DBoW2,打开CMakeLists.txt,找到find_package(OpenCV 3.2 QUIET),把版本号改成自己的版本,也就是4.2。
在这里插入图片描述
随后进入Examples→Monocular,打开mono_euroc.cc文件,把第83行的false改成true。(这一步是为了程序运行时能显示可视化窗口)
在这里插入图片描述
而后在ORB-SLAM3文件夹下右键打开终端执行以下指令刷新配置:

chmod +x build.sh 
./build.sh

测试数据集

下载EuRoC数据集

EuRoC数据集下载网址:
https://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets
在ORB-SLAM3文件夹下新建一个datasets文件夹,在datasets文件夹下新建一个MH01文件夹,打开kmavvisualinertialdatasets – ASL Datasets下载ASL Dataset Format列表下的Machine Hall 01数据集,将下载后的mav0文件拷贝到上文中新建的MH01文件夹中
(其他数据集参考https://blog.csdn.net/m0_60355964/article/details/125995064这篇文章)

运行EuRoC数据集

在ORB-SLAM3文件夹下右键打开终端执行以下指令:

./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml ./datasets/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono

运行效果如下:
在这里插入图片描述

下载RGBD-TUM数据集

RGBD-TUM数据集下载网址: https://vision.in.tum.de/data/datasets/rgbd-dataset/download
将下载的数据解压缩到ORBSLAM3文件夹中,以rgbd_dataset_freiburg3_walking_xyz为例。
在这里插入图片描述
下载配准文件associate.py
下载网址:https://cvg.cit.tum.de/data/datasets/rgbd-dataset/tools
或者自己在/ORB_SLAM3/Examples/RGB-D目录里面创建一个associate.py,将以下代码粘贴进去。

import argparse
import sys
import os
import numpy
 
 
def read_file_list(filename):
    """
    Reads a trajectory from a text file. 
    
    File format:
    The file format is "stamp d1 d2 d3 ...", where stamp denotes the time stamp (to be matched)
    and "d1 d2 d3.." is arbitary data (e.g., a 3D position and 3D orientation) associated to this timestamp. 
    
    Input:
    filename -- File name
    
    Output:
    dict -- dictionary of (stamp,data) tuples
    
    """
    file = open(filename)
    data = file.read()
    lines = data.replace(","," ").replace("\t"," ").split("\n")
    #if remove_bounds:
    #    lines = lines[100:-100]
    list = [[v.strip() for v in line.split(" ") if v.strip()!=""] for line in lines if len(line)>0 and line[0]!="#"]
    list = [(float(l[0]),l[1:]) for l in list if len(l)>1]
    return dict(list)
 
def associate(first_list, second_list,offset,max_difference):
    """
    Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim 
    to find the closest match for every input tuple.
    
    Input:
    first_list -- first dictionary of (stamp,data) tuples
    second_list -- second dictionary of (stamp,data) tuples
    offset -- time offset between both dictionaries (e.g., to model the delay between the sensors)
    max_difference -- search radius for candidate generation
    Output:
    matches -- list of matched tuples ((stamp1,data1),(stamp2,data2))
    
    """
    first_keys = list(first_list.keys())
    second_keys = list(second_list.keys())
    potential_matches = [(abs(a - (b + offset)), a, b) 
                         for a in first_keys 
                         for b in second_keys 
                         if abs(a - (b + offset)) < max_difference]
    potential_matches.sort()
    matches = []
    for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches
 
if __name__ == '__main__':
    
    # parse command line
    parser = argparse.ArgumentParser(description='''
    This script takes two data files with timestamps and associates them   
    ''')
    parser.add_argument('first_file', help='first text file (format: timestamp data)')
    parser.add_argument('second_file', help='second text file (format: timestamp data)')
    parser.add_argument('--first_only', help='only output associated lines from first file', action='store_true')
    parser.add_argument('--offset', help='time offset added to the timestamps of the second file (default: 0.0)',default=0.0)
    parser.add_argument('--max_difference', help='maximally allowed time difference for matching entries (default: 0.02)',default=0.02)
    args = parser.parse_args()
 
    first_list = read_file_list(args.first_file)
    second_list = read_file_list(args.second_file)
 
    matches = associate(first_list, second_list,float(args.offset),float(args.max_difference))    
 
    if args.first_only:
        for a,b in matches:
            print("%f %s"%(a," ".join(first_list[a])))
    else:
        for a,b in matches:
            print("%f %s %f %s"%(a," ".join(first_list[a]),b-float(args.offset)," ".join(second_list[b])))
            
        

在ORBSLAM3文件夹中打开终端执行以下指令:

python3 ./Examples/RGB-D/associate.py ./rgbd_dataset_freiburg3_walking_xyz/rgb.txt ./rgbd_dataset_freiburg3_walking_xyz/depth.txt >./rgbd_dataset_freiburg3_walking_xyz/associations.txt

就可以得到示例数据集的associations.txt

运行RGBD-TUM数据集

在ORBSLAM3文件夹中打开终端执行以下指令:

./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt ./Examples/RGB-D/TUM3.yaml ./rgbd_dataset_freiburg3_walking_xyz rgbd_dataset_freiburg3_walking_xyz/associations.txt

其中TUM3.yaml为相机内参文件,注意数据集使用的是那个相机内参,rgbd_dataset_freiburg3_walking_xyz中“freiburg3”表示用的TUM3.yaml。
运行效果如下:
在这里插入图片描述

本篇文章主要参考以下文章:
1:https://blog.csdn.net/Prototype___/article/details/129286042
2:https://www.bilibili.com/read/cv24690326/
3:https://blog.csdn.net/weixin_43907136/article/details/130273186
4:https://blog.csdn.net/Welf688/article/details/124029171

  • 12
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值