【SLAM】【Windoes】ORB-SLAM2在windoes11上的详细安装教程

前言

paper:https://arxiv.org/pdf/1610.06475.pdf
githup::https://github.com/raulmur/ORB_SLAM2
githup(windoes):https://github.com/phdsky/ORBSLAM24Windows
ORB-SLAM2 是一个开源的同步定位与地图构建(Simultaneous Localization and Mapping, SLAM)系统,它能够在单目、双目以及RGB-D相机输入下工作,实现在未知环境中的机器人或移动设备进行实时定位和地图构建。
最近在windoes11上配置ORB-SLAM2运行环境时踩了很多坑,在这期间查阅了很多资料和博客,于是想对安装过程进行总结,方便自己反复查阅以及分享经验避免大家重复踩坑。

安装前的准备
安装Visual Studio,博主安装的是 Visual Studio 2019版本:

安装Cmake,博主安装的是Cmake 3.27.7版本:

安装git:


安装第三方库

# 通过git下载ORB_SLAM2_Windows源码到合适的路径下,需要科学上网
git clone https://github.com/phdsky/ORBSLAM24Windows.git

Eigen、Pangolin、DBoW2和g2o在ORBSLAM24Windows\Thirdparty文件夹中,后续博主会将其他第三方库也放到ORBSLAM24Windows\Thirdparty目录下,方便项目管理。

安装OpenCV

1.安装OpenCV可以选择下载opencv直接使用【官网地址】或者源码自定义安装【参考博文】。
opencv能否直接下载使用,需要对照官方提供的opencv的VC版本与主机上安装的VS版本是否匹配【VC与VS(visual studio) 的对应版本】,假如不匹配,一般进行源码编译。

博主选择下载opencv3.4.5源码进行编译,因为VC14和VC15与VS2019匹配,具体的编译流程不在赘述,建议参考上述链接中博主的另一篇博文,编译完成后在install文件夹内生成以下内容。

博主建议不要选择opencv4.0及以上,后续ORB-SLAM2编译会存在很多麻烦。

2.将install文件重命名为opencv(博主个人习惯),并拷贝到ORBSLAM24Windows\Thirdparty(博主建议)路径下:

打开opencv\OpenCVConfig.cmake文件,需要着重检查是否OpenCV_FOUND被设置成FALSE:

set(OpenCV_FOUND FALSE)

假设设置成FALSE需要设置成TRUE,否则将无法使用OpenCV库进行构建。

set(OpenCV_FOUND TRUE)

安装DBoW2

1.在ORBSLAM24Windows\Thirdparty(个人下载路径)目录下创建一个build文件夹:

2.以管理员身份运行cmake软件,where is the source code是DBoW2的文件夹位置,where to build the binaries是编译DBoW2保存的文件夹位置(新建的build路径),在左下角点击Configure。

选择对应vs的版本(博主是vs2019),系统选择x64,最后点右下角Finish:

3.显示Configuring done后,点击generate,显示generating done,成功完成cmake编译:

可能的错误:因为没有找到OpenCV的lib库:

解决方式:在OpenCV_DIR位置设置正确的路径即可,博主的路径为ORBSLAM24Windows\Thirdparty\opencv\lib:

4.点击open project,下用VS2019进入工程,配置好Release,X64,然后右键ALL_BUILD,点击生成:

也可以在build目录直接点击DBoW2.sln打开,是一样的效果


5.在ORBSLAM24Windows\Thirdparty\DBoW2\lib\Release路径下,能够看到如下的DBoW2.lib文件,代表已经生成完成:

可能出现的错误:编译器无法找到名为stdint-gcc.h的头文件。

解决方式:修改ORBSLAM24Windows\Thirdparty\DBoW2\DBoW2\FORB.cpp内容。

#include <stdint-gcc.h>
// 改为
#include <stdint.h>

安装Eigen3(可以跳过该步骤)

1.同样以管理员身份运行cmake软件,并在eigen文件夹下创建build文件夹,在左下角点击Configure,点击Generate:

CMAKE_INSTALL_PREFIX是编译安装后默认到系统路径下,博主自定义到 ORBSLAM24Windows\Thirdparty\eigen\Eigen3,因此后面需要手动添加,否则找不到路径


2.点击open project,配置好Release,X64,然后右键INSTALL,点击生成:

3.在ORBSLAM24Windows\Thirdparty\eigen\Eigen3生成输出:

安装g2o

1.同样以管理员身份运行cmake软件,并在g2o文件夹下创建build文件夹,在左下角点击Configure,点击Generate:

2.点击Open Project打开工程,右键单击 g2o 项目 --> 属性 -> C/C++ --> 预处理器–>预处理器定义,在最后一行末尾添加 WINDOWS–>单击应用并确定:
3.配置好Release,X64,然后右键ALL_BUILD,点击生成:

4.在ORBSLAM24Windows\Thirdparty\g2o\lib\Release路径下,能够看到如下的g2o.lib文件,代表已经生成完成:

安装Pangolin

1.同样以管理员身份运行cmake软件,并在Pangolin文件夹下创建build文件夹,在左下角点击Configure,点击Generate:

CMAKE_INSTALL_PREFIX是编译安装后默认到系统路径下,博主自定义到ORBSLAM24Windows\Thirdparty\Pangolin\Pangolin,因此后面需要手动添加,否则找不到路径


2.点击open project,配置好Release,X64,然后右键INSTALL,点击生成:

出现显示配置成功18个,有错误是关于pthread.lib的,直接可以忽略;

可能出现的错误:Pangolin库编译的时候需要git上下载一些依赖,可能下载不下来。

解决办法【参考博主的博文】:手动下载所需的依赖【百度云下载,提取码: x7w3 】,将CMakeLists.txt覆盖,并将解压后的各种依赖重命名xxxx-cmake。

3.在ORBSLAM24Windows\Thirdparty\Pangolin\lib\Release生成输出:

安装以及运行ORB-SLAM2

安装编译ORB-SLAM2

1.同样以管理员身份运行cmake软件,并在ORB-SLAM2文件夹下创建build文件夹,在左下角点击Configure,点击Generate:

根据个人安装路径设置:
OpenCV_DIR设置成ORBSLAM24Windows\Thirdparty\opencv\lib;
Pangolin_DIR设置成ORBSLAM24Windows\Thirdparty\Pangolin\build\src;
CMAKE_INSTALL_PREFIX是编译安装后默认到系统路径下,博主自定义设置成ORBSLAM24Windows\ORB_SLAM2。


2.点击open project,配置好Release,X64,然后右键ALL_BUILD,点击生成:

可能出现的问题:“monotonic_clock”: 不是 “std::chrono” 的成员。

解决方式:替换报错内容

// std::chrono::monotonic_clock
std::chrono::steady_clock

单目模式运行演示案例

TUM 数据集
数据下载链接,下载如下数据集

博主将数据集解压到在ORBSLAM24Windows\Examples\data目录下:

根据数据集要求: Examples/Monocular/TUM1.yaml 对应 freiburg1:

解压ORBSLAM24Windows\Vocabulary\ORBvoc.txt.tar.gz文件:

需要将ORBSLAM24Windows\Thirdparty\opencv\bin的opencv_world345.dll拷贝至ORBSLAM24Windows\Examples\Monocular\Release路径下:

执行以下命令显示效果:

# 进入ORBSLAM24Windows工程下
cd E:\ORBSLAM\ORBSLAM24Windows
# 执行命令查看运行效果
Examples\Monocular\Release\mono_tum.exe Vocabulary\ORBvoc.txt\ORBvoc.txt Examples\Monocular\TUM1.yaml Examples\data\rgbd_dataset_freiburg1_desk

3.RGBD模式模式运行演示案例

需额外associate.py添加到数据文件夹下:

博主对associate.py进行了修改,原始的associate.py只能在python2.0版本中运行。

import argparse
import sys
import os
import numpy

def read_file_list(filename):
    """
    Reads a trajectory from a text file.
    ...
    """
    with open(filename, 'r') as file_handle:  # 使用上下文管理器打开文件
        data = file_handle.read()
        lines = data.replace(",", " ").replace("\t", " ").split("\n")
        list_of_lines = [[v.strip() for v in line.split(" ") if v.strip() != ""] for line in lines if
                         len(line) > 0 and line[0] != "#"]
        list_of_lines = [(float(l[0]), l[1:]) for l in list_of_lines if len(l) > 1]
        return dict(list_of_lines)


def associate(first_list, second_list, offset, max_difference):
    """
    Associate two dictionaries of (stamp,data) tuples.
    ...
    """
    first_keys = list(first_list.keys())  # 将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, type=float)  # 显式指定类型转换
    parser.add_argument('--max_difference',
                        help='maximally allowed time difference for matching entries (default: 0.02)', default=0.02,
                        type=float)
    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, args.offset, args.max_difference)

    if args.first_only:
        for a, b in matches:
            print("%f %s" % (a, " ".join(first_list[a])))  # 使用print函数
    else:
        for a, b in matches:
            print("%f %s %f %s" % (a, " ".join(first_list[a]), b - args.offset, " ".join(second_list[b])))  # 使用print函数

个人理解:作用是使RGD和depth的数据做一个对齐,一 一对应。

# 在数据文件夹里执行命令
cd E:\ORBSLAM\ORBSLAM24Windows\Examples\data\rgbd_dataset_freiburg1_desk
python associate.py rgb.txt depth.txt > associate.txt
python associate.py associate.txt groundtruth.txt > associate_with_groundtruth.txt


需要将ORBSLAM24Windows\Thirdparty\opencv\bin的opencv_world345.dll拷贝至ORBSLAM24Windows\Examples\RGB-D\Release路径下:

执行以下命令显示效果

# 进入ORBSLAM24Windows工程下
cd E:\ORBSLAM\ORBSLAM24Windows
# 执行命令查看运行效果
Examples\RGB-D\Release\rgbd_tum.exe Vocabulary\ORBvoc.txt\ORBvoc.txt Examples\RGB-D\TUM1.yaml Examples\data\rgbd_dataset_freiburg1_desk Examples\data\rgbd_dataset_freiburg1_desk\associate.txt

总结

尽可能简单、详细的介绍ORB-SLAM2的在windoes11下的安装流程以及解决了安装过程中可能存在的问题。后续会根据自己学到的知识结合个人理解讲解ORB-SLAM2的原理和代码。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值