ROS工作空间内利用rgbd_dataset_freiburg2_pioneer_360数据集配置ORB_SLAM2

本文主要是介绍ROS工作空间内利用rgbd_dataset_freiburg2_pioneer_360数据集配置ORB_SLAM2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

ORB-SLAM2官方教程
一、准备工作:安装第三方依赖库
本人的依赖库均存放在文档目录里
在这里插入图片描述

1、安装Eigen

sudo apt install libeigen3-dev

在这里插入图片描述

2、安装Pangolin

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
sudo apt install libgl1-mesa-dev libglew-dev cmake
sudo apt install libpython2.7-dev python-pip
git submodule init && git submodule update
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
mkdir build
cd build
cmake ..
cmake --build .
sudo make install

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

3、安装Sophus

git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout a621ff
mkdir build
cd build
cmake ..
make

在这里插入图片描述
在这里插入图片描述
报错问题:
在make过程中会出现如下的错误,需要修改Sophus/sophus中的so2.cpp文件,之后重新make即可
在这里插入图片描述
在这里插入图片描述

4、安装OpenCV

git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.4.3
sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

在这里插入图片描述
在这里插入图片描述
报错问题:
在安装相关依赖时可能会出现如下错误,执行下面的命令:
在这里插入图片描述

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

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
接前面的步骤→

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j8
sudo make install

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
报错问题:
在make -j8过程中会出现如下的错误,需要修改gen_java.py中的文件,之后重新make即可
在这里插入图片描述
在这里插入图片描述

修改内容:assert path[-3:]!=’.in’,path修改为assert path[-4:]!=’.in’,path
重新编译后如果还报错,将f.wrtite(buf)修改为f.write(buf.encode(‘utf-8’))

5、安装PCL

sudo apt install libpcl-dev
sudo apt install pcl-tools

在这里插入图片描述

6、安装Ceres Solver

git clone https://github.com/ceres-solver/ceres-solver.git
cd ceres-solver
sudo apt install cmake libeigen3-dev
sudo apt install libgoogle-glog-dev libatlas-base-dev libsuitesparse-dev
mkdir build
cd build
cmake ..
make -j4
sudo make install

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

7、安装g2o

git clone https://github.com/RainerKuemmerle/g2o.git
cd g2o
sudo apt install cmake libeigen3-dev
sudo apt install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev

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

报错问题:
在安装相关依赖时可能会出现E:软件包libqglviewer-dev没有可安装候选的错误,执行下面的命令:

apt-cache search libqglviewer-dev
sudo apt-get install libqglviewer-dev-qt5

在这里插入图片描述
接前面的步骤→

mkdir build
cd build
cmake ..
make -j4
sudo make install

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

二、构建ORB-SLAM2库和示例
因为后期会将ORB_SLAM2和ROS关联运行,所以下述代码均存放在ros工作空间catkin_ws/src目录下进行相关测试,测试内容并没有涉及ROS相关功能,可以看成一个普通的文件夹
1、构建ORB-SLAM2库和示例

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2 && chmod +x build.sh && ./build.sh

在这里插入图片描述

在编译过程中可能会出现的问题及解决方案:
(1)
问题:error: ‘usleep’ was not declared in this scope usleep(3000)
在这里插入图片描述
解决:在如下的文件中的头文件上分别加上#include<unistd.h>
ORB_SLAM2/src/LocalMapping.cc
ORB_SLAM2/src/LoopClosing.cc
ORB_SLAM2/src/System.cc
ORB_SLAM2/src/Tracking.cc
ORB_SLAM2/src/Viewer.cc
ORB_SLAM2/Examples/Monocular/mono_euroc.cc
ORB_SLAM2/Examples/Monocular/mono_kitti.cc
ORB_SLAM2/Examples/Monocular/mono_tum.cc
ORB_SLAM2/Examples/RGB-D/rgbd_tum.cc
ORB_SLAM2/Examples/Stereo/stereo_euroc.cc
ORB_SLAM2/Examples/Stereo/stereo_kitti.cc
在这里插入图片描述
在这里插入图片描述
(2)
问题:CMakeFiles/Stereo.dir/build.make:227:recipe for target ‘…/Stereo’ failed
CMakeFiles/RGBD.dir/build.make:197: recipe for target ‘…/RGBD’ failed
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/RGBD.dir/all’ failed
CMakeFiles/Makefile2:104:recipe for target ‘CMakeFiles/Stereo.dir/all’ failed
解决:把ORB_SLAM2/Examples/ROS/ORB_SLAM2/文件夹下的CMakeLists.txt文件进行修改,在set(LIBS的最后加上-lboost_system
在这里插入图片描述
(3)
问题:ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc:233:9: error: ‘usleep’ was not declared in this scope usleep(mT*1000)
解决:在文件ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc开始处加上#include<unistd.h>
在这里插入图片描述

2、下载公开数据集
以rgbd_dataset_freiburg2_pioneer_360为例,从TUM下载压缩包,后解压到ORB_SLAM2/data文件夹中

cd ORB_SLAM2
mkdir data
cd data
tar zxvf rgbd_dataset_freiburg2_pioneer_360.tgz

在这里插入图片描述

3、下载associate.py测试工具放在orb_slam2/Examples/RGB-D/目录下面

cd ..
cd Example/RGB-D

associate.py中的详细内容如下:

#!/usr/bin/python
# Software License Agreement (BSD License)
#
# Copyright (c) 2013, Juergen Sturm, TUM
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above
#    copyright notice, this list of conditions and the following
#    disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of TUM nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Requirements: 
# sudo apt-get install python-argparse"""
The Kinect provides the color and depth images in an un-synchronized way. This means that the set of time stamps from the color images do not intersect with those of the depth images. Therefore, we need some way of associating color images to depth images.For this purpose, you can use the ''associate.py'' script. It reads the time stamps from the rgb.txt file and the depth.txt file, and joins them by finding the best matches.
"""import argparse
import sys
import os
import numpydef 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 nameOutput:dict -- dictionary of (stamp,data) tuples"""file = open(filename)data = file.read()lines = data.replace(","," ").replace("\t"," ").split("\n") 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) tuplessecond_list -- second dictionary of (stamp,data) tuplesoffset -- time offset between both dictionaries (e.g., to model the delay between the sensors)max_difference -- search radius for candidate generationOutput:matches -- list of matched tuples ((stamp1,data1),(stamp2,data2))"""first_keys = first_list.keys()second_keys = 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 matchesif __name__ == '__main__':# parse command lineparser = 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])))           

4、运行时间戳关联函数associate.py
目的是将rgb 图像序列和depth深度图的序列,进行时间上的关联。运行结束后,orb_slam2/Examples/RGB-D/目录下面会生成associations.txt文件。

python associate.py ../../data/rgbd_dataset_freiburg2_pioneer_360/rgb.txt ../../data/rgbd_dataset_freiburg2_pioneer_360/depth.txt > associations.txt

5、运行ORB_SLAM2
在ORB_SLAM2主目录上运行执行指令

cd ..
cd ..
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM2.yaml data/rgbd_dataset_freiburg2_pioneer_360 Examples/RGB-D/associations.txt

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

这篇关于ROS工作空间内利用rgbd_dataset_freiburg2_pioneer_360数据集配置ORB_SLAM2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/249644

相关文章

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

Maven的使用和配置国内源的保姆级教程

《Maven的使用和配置国内源的保姆级教程》Maven是⼀个项目管理工具,基于POM(ProjectObjectModel,项目对象模型)的概念,Maven可以通过一小段描述信息来管理项目的构建,报告... 目录1. 什么是Maven?2.创建⼀个Maven项目3.Maven 核心功能4.使用Maven H

SpringBoot多数据源配置完整指南

《SpringBoot多数据源配置完整指南》在复杂的企业应用中,经常需要连接多个数据库,SpringBoot提供了灵活的多数据源配置方式,以下是详细的实现方案,需要的朋友可以参考下... 目录一、基础多数据源配置1. 添加依赖2. 配置多个数据源3. 配置数据源Bean二、JPA多数据源配置1. 配置主数据

SpringBoot使用GZIP压缩反回数据问题

《SpringBoot使用GZIP压缩反回数据问题》:本文主要介绍SpringBoot使用GZIP压缩反回数据问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot使用GZIP压缩反回数据1、初识gzip2、gzip是什么,可以干什么?3、Spr

Spring 基于XML配置 bean管理 Bean-IOC的方法

《Spring基于XML配置bean管理Bean-IOC的方法》:本文主要介绍Spring基于XML配置bean管理Bean-IOC的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一... 目录一. spring学习的核心内容二. 基于 XML 配置 bean1. 通过类型来获取 bean2. 通过

如何使用Nginx配置将80端口重定向到443端口

《如何使用Nginx配置将80端口重定向到443端口》这篇文章主要为大家详细介绍了如何将Nginx配置为将HTTP(80端口)请求重定向到HTTPS(443端口),文中的示例代码讲解详细,有需要的小伙... 目录1. 创建或编辑Nginx配置文件2. 配置HTTP重定向到HTTPS3. 配置HTTPS服务器

SpringBoot中配置Redis连接池的完整指南

《SpringBoot中配置Redis连接池的完整指南》这篇文章主要为大家详细介绍了SpringBoot中配置Redis连接池的完整指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以... 目录一、添加依赖二、配置 Redis 连接池三、测试 Redis 操作四、完整示例代码(一)pom.

Linux内核参数配置与验证详细指南

《Linux内核参数配置与验证详细指南》在Linux系统运维和性能优化中,内核参数(sysctl)的配置至关重要,本文主要来聊聊如何配置与验证这些Linux内核参数,希望对大家有一定的帮助... 目录1. 引言2. 内核参数的作用3. 如何设置内核参数3.1 临时设置(重启失效)3.2 永久设置(重启仍生效

IDEA自动生成注释模板的配置教程

《IDEA自动生成注释模板的配置教程》本文介绍了如何在IntelliJIDEA中配置类和方法的注释模板,包括自动生成项目名称、包名、日期和时间等内容,以及如何定制参数和返回值的注释格式,需要的朋友可以... 目录项目场景配置方法类注释模板定义类开头的注释步骤类注释效果方法注释模板定义方法开头的注释步骤方法注

如何在Mac上安装并配置JDK环境变量详细步骤

《如何在Mac上安装并配置JDK环境变量详细步骤》:本文主要介绍如何在Mac上安装并配置JDK环境变量详细步骤,包括下载JDK、安装JDK、配置环境变量、验证JDK配置以及可选地设置PowerSh... 目录步骤 1:下载JDK步骤 2:安装JDK步骤 3:配置环境变量1. 编辑~/.zshrc(对于zsh