实验简介:
我是在虚拟机VMware上安装的,进行过多次的配置及安装,对于一些安装过程中的坑都有一些小心得相逢想给大家
参考文章:ORB-SLAM3配置及安装教程(2023.3)_orbslam3安装-CSDN博客
ORB-SLAM3配置安装及运行---Ubuntu20.04(2021年)-CSDN博客
致命错误:Eigen/Dense:没有那个文件或目录_eigen库报错找不到头文件但是右键能找到-CSDN博客在Ubuntu上安装ORBSLAM3与运行RGBD-TUM数据集_orb-slam3运行rgbd数据集-CSDN博客
一.准备工作
1.安装 gcc 和 g++ 环境:
sudo apt-get install gcc
sudo apt-get install g++
测试c++:
touch test.cpp
打开文件并输入
#include <iostream>
using namespace std;
int main()
{
cout << "HELLO WORLD!" << endl;
return 0;
}
在“test.cpp”文件目录中打开终端并输入:
g++ test.cpp -o test.out
通过以上编译得到test.out文件以后,可以直接把这个文件拖到Terminal上,通过按回车键运行,可以得到结果:HELLO WORLD! 就是成功了。
2.有些电脑用终端下载源码时下不下来,我把网站给大家放在下面了
点击Code然后download zip
3.安装git,vi编译器,cmake
sudo apt-get install git
sudo apt-get remove vim-common
sudo apt-get install vim
sudo apt-get install cmake
sudo apt-get install mlocate
二.安装Eigen3
1.安装源码
# github
git clone https://github.com/eigenteam/eigen-git-mirror
如果下载不了
可以直接从网站下Eigen3
也采用下面这个指令安装eigen3
sudo apt-get install libeigen3-dev
2.安装
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install
路径为/usr/local/include/eigen3/
3.测试
新建新建test-Eigen.cpp
touch test-Eigen.cpp
将以下代码复制进去
- #include <Eigen/Dense>
- #include <iostream>
- using namespace Eigen;
- using namespace Eigen::internal;
- using namespace Eigen::Architecture;
- using namespace std;
- int main()
- {
- Vector4d test1;
- test1<< 1,2,3,4;
- cout<<"test=\n"<<test1<<endl;
- cout<<"Test Success!"<<endl;
- return 0;
- }
在终端打开:
g++ test-Eigen.cpp -o test-Eigen.out
./test-Eigen.out
4.遇到的坑以及解决
1.
CMake Error at CMakeLists.txt:1 (project):
No CMAKE_CXX_COMPILER could be found.
解决方法:依次检查gcc -v g++ -v
看是否存在,不存在安装即可
2.
试运行Eigen时出现问题
运行g++ test-Eigen.cpp -o test-Eigen.out时
出现
test-Eigen.cpp:1:10: fatal error: Eigen/Dense: 没有那个文件或目录
1 | #include
| ^~~~~~~~~~~~~
compilation terminated.
分析:编译器会去 /usr/local/include 或者 /usr/include 目录找头文件,但找到的是eigen3,并没有Eigen和unsupported,因此需要建立一个软连接,链接到这两个文件夹即可
解决方法:
cd /usr/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported
或者
#移动头文件
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
三.安装Pangolin
1.安装源码
#github
git clone https://github.com/stevenlovegrove/Pangolin.git
如果下载不了
可以直接从网站下Pangolin
2.安装
安装依赖:
sudo apt install libgl1-mesa-dev
sudo apt install libglew-dev
sudo apt install cmake
sudo apt install libpython2.7-dev
sudo apt install pkg-config
sudo apt install libegl1-mesa-dev libwayland-dev libxkbcommon-dev wayland-protocols
sudo apt install libepoxy-dev
sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev
sudo apt-get install libdc1394-dev libraw1394-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev
3.编译安装
cd Pangolin
mkdir build
cd build
cmake ..
cmake --build .
4.测试Pangolin
在build目录下
make
cd examples
cd HelloPangolin
./HelloPangolin
出现正方形就是成功了!
5.遇到的坑以及解决
2.sudo apt-get install libjpeg-dev libpng16-dev libtiff5-dev libopenexr-dev
问题:然而下列软件包会取代它:
libpng-dev:i386
解决:
sudo apt-get install libpng-dev:i386
3.sudo apt-get update
W: GPG 错误:http://archive.ubuntu.com/ubuntu trusty Release: 由于没有公钥,无法验证下列签名: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
解决:
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3B4FE6ACC0B21F32
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 40976EAF437D05B5
四.安装opencv
(如果要安装opencv_contrib可以去看这篇conrtrib)
注明:opencv我配过好几个版本(3.4.3,4.4,4.5.5)要按照之后要装的搭配安装不然要重装
1.安装源码
OpenCV自己找适应的版本就好
点击source就可以下载了
2.安装
安装依赖
unzip opencv-x.x.x.zip
(x.x.x用自己下载的版本即好)
更新
sudo apt-get update
安装依赖
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
若是报错如下
error: unable to locate libjasper-dev 无法定位这个包libjasper-dev
先试试这个
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
若还是报错
error: unable to locate libjasper-dev
error: unable to locate libjasper1
去找更新命令中发现有个仓库缺少数字签名
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
将数字签名存储下来,再进行更新
sudo apt update
sudo apt install libjasper1 libjasper-dev
3.编译安装
cd opencv-x.x.x
mkdir build
cd build
cmake
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
执行命令后会自动下载一个ippicv库
但我安装的好几次都没成功,需要离线下载一个ippicv库
注意:需要将ippicv库单独拷贝下来放在文件夹下面
然后把你的OpenCV源文件中 /3rdparty/ippicv 文件夹下的 ippicv.cmake 中
第47行"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}/ippicv/" 改成你新下载的ippicv文件路径
我放的是opencv下面,所以我的路径是"file:///home/*****/opencv/ippicv"
(****指的是你的opencv的路径不知道的可以直接右键点击opencv文件夹查看属性可以看到复制黏贴即可)
再次进行编译cmake命令,就完成了编译
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make -j4
sudo make install
添加库路径
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
配置bash
sudo gedit /etc/bash.bashrc
在末尾粘贴如下两行代码
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
保存,执行如下命令使得配置生效
source /etc/bash.bashrc
更新
sudo updatedb
检测版本
pkg-config --modversion opencv
注意:OpenCV版本4以上的,默认不生成.pc文件,会出现找不到包的问题
4.遇到的坑以及解决
编译opencv时出现的错误
/home/changym/sources/opencv-4.4.0/modules/gapi/test/gapi_async_test.cpp:448:26: error: ‘sleep_for’ is not a member of ‘std::this_thread’
448 | std::this_thread::sleep_for(std::chrono::milliseconds{2});
| ^~~~~~~~~
解决: 在 gapi_async_tesr.cpp 中添加
#include <thread>
五.python
sudo apt install libpython2.7-dev
六.安装boost
1.安装源码
点击对应版本后选择后缀为(.tar.gz)即可
解压:
tar -xzvf boost_x_xx_x.tar.gz
(xxx即为版本号)
执行这个脚本
sudo ./bootstrap.sh
再执行这个脚本
sudo ./b2 install
七.安装libssl-dev
sudo apt-get install libssl-dev
八.安装和编译ORB-SLAM3
1.安装源码
2.编译安装
进入文件夹ORB_SLAM3中
先将第20行的11改成14
若是OpenCV3.4.3的别忘了把OpenCV的版本也改下
cd ORB_SLAM3
chmod +x build.sh
./build.sh
若是内存不足可以一步一步安装
没有提示错误则安装成功
echo "Configuring and building Thirdparty/DBoW2 ..."
cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
cd ../../g2o
echo "Configuring and building Thirdparty/g2o ..."
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j
cd ../../../
echo "Uncompress vocabulary ..."
cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
echo "Configuring and building ORB_SLAM3 ..."
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cd ..
make -j
3.遇到的坑以及解决
编译slam3时
#include <pangolin/pangolin.h>这句话报错
解决:
回到Pangolin文件夹的build文件夹下打开中终端然后执行
sudo make install
若是出现
make[2]: *** [CMakeFiles/ORB_SLAM3.dir/build.make:89:CMakeFiles/ORB_SLAM3.dir/src/LocalMapping.cc.o] 错误 1
make[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());
}
}
参考文章:ORB-SLAM3配置安装及运行---Ubuntu20.04(2021年)-CSDN博客
若是不行可以尝试删除build文件夹重新构建
九.数据集
我刚开始用的是mho1(mono_euroc)没成功后来经老师提点换了rgbd
RGBD-TUM数据集
https://vision.in.tum.de/data/datasets/rgbd-dataset/download(这几天网站服务器好像有问题打不开,前几天我还打得开,大家可以过段时间看看)
解压缩到ORBSLAM3文件夹中,以rgbd_dataset_freiburg1_desk为例
1.新建associate.py文件
touch associate.py
它从rgb.txt文件和 depth.txt 文件中读取时间戳,并通过查找最佳匹配来连接它们。
直接黏贴:
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_freiburg1_desk/rgb.txt ./rgbd_dataset_freiburg1_desk/depth.txt >./rgbd_dataset_freiburg1_desk/associations.txt
得到associations.txt
十.运行ORB-SLAM3
在ORBSLAM3中打开终端:
./Examples/RGB-D/rgbd_tum ./Vocabulary/ORBvoc.txt ./Examples/RGB-D/TUM1.yaml ./rgbd_dataset_freiburg1_desk ./rgbd_dataset_freiburg1_desk/associations.txt
若是出现段错误或者已终止请检查命令,其他博主的命令和我的不是很一样请仔细检查
若是没有区别,可以试试多运行几次可能就会好
十一.讨论
若遇到问题可以在评论区发出来一起讨论研究下