一、使用声明
该文章主要是用于自用,可能存在诸多不合理的格式与文章结构性问题,同时还会存在由于个人能力有限导致的错误。为了方便编辑,大部分的解决方案都只附上了链接,如果涉及到授权问题,请及时私信我。
该文章涉及到的问题,可能不具备广泛性,同时也没有收集所有问题,欢迎补充。
二、orbslam2的安装与常见编译失败问题
2.1 orbslam2的安装
由于网上安装orbslam2的教程非常多,因此这里直接附上链接:
orbslam2 安装与运行_orbslam2安装-CSDN博客
2.2常见编译失败问题
2.2.1 opencv版本问题
由于我的Ubuntu20事先已经安装好了ros noetic,因此其自带的opencv库是4.2.0版本的。在编译orbslam2时会找不到库,目前有两套解决方案:
方案一:更改CMake文件中的find_package(OpenCV 3 QUIET)为find_package(OpenCV 4 QUIET),此举还需要去更改源文件中的相关opencv源代码。虽然相对来说比较方便,但是暂时没有采用此方式。
方案二:安装一个opencv3.4.0,此举会涉及到多版本opencv管理的问题。但是,一般来说在cmake文件中为opencv设定好版本(如:find_package(OpenCV 3 QUIET)),基本可以解决此问题。opencv的安装以及多版本管理见以下链接:
ubuntu 安装Opencv4版本后安装Opencv3,并在项目中区分使用_ubutu20自带opencv4,现在要安装opencv3-CSDN博客
注:其中,在编译opencv3的时候还遇到了一个比较离谱的报错:make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:56...
附上解决方案:
Ubuntu20.04 安装 OpenCV3 过程中遇到的各种问题及其解决办法_opencv安装失败ubuntu-CSDN博客树莓派安装opencv报错:make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/build.make:56...-CSDN博客
2.2.2编译时遇到的各种报错解决方案
1、在编译cmake文件时,出现下图所示情况,描述为未找到Eigen3库
Make Error at CMakeLists.txt:42 (find_package):
Found package configuration file:
/usr/local/lib/cmake/Pangolin/PangolinConfig.cmake
but it set Pangolin_FOUND to FALSE so package "Pangolin" is considered to
be NOT FOUND. Reason given by package:
Pangolin could not be found because dependency Eigen3 could not be found.
只需要cmake文件中,加上一个NO_MODULE即可。
find_package(Eigen3 REQUIRED NO_MODULE)
三、双目EuRoC数据集的制作
3.1最简EuRoC数据集的结构形式
├── cam0
├── cam1
├── EuRoC.yaml
└── timestamps.txt
1、cam0与cam1文件夹中分别以.png的格式存放左目右目的图片,图片名称为时间戳数据,单位是纳秒。并且左右目的图片数量要一致,对应的图像名称也要一致。
2、EuRoC.yaml填写相机的相关参数、orb特征点相关参数,下文会详细介绍如何填写EuRoC.yaml。
3、timestamps.txt填写图片的时间戳 ,其形式如下图所示:(下文会介绍如何制作这种txt文件以及如何从bag中提取左右目图片)
1722760763161108255
1722760763194428205
1722760763227728367
1722760763261048317
1722760763294348240
1722760763327668190
1722760763360988140
1722760763394288301
1722760763427608252
1722760763460928202
1722760763494238138
1722760763527548313
1722760763560868263
1722760763594178200
1722760763627488136
1722760763660808325
1722760763694108248
1722760763727428198
1722760763760728359
1722760763794048309
1722760763827368259
1722760763860678196
1722760763893988371
1722760763927308321
1722760763960618258
1722760763993928194
1722760764027248144
1722760764060558319
3.2 EuRoC.yaml文件
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV)
#1.如果相机的左右目参数基本一致,则只需要填以下参数。
#但若左右目参数不一致,个人认为,这组参数一般需要填左目的参数。
#这组参数在tracking线程调用
Camera.fx: 435.2046959714599
Camera.fy: 435.2046959714599
Camera.cx: 367.4517211914062
Camera.cy: 252.2008514404297
Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0
Camera.width: 752
Camera.height: 480
# Camera frames per second
Camera.fps: 20.0
# stereo baseline times fx 注:Camera.bf=基线长度(单位:米)*Camera.fx(单位:像素)
Camera.bf: 47.90639384423901
# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
# Close/Far threshold. Baseline times.
#该参数为远点近点的判断阈值,填写的参数是基线的倍数,网上说一般填写40(倍)比较安全
ThDepth: 35
#--------------------------------------------------------------------------------------------
# Stereo Rectification. Only if you need to pre-rectify the images.
# Camera.fx, .fy, etc must be the same as in LEFT.P
#--------------------------------------------------------------------------------------------
#2.如果双目相机左右目有一定的差异性(如内参、畸变模型有差别),则需要填下以下参数。
#这些参数将在main函数中由loadimage函数调用
# 相机拍摄的图像尺寸
LEFT.height: 480
LEFT.width: 752
# 畸变系数
LEFT.D: !!opencv-matrix
rows: 1
cols: 5
dt: d
data:[-0.28340811, 0.07395907, 0.00019359, 1.76187114e-05, 0.0]
# 相机内参
LEFT.K: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [458.654, 0.0, 367.215,
0.0, 457.296, 248.375,
0.0, 0.0, 1.0]
# 在立体校正过程中,相机为实现共面过程中所需要进行的旋转
LEFT.R: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [0.999966347530033, -0.001422739138722922, 0.008079580483432283,
0.001365741834644127, 0.9999741760894847, 0.007055629199258132,
-0.008089410156878961, -0.007044357138835809, 0.9999424675829176]
# 在立体校正过程后,相机在新坐标系下的投影矩阵
LEFT.P: !!opencv-matrix
rows: 3
cols: 4
dt: d
data: [435.2046959714599, 0, 367.4517211914062, 0, 0, 435.2046959714599, 252.2008514404297, 0, 0, 0, 1, 0]
RIGHT.height: 480
RIGHT.width: 752
RIGHT.D: !!opencv-matrix
rows: 1
cols: 5
dt: d
data:[-0.28368365, 0.07451284, -0.00010473, -3.555907e-05, 0.0]
RIGHT.K: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [457.587, 0.0, 379.999, 0.0, 456.134, 255.238, 0.0, 0.0, 1]
RIGHT.R: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [0.9999633526194376, -0.003625811871560086, 0.007755443660172947, 0.003680398547259526, 0.9999684752771629, -0.007035845251224894, -0.007729688520722713, 0.007064130529506649, 0.999945173484644]
RIGHT.P: !!opencv-matrix
rows: 3
cols: 4
dt: d
data: [435.2046959714599, 0, 367.4517211914062, -47.90639384423901, 0, 435.2046959714599, 252.2008514404297, 0, 0, 0, 1, 0]
#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------
#每帧的特征点数量
# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1200
# ORB Extractor: Scale factor between levels in the scale pyramid
ORBextractor.scaleFactor: 1.2
#金字塔层数
# ORB Extractor: Number of levels in the scale pyramid
ORBextractor.nLevels: 8
# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
#提取特征点的最高与最低门槛
# You can lower these values if your images have low contrast
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7
#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500
3.3使用python脚本提取bag包中的图片与timestamps.txt时间戳文件
该脚本可以将指定的bag包中的话题提取到指定的文件夹中,同时还会提取出一个已经满足EuRoC格式的timestamps.txt文件。
# coding:utf-8
import roslib
import rosbag
import rospy
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
path = '/media/drone/SAMSUNG/drone_bag/cam1/' # ****存放图片的位置
class ImageCreator():
def __init__(self):
self.bridge = CvBridge()
timestamps_file = open(path + 'timestamps.txt', 'w') # 用于存储时间戳的txt文件
with rosbag.Bag('1-4-forst.bag', 'r') as bag: # ****要读取的bag文件
for topic, msg, t in bag.read_messages():
if topic == "/mynteye/right/image_mono": # 图像的topic
#if topic == "/mynteye/right/image_color": # ****图像的topic
#if topic == "/cam1/image_raw": # 图像的topic <- 数据集
try:
cv_image = self.bridge.imgmsg_to_cv2(msg, "bgr8")
except CvBridgeError as e:
print(e)
timestr = "%.19d" % msg.header.stamp.to_nsec() # 19位时间戳,单位为纳秒
timestamps_file.write(timestr + '\n') # 将时间戳写入txt文件
image_name = timestr + ".png" # 图像命名:时间戳.png
cv2.imwrite(path + image_name, cv_image) # 保存为PNG格式
timestamps_file.close() # 关闭txt文件
if __name__ == '__main__':
rospy.init_node('image_creator_node')
try:
image_creator = ImageCreator()
except rospy.ROSInterruptException:
pass
3.4运行数据集
cd orbslam2 //进入orbslam2的文件夹内
./Examples/Stereo/stereo_euroc arg[0] arg[1] arg[2] arg[3] arg[4]
例子:
./Examples/Stereo/stereo_euroc Vocabulary/ORBvoc.txt Examples/Stereo/EuRoC.yaml /media/drone/SAMSUNG/drone_bag/euroc1-4-forst/cam0 /media/drone/SAMSUNG/drone_bag/euroc1-4-forst/cam1 /media/drone/SAMSUNG/drone_bag/euroc1-4-forst/timestamps.txt
对各个参数的解释:
arg[0]:BOW字典文件:ORBvoc.txt
arg[1]:相机参数的配置文件:EuRoC.yaml
arg[2]:左目图像路径
arg[3]:右目图像路径
arg[4]:时间戳文件:timestamps.txt