环境:
最开始用的是源码是ORB-SLAM3 的1.0版本,但是编译的时候出错太多了,超出了能力范围,更换了0.4 beta版本,但是这个版本在运行的时候会直接segmentation fault(core dump),尝试无果后,又换了0.3 版本,终于成功运行。
编译没有使用官方的build.sh文件
在编译之前,最好进入ThirdParty文件夹中的g2o.中,把CMAKELISTS中的指定的eigen3 3.1.0的版本号删除
还有,orbslam3的CMAKELists文件中的eigen版本号最好也给删掉。
然后编译,首先把ThirdParty中的g2o以及DBoW编译了
cd DBoW/g2o
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release
make -j8
然后回到ORB-SLAM3的根目录下,将ORB-SLAM3进行编译,编译步骤同上
接下来尝试运行:
首先下载数据集,我使用的是MH_04,下载链接在这里:EuRocs数据集…
然后别忘了Vocabulary文件中的词典文件解压
按照ORB-SLAM3双目的启动参数要求如下:
Usage:
./stereo_inertial_euroc
path_to_vocabulary # 字典文件
path_to_settings # 参数设置文件
path_to_sequence_folder_1 # 影像序列文件夹路径
path_to_times_file_1 # 对应的时间戳文件
save_file_name
进入stereo-inertial 文件下运行,注意路径就好
./stereo_inertial_euroc ../../Vocabulary/ORBvoc.txt ./EuRoC.yaml ../../../Datasets/MH_04_difficult ./EuRoC_TimeStamps/MH04.txt stereo-inertialtest
经过以上步骤之后,直接进入/Examples/ROS/ORB_SLAM3
文件夹下,和上面的编译方法一样,直接按照标准的编译流程走就行,不过在这之前,现要将SLAM的ROS路径添加到环境变量中,首先sudo gedit ~./bashrc
,在打开的文件夹下输入:
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/juno/Projects/orb_slam3-v0.3-beta/Examples/ROS
路径要改成自己的路径,保存退出后别忘了source ~/.bashrc
然后就可以直接编译了:
cd Examples/ROS/ORB_SLAM3
mkdir build && cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j8
碰到了以下错误:
[rosbuild] Error from directory check: /opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py /home/juno/Projects/ORB_SLAM3-0.4-beta/Examples/ROS/ORB_SLAM3
1
Traceback (most recent call last):
File "/opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py", line 46, in <module>
raise Exception
Exception
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/private.cmake:102 (message):
[rosbuild] rospack found package "ORB_SLAM3" at "", but the current
directory is
"/home/juno/Projects/ORB_SLAM3-0.4-beta/Examples/ROS/ORB_SLAM3". You
should double-check your ROS_PACKAGE_PATH to ensure that packages are found
in the correct precedence order.
Call Stack (most recent call first):
/opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:177 (_rosbuild_check_package_location)
CMakeLists.txt:4 (rosbuild_init)
-- Configuring incomplete, errors occurred!
See also "/home/juno/Projects/ORB_SLAM3-0.4-beta/Examples/ROS/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found. Stop.
执行以下语句解决:
sudo ln -s /home/juno/Projects/orb_slam3-v0.3-beta/Examples/ROS/ORB_SLAM3 /opt/ros/melodic/share/ORB_SLAM3
编译成功后尝试运行Stereo节点,首先打开ROS Master:roscore
首先使用rosbag命令查看bag文件的话题名称:
rosbag info MH_04_difficult.bag
显示如下:
path: /home/juno/Projects/Datasets/MH_04_difficult.bag
version: 2.0
duration: 1:42s (102s)
start: Jun 25 2014 03:28:47.33 (1403638127.33)
end: Jun 25 2014 03:30:29.91 (1403638229.91)
size: 1.4 GB
messages: 25855
compression: none [1356/1356 chunks]
types: geometry_msgs/PointStamped [c63aecb41bfdfd6b7e1fac37c7cbe7bf]
sensor_msgs/Image [060021388200f6f0f447d0fcd9c64743]
sensor_msgs/Imu [6a62c6daae103f4ff57a132d6f95cec2]
topics: /cam0/image_raw 2033 msgs : sensor_msgs/Image
/cam1/image_raw 2032 msgs : sensor_msgs/Image
/imu0 20320 msgs : sensor_msgs/Imu
/leica/position 1470 msgs : geometry_msgs/PointStamped
首先打开ROS Master,
可以看出话题名称为/cam0/image_raw
和/cam1/image_raw
,所以需要将原代码文件中的相关话题给改掉:
然后重新编译,或者也可以使用下面的命令将话题名转换一下,可以免去编译,新打开两个终端,分别输入:
rosrun topic_tools throttle messages /cam0/image_raw 20.0 /camera/left/image_raw
rosrun topic_tools throttle messages /cam1/image_raw 20.0 /camera/right/image_raw
回放rosbag:
rosbag play MH_03_medium.bag
启动stereo节点
rosrun ORB_SLAM3 Stereo /home/juno/Projects/orb_slam3-v0.3-beta/Vocabulary/ORBvoc.txt /home/juno/Projects/orb_slam3-v0.3-beta/Examples/Stereo/EuRoC.yaml true
realsense-viewer
roslaunch realsense2_camera rs_camera.launch
使用rostopic list
查看这些节点
也可以使用rqt_image_view
订阅这些节点
另外需要注意的是,前面提到D435i是支持双目的红外影像输出的,但是它默认是关闭这一选项的,也就是说它不会有双目红外影像的Topic。我们需要在对应的Launch文件中修改相关参数,就可以获得红外影像了。具体如下。
找到rs_camera.launch
,将这三个参数全部设为true
这样,重新运行的时候就会出现这个话题了:
D435i相机在出厂时有一个默认的内参。查看方式有非常简单,在运行D435i以后,我们可以在Topic列表中看到很多叫camera_info的Topic,这些Topic就是对应的相机内参等参数。如下,查看的是RGB相机的参数。
rostopic echo /camera/color/camera_info
---
header:
seq: 835
stamp:
secs: 1646790784
nsecs: 399462700
frame_id: "camera_color_optical_frame"
height: 720
width: 1280
distortion_model: "plumb_bob"
D: [0.0, 0.0, 0.0, 0.0, 0.0]
K: [921.84423828125, 0.0, 630.59033203125, 0.0, 921.9102783203125, 366.97906494140625, 0.0, 0.0, 1.0]
R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P: [921.84423828125, 0.0, 630.59033203125, 0.0, 0.0, 921.9102783203125, 366.97906494140625, 0.0, 0.0, 0.0, 1.0, 0.0]
binning_x: 0
binning_y: 0
roi:
x_offset: 0
y_offset: 0
height: 0
width: 0
do_rectify: False
其中,K就是我们得到的内参矩阵写成了向量模式: K = [ f x , 0 , c x , 0 , f y , c y , 0 , 0 , 1 ] K=[f_x,0,c_x,0,f_y,c_y,0,0,1] K=[fx,0,cx,0,fy,cy,0,0,1],
根据Intel Realsense官方手册(link…)
相机的baseline=50mm,根据公式: b f = b a s e l i n e ( i n m e t e r s ) × f x bf= baseline (in\ meters) \times fx bf=baseline(in meters)×fx
可以算出我的相机参数:
b f = 0.05 × 921.84423828125 = 46.0922119140625 bf=0.05\times921.84423828125=46.0922119140625 bf=0.05×921.84423828125=46.0922119140625
将yaml文件中的参数按照自己相机的这些参数修改,基本上只需要修改相机内参以及图像的宽高。
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
Camera.type: "PinHole"
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 921.84423828125
Camera.fy: 921.9102783203125
Camera.cx: 630.59033203125
Camera.cy: 366.97906494140625
Camera.k1: 0.262383
Camera.k2: -0.953104
Camera.p1: -0.005358
Camera.p2: 0.002628
Camera.k3: 1.163314
Camera.width: 848
Camera.height: 480
# Camera frames per second
Camera.fps: 30.0
# IR projector baseline times fx (aprox.)
Camera.bf: 46.0922119140625
# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
# Close/Far threshold. Baseline times.
ThDepth: 40.0
# Deptmap values factor
DepthMapFactor: 5000.0 # 1.0 for ROS_bag
#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------
# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000
# 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
运行
roscore
roslaunch realsense2_camera rs_camera.launch
rosrun ORB_SLAM3 Stereo ../../../Vocabulary/ORBvoc.txt d435i.yaml false
参考: Intel RealSense D435i:简介、安装与使用(ROS、Python)
待续。。。