下载安装链接
下载ORB-SLAM3地址: git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git
eigen3多版本安装:https://blog.csdn.net/weixin_41756645/article/details/129570141
ORB-SLAM2中eigen3版本为:3.2.10版本
ORB-SLAM3中eigen3版本为:3.3.9版本
参考文档:https://blog.csdn.net/weixin_41756645/article/details/129570141
安装fmt 8.1.1版本:https://github.com/fmtlib/fmt/tags
安装Sophus 1.22.4版本:参考文档:地址
数据包地址:https://projects.asl.ethz.ch/datasets/doku.php?id=kmavvisualinertialdatasets
下载ORB-SLAM3
git clone https://github.com/UZ-SLAMLab/ORB_SLAM3.git
修改ORB-SLAM3源文件
ORB_SLAM3下CMakeLists.txt
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV 4.0 QUIET)
if(NOT OpenCV_FOUND)
find_package(OpenCV 2.4.3 QUIET)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV > 4.2 not found.")
endif()
endif()
find_package(Eigen3 REQUIRED)
DBoW2下CMakeLists.txt
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 ")
find_package(OpenCV 4.0 QUIET)
if(NOT OpenCV_FOUND)
find_package(OpenCV 2.4.3 QUIET)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV > 4.2 not found.")
endif()
endif()
g2o下CMakeLists.txt
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 ")
FIND_PACKAGE(Eigen3 REQUIRED)
將Examples_old中的ROS移動到Examples中
修改 Examples下CMakeLists.txt
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3 ")
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV 4.0 QUIET)
if(NOT OpenCV_FOUND)
find_package(OpenCV 2.4.3 QUIET)
if(NOT OpenCV_FOUND)
message(FATAL_ERROR "OpenCV > 4.2 not found.")
endif()
endif()
find_package(Eigen3 REQUIRED)
add_definitions(-DBOOST_ERROR_CODE_HEADER_ONLY)
add_definitions(-DBOOST_SYSTEM_NO_DEPRECATED)
set(Boost_NO_BOOST_CMAKE ON)
set(BOOST_ROOT "/usr/include")
在编译ros版本时候需要初始化ROS,在**~/.bashrc的最后一行加入以下代码,一定要添加到最後一行,否則報錯
sudo gedit ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/youzhu/ROS/catkin_modi/src/ORB_SLAM3/Examples/ROS
#保存退出
source ~/.bashrc
编译
编译ORB-SLAM3
cd ORB_SLAM3
chmod +x build.sh
./build.sh
在ORB_SLAM3中创建dataset
下载数据包放到dataset文件中:
下载数据包地址:http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/
wget http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_01_easy/MH_01_easy.bag
查看是否编译成功。运行命令
roscore
rosbag play --pause ./dataset/MH_01_easy.bag /cam0/image_raw:=/camera/image_raw /imu0:=/imu
rosrun ORB_SLAM3 Mono_Inertial Vocabulary/ORBvoc.txt Examples/Monocular-Inertial/EuRoC.yaml true
编译ROS下ORB-SLAM3
cd ORB_SLAM3
chmod +x build_ros.sh
./build_ros.sh
编辑过程中报错:ros版本编译,提示找不到sophus库,及 Sophus::SE3f, cv::MAT,Eigen::Vector3f
类型转换报错 #442
1:首先查看是否安装了Sophus 没有安装的话的现进行安装,安装前查看fmt是否安装,没有的话现安装fmt
安装成功后再进行编译
./build_ros.sh
2:/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/AR/ros_mono_ar.cc文件中cv::Mat Tcw = mpSLAM->TrackMonocular(cv_ptr->image,cv_ptr->header.stamp.toSec());
报错:
解决:
cv::Mat Tcw;
Sophus::SE3f Tcw_SE3f = mpSLAM->TrackMonocular(cv_ptr->image,cv_ptr->header.stamp.toSec());
Eigen::Matrix4f Tcw_Matrix = Tcw_SE3f.matrix();
3:文件:/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/AR/ros_mono_ar.cc文件中:error: ‘eigen2cv’ is not a member of ‘cv’
报错:
解决
#include <Eigen/Dense>
#include <opencv2/core/eigen.hpp>
#include <opencv2/opencv.hpp>
4:在/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/AR/ViewerAR.cc文件中:vPoints.push_back(pMP->GetWorldPos());
报错
cv::Mat WorldPos;
cv::eigen2cv(pMP->GetWorldPos(), WorldPos);
vPoints.push_back(WorldPos);
5:在/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/AR/ViewerAR.cc文件cv::Mat Xw = pMP->GetWorldPos();
报错
6:在/ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/AR/ViewerAR.cc文件error: ‘eigen2cv’ is not a member of ‘cv’
报错:
参考·链接:https://blog.csdn.net/m0_54539677/article/details/123480828
再进行编译
./build_ros.sh
使用D435i深度相机进行测试
在/home/youzhu/ROS/catkin_modi/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3文件中创建:MyD435i.yaml
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
Camera.type: "PinHole"
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 905.8228759765625
Camera.fy: 905.6454467773438
Camera.cx: 640.6072998046875
Camera.cy: 364.5034484863281
Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0
Camera.p3: 0.0
Camera.width: 720
Camera.height: 1280
# Camera frames per second
Camera.fps: 30.0
# IR projector baseline times fx (aprox.)
# bf = baseline (in meters) * fx, D435i的 baseline = 50 mm
Camera.bf: 50.0
# 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: 1000.0
#--------------------------------------------------------------------------------------------
# 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
PointCloudMapping.Resolution: 0.01
meank: 50
thresh: 2.0
修改ros接口
启动RealSense的ROS节点
realsense的ROS接口可以理解为一个读取数据并发布topic的节点,自己写ROS程序的时候订阅这个节点发出的topic即可
roslaunch realsense2_camera rs_camera.launch
查看这些节点
rostopic list
使用rqt_image_view订阅这些节点
也可以使用rqt_image_view订阅这些节点
修改rs_camera.launch,我的rs_camera.launch文件在:/home/youzhu/catkin_ws/src/realsense-ros/realsense2_camera/launch
目录中有的人是在:/opt/ros/noetic/share/realsense2_camera/launch中
再使用rqt_image_view订阅这些节点:
修改ORB_SLAM3/Examples/ROS/ORB_SLAM3/src/ros_mono.cc文件的订阅消息
message_filters::Subscriber<sensor_msgs::Image> left_sub(nh, "/camera/infra1/image_rect_raw", 1);
message_filters::Subscriber<sensor_msgs::Image> right_sub(nh, "/camera/infra2/image_rect_raw", 1);
再进行编译
./build_ros.sh
使用D435i相机运行ORB-SLAM3
roscore
roslaunch realsense2_camera rs_camera.launch
true:
是正在将关键帧轨迹保存到KeyFrameTrajectory_TUM_Format.txt。。。
正在将相机轨迹保存到FrameTrajectory_TUM_Format.txt。。。
正在将相机轨迹保存到FrameTrajectory_KITTI_Format.txt。。
rosrun ORB_SLAM3 Stereo ../../../Vocabulary/ORBvoc.txt MyD435i.yaml false