ORB-SLAM3 configuration installation and ROS and script running---Ubuntu20.04
ORB-SLAM3 code download address: ORB-SLAM3 source code download
All operations are performed after completing all the operations in the following URL: The first thing to do after installing the Ubuntu system.
本文是总结的比较完善和直接的过程。
In fact, some problems were encountered during the entire operation, and some summaries were also made, which were recorded in the article
ORB- Among the problems and solutions encountered during the SLAM3 reproduction process,
it is recommended to focus on this article first, and then refer to the problem solutions after problems arise.
1. Install required dependencies and packages
After installing ROS with one click, you only need to install Pangolin, and all other requirements are already there.
Just execute the following commands in sequence:
#依赖项
sudo apt-get install libglew-dev
sudo apt-get install cmake
sudo apt-get install libpython2.7-dev
sudo apt-get install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libswscale-dev libavdevice-dev
sudo apt-get install libdc1394-22-dev libraw1394-dev
sudo apt-get install libjpeg-dev libpng-dev libtiff5-dev libopenexr-dev
#下载编译
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
cmake --build .
sudo make install
What is downloaded in this way is Pangolin0.8. It can be used normally in ORB-SLAM3.
2. Modify code and file content
Since the versions of many libraries are different, some codes need to be changed.
Here I declare my environment:
Ubuntu20.04
Opencv4.2.0
C++11
Eigen3.3.7
Python3.8.10
Pangolin0.8
2.1 Modification of CMakeLists.txt file
- Modification of /home/xiaoduan/project/source2/orb_slam3/CMakeLists.txt file
gedit /home/xiaoduan/project/source2/orb_slam3/CMakeLists.txt
#第33行Opencv的版本改为4
#第41行Eigen的版本改为3
- Modification of /home/xiaoduan/project/source2/orb_slam3/Examples_old/ROS/ORB_SLAM3/CMakeLists.txt file
gedit /home/xiaoduan/project/source2/orb_slam3/Examples_old/ROS/ORB_SLAM3/CMakeLists.txt
The changes are as follows:
- The version of Opencv in line 33 is changed to 4
- Line 41 Eigen's version is changed to 3
- Line 49, add ${PROJECT_SOURCE_DIR}/…/…/…/Thirdparty/Sophus
2.2 Modification of monocular visualization code
gedit /Examples/Monocular/mono_euroc.cc
change content:
第83行中的false改为true
2.3 Modification of environment configuration files
gedit ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples_old/ROS
source ~/.bashrc
Note: ${ROS_PACKAGE_PATH} in the second command is the path of your own file.
2.4 Modification of source code
There is an AR folder under src in ORB_SLAM3. Some contents in it will cause the compilation of the ros executable file. Make the following modifications:
- Add the following two header files:
#include <Eigen/Dense>
#include <opencv2/core/eigen.hpp>
- Delete line 151 of ROS/ORB_SLAM3/src/AR/ros_mono_ar.cc and replace it with the following content
cv::Mat Tcw;
Sophus::SE3f Tcw_SE3f = mpSLAM->TrackMonocular(cv_ptr->image,cv_ptr->header.stamp.toSec());
Eigen::Matrix4f Tcw_Matrix = Tcw_SE3f.matrix();
cv::eigen2cv(Tcw_Matrix, Tcw);
- Delete line 409 of ROS/ORB_SLAM3/src/AR/ViewerAR.cc and replace it with the following
cv::Mat WorldPos;
cv::eigen2cv(pMP->GetWorldPos(), WorldPos);
vPoints.push_back(WorldPos);
- Delete line 409 of ROS/ORB_SLAM3/src/AR/ViewerAR.cc and replace it with the following
cv::Mat Xw;
cv::eigen2cv(pMP->GetWorldPos(), Xw);
3. Compilation of ORB-SLAM3
3.1 Build ORB-SLAM3 library
Just execute the following commands in order:
cd ORB_SLAM3
chmod +x build.sh
./build.sh
3.2 Generate ROS nodes
Execute the following command:
cd Examples_old/ROS/ORB_SLAM3
chmod +x build_ros.sh
./build_ros.sh
4. Operation of ORB-SLAM3
4.1 Running in non-ROS environment
4.1.1 EuROC data set
The visual inertial data set collected by the micro-aircraft includes simultaneous measurement data of binocular cameras and IMU and the true value of pose.
The data set needs to be downloaded from MH_01_easy.zip. The download address is: MH_01_easy.zip download address
. Unzip the data set and name it MH01.
Run the command:
Note: ${dir} in the command is the storage path of personal data
- Pure monocular:
cd Examples
./Monocular/mono_euroc ../Vocabulary/ORBvoc.txt ./Monocular/EuRoC.yaml ${
dir}/MH01 ./Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono
- Pure binocular:
./Examples/Stereo/stereo_euroc ./Vocabulary/ORBvoc.txt ./Examples/Stereo/EuRoC.yaml ${
dir}/MH01 ./Examples/Stereo/EuRoC_TimeStamps/MH01.txt dataset-MH01_stereo
- Monocular inertial navigation:
./Examples/Monocular-Inertial/mono_inertial_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular-Inertial/EuRoC.yaml ${
dir}/MH01 ./Examples/Monocular-Inertial/EuRoC_TimeStamps/MH01.txt dataset-MH01_monoi
- Binocular inertial navigation:
./Examples/Stereo-Inertial/stereo_inertial_euroc ./Vocabulary/ORBvoc.txt ./Examples/Stereo-Inertial/EuRoC.yaml ${
dir}/MH01 ./Examples/Stereo-Inertial/EuRoC_TimeStamps/MH01.txt dataset-MH01_stereoi
4.1.2 TUM VI data set
The cameras and IMU sensors used are time synchronized in hardware.
The provided image has a high dynamic range and has been photometrically calibrated in advance. It is collected with a frame rate of 20Hz and a resolution of 1024 pixels * 1024 pixels. The three-axis IMU sampling frequency is 200Hz and can measure acceleration and angular velocity.
You need to download the datasets dataset-room1_512_16 and rgbd_dataset_freiburg1_desk. Download address: TUM data set download
- Pure monocular:
cd Examples
./Monocular/mono_tum_vi ../Vocabulary/ORBvoc.txt Monocular/TUM_512.yaml ${
dir}/dataset-room1_512_16/mav0/cam0/data Monocular/TUM_TimeStamps/dataset-room1_512.txt dataset-room1_512_mono
- Pure binocular:
./Stereo/stereo_tum_vi ../Vocabulary/ORBvoc.txt Stereo/TUM_512.yaml ${
dir}/dataset-room1_512_16/mav0/cam0/data /home/sangfor/2023/bro_ws/dataset-room1_512_16/mav0/cam1/data Stereo/TUM_TimeStamps/dataset-room1_512.txt dataset-room1_512_stereo
- Monocular inertial navigation:
./Monocular-Inertial/mono_inertial_tum_vi ../Vocabulary/ORBvoc.txt Monocular-Inertial/TUM_512.yaml ${
dir}/dataset-room1_512_16/mav0/cam0/data Monocular-Inertial/TUM_TimeStamps/dataset-room1_512.txt Monocular-Inertial/TUM_IMU/dataset-room1_512.txt dataset-room1_512_monoi
- Binocular inertial navigation:
./Monocular-Inertial/mono_inertial_tum_vi ../Vocabulary/ORBvoc.txt Monocular-Inertial/TUM_512.yaml ${
dir}/dataset-room1_512_16/mav0/cam0/data Monocular-Inertial/TUM_TimeStamps/dataset-room1_512.txt Monocular-Inertial/TUM_IMU/dataset-room1_512.txt dataset-room1_512_monoi
- RGB-D:
./Examples/RGB-D/rgbd_tum Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml ${
dir}/rgbd_dataset_freiburg1_desk /home/sangfor/2023/bro_ws/rgbd_dataset_freiburg1_desk/associations.txt
4.2 Running in ROS environment
First, open 三个
a terminal
and run it on the first terminal roscore
. Then on the remaining two terminals, run the following commands:
- Pure monocular:
rosrun ORB_SLAM3 Mono Vocabulary/ORBvoc.txt Examples/Monocular/EuRoC.yaml
rosbag play MH_01_easy.bag /cam0/image_raw:=/camera/image_raw
- Pure binocular:
rosrun ORB_SLAM3 Stereo Vocabulary/ORBvoc.txt Examples/Stereo/EuRoC.yaml false
rosbag play MH_01_easy.bag /cam0/image_raw:=/camera/left/image_raw /cam1/image_raw:=/camera/right/image_raw
- Monocular inertial navigation:
rosrun ORB_SLAM3 Mono_Inertial Vocabulary/ORBvoc.txt Examples/Monocular-Inertial/EuRoC.yaml
rosbag play MH_01_easy.bag
- Binocular inertial navigation:
rosrun ORB_SLAM3 Stereo_Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/EuRoC.yaml false
rosbag play MH_01_easy.bag /cam0/image_raw:=/camera/left/image_raw /cam1/image_raw:=/camera/right/image_raw /imu0:=/imu
- RGB-D:
First download the data set: rgbd_dataset_freiburg1_xyz.bag, fr1/xyz select more info to find the bag file, and then download it.
The download address is the download URL of the data set that has been given by JianzhengTUM
.
rosrun ORB_SLAM3 RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/TUM1.yaml
rosbag play rgbd_dataset_freiburg1_xyz.bag
The execution of each command will have a visual interface, as shown in the figure below: