This article introduces the problems encountered in ORB_SLAM3 compilation and operation, especially the problems encountered in ORB_SLAM3 ROS compilation. Finally, it runs in an indoor environment by using the D435I.
The operating environment of this article is Ubuntu20.04 + ROS noetic.
1. ORB_SLAM3 depends on installation
ORB_SLAM3 depends on the installation. Some students like to come to Baidu and install it according to others’ introduction. Most of the time, errors will occur when doing so, because everyone’s computer environment is different (maybe different versions of the library are installed). In fact, the best way is to directly install the code in the warehouse according to the introduction of the readme, so there is really nothing to introduce about this part.
Specific reference: https://github.com/UZ-SLAMLab/ORB_SLAM3#readme
Note: Because the article will introduce ROS operation, install ROS by yourself.
Two, compile
Unfortunately, after completing the above installation step by step, I thought I could play directly and happily, but an error occurred when compiling. The main errors are as follows:
1.error: decay_t is not a member of std did you mean decay
The reason for the problem is that the author uses C++11 to compile, as can be seen from CMakeLists.txt, so you only need to replace the following lines with C++14 for C++11.
17行:CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
20行:set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
22行:message(STATUS "Using flag -std=c++14.")
28行:message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
2.Could not find a configuration file for package “OpenCV” that is compatible
with requested version “4.4”.
The problem is mainly opencv version problem. Check the opencv version you installed, and change cmake to the version you installed. Modify as follows
原:find_package(OpenCV 4.4)
修改后:find_package(OpenCV 3.4)
Among them, OpenCV 3.4 is the version I installed. If the lower version is available, readers can try it by themselves according to the version they installed.
Then you can have fun playing.
cd ORB_SLAM3
chmod +x build.sh
./build.sh
Normally there should be no errors.
3. ROS compilation
ROS compilation is the focus of this article. Because according to the introduction in the author's readme, just execute the following script directly,
gedit ~/.bashrc
export ROS_PACKAGE_PATH=${
ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples/ROS
chmod +x build_ros.sh
./build_ros.sh
After execution, it can be compiled successfully, but an error occurs./build_ros.sh
: line 3: cd: Examples/ROS/ORB_SLAM3: No such file or directory
mkdir: cannot create directory 'build': File exists
According to the path search, it is actually in Examples There is no ROS folder! ! !
Hey, you said it was cheating or not.
Next, we will start our operation. After several searches, we found that it is in Examples_old. So:
copy the ROS folder under the Examples_old folder to the Examples folder, and then compile, the following error will appear:
1. For the version compiled by C++11, replace C++11 with C++14 in the CMakeLists.txt file under the ROS/ORB_SLAM3 file.
2. Prompt that the sophus library cannot be found
In the CMakeLists.txt file, add
include_directories(
${
PROJECT_SOURCE_DIR}/…/…/…/Thirdparty/Sophus
)
3. Sophus::SE3f, cv::MAT, Eigen::Vector3f type conversion error, add the header file in the error file
#include <Eigen/Dense>
#include <opencv2/core/eigen.hpp>
4. Solve cv::Mat Tcw = mpSLAM->TrackMonocular(cv_ptr->image,cv_ptr->header.stamp.toSec()); error
Introduce the above two header files, then delete line 151 of ROS/ORB_SLAM3/src/AR/ros_mono_ar.cc and replace it with the following
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);
5. Solve vPoints.push_back(pMP->GetWorldPos()); error
Introduce the above two header files, then 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);
6. Solve cv::Mat Xw = pMP->GetWorldPos(); error
Introduce the above two header files, then delete line 530 of ROS/ORB_SLAM3/src/AR/ViewerAR.cc and replace it with the following
cv::Mat Xw;
cv::eigen2cv(pMP->GetWorldPos(), Xw);
So you can play happily again, and compile the above
gedit ~/.bashrc
export ROS_PACKAGE_PATH=${
ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples/ROS
chmod +x build_ros.sh
./build_ros.sh
Now there is no error.
3. Run the data set
1. peace3
(1) EuRoC stereo+Inertial test
euroc dataset
This test is based on binocular+imu running euroc dataset as an example./Examples/Stereo-Inertial/stereo_inertial_euroc
./Vocabulary/ORBvoc.txt ./Examples/Stereo-Inertial/EuRoC.yaml ./Examples/datasets/ MH_03_medium ./Examples/Stereo-Inertial/EuRoC_TimeStamps/MH03.txt
The results are as follows:
ps: Create a datasets folder in Examples and put the downloaded datasets in it.
(2) Running D435I
./Examples/Stereo-Inertial/stereo_inertial_realsense_D435i ./Vocabulary/ORBvoc.txt ./Examples/Stereo-Inertial/Realsense_D435i.yaml
For D435I camera settings and calibration, please refer to the series of articles
Realsense d435i driver installation, configuration and calibration
Realsense d435i internal reference and external reference Parameter calibration
completes slam combat from zero, taking Vins-Fusion as an example
2. slam3_ros
(1) EuRoC ros package + stereo + Inertial test
rosrun ORB_SLAM3 Stereo-Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/Realsense_D435i.yaml false
rosbag play MH_03_medium.bag
The running results are as follows:
Where: MH_03_medium.bag topic/imu0 /cam0/image_raw /cam1/image_raw
(2) Run your own recorded bag
rosrun ORB_SLAM3 Stereo-Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/EuRoC.yaml ./Examples/datasets/MH_03_medium.bag false
rosbag play room.bag
The running results are as follows:
where: room.bag contains the topic: /camera/imu /camera/infra1/image_rect_raw /camera/infra2/image_rect_raw
ps: Tips, according to the topic of your own recording package, change the corresponding subscription topic in lines 141-143 in ros_stereo_inertial.cc.
references
https://github.com/UZ-SLAMLab/ORB_SLAM3
https://blog.csdn.net/zhh2005757/article/details/122353772