Realsense ROS D435i ORB_SLAM2

 

 

 

注:在执行./build.sh之前先在 /ORB_SLAM2/include/System.h文件开头的包含声明中添加#include <unistd.h>,不然会编译时会报错error: usleep is not declared in this scope

 

 

 

安装eigen

cd eigen
mkdir build
cd build
cmake ..
sudo make install  

  

 

sudo apt-get install libsuitesparse-dev

  

 

 

cd ORB_SLAM2
./build.sh

  

 

cd
vim .bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:~/ORB_SLAM2/Examples/ROS
source .bashrc

  

错误

 

上述步骤中在执行./build_ros.sh会出现关于boost库的错误,在/ORB_SLAM2/Examples/ROS/ORB-SLAM2/CMakeLists.txt文件下修改,按照下述位置加上-lboost_system,然后重新执行./build_ros.sh

// CMakeLists.txt文件部分内容节选如下
set(LIBS 
${OpenCV_LIBS} 
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
-lboost_system             // 此句加在这里
)

  

 

 

cd ORB_SLAM2 
chmod +x build_ros.sh
./build_ros.sh

  

 获取相机参数

roslaunch realsense2_camera rs_rgbd.launch
#新开终端运行以下命令:
rostopic echo /camera/color/camera_info

  

 

在ORB_SLAM2/Examples/RGB-D/下新建D435i.yaml文件,内容根据上述终端输出的参数修改

%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV) 

Camera.fx: 612.8856811523438
Camera.fy: 612.9019775390625
Camera.cx: 322.271240234375
Camera.cy: 244.7898712158203

Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0
Camera.p3: 0.0

Camera.width: 640
Camera.height: 480

# 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: 30.797   

# 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

  

 

 

摄像头节点发布的rgbd图和depth图话题名与ORB-SLAM2的订阅RGB图和depth图话题名不同,在ORB-SLAM2/Examples/ROS/ORB-SLAM2/src中修改ros_rgbd.cc的topic订阅:

message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/camera/color/image_raw", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/camera/aligned_depth_to_color/image_raw", 1);

  

 

# 重新编译build_ros.sh
chmod +x build_ros.sh
./build_ros.sh

  

 

# 启动相机
roslaunch realsense2_camera rs_rgbd.launch
# 运行ORB_SLAM2
rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.txt Examples/RGB-D/D435i.yaml

  

 

 

参考

https://blog.csdn.net/ssstarr/article/details/121089975

https://blog.csdn.net/qq_33950926/article/details/121129028

 

https://blog.csdn.net/rosfreshman/article/details/116404077

 

posted @ 2022-04-14 16:07  kay880  阅读(185)  评论(0编辑  收藏  举报