kinect2与ORB_SLAM2

首先安装好kinect2的驱动https://github.com/code-iai/iai_kinect2

并标定好,标定的样本图片越多越好

在工作空间git clone https://github.com/raulmur/ORB_SLAM2

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

编译中我遇到的错误前边博客以列出

还需修改

~/catkin_ws/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc

其中话题名修改如下

message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/kinect2/qhd/image_color_rect", 1);  
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/kinect2/qhd/image_depth_rect", 1); 

需要重新编译./build_ros.sh

还需将仿照TUM1.yaml的格式编写kinect2_qhd.yaml提供所需参数

%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------

# Camera calibration and distortion parameters (OpenCV) 
Camera.fx: 501.3
Camera.fy: 499.8 
Camera.cx: 479.7 
Camera.cy: 236.0

Camera.k1: 0.00643 
Camera.k2: 0.0150
Camera.p1: 0.00944
Camera.p2: 0.00212
Camera.p3: 0.0267
# 以上参数为calib_color.yaml中所得
Camera. 960 
Camera.height: 540 

# Camera frames per second 
Camera.fps: 30.0

# IR projector baseline times fx (aprox.)
Camera.bf: 40.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: 50.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

calib_color.yaml

%YAML:1.0                                                                     
---
cameraMatrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 1.0026733709141176e+03, 0., 9.5955552780476421e+02, 0.,
       9.9937595642637643e+02, 4.7210512130052348e+02, 0., 0., 1. ]
distortionCoefficients: !!opencv-matrix
   rows: 1
   cols: 5
   dt: d
   data: [ 6.4315074878269415e-03, -1.4985055702513178e-02,
       -9.4388254621764183e-03, 2.1259459646973751e-03,
       -2.6684108335689218e-02 ]
rotation: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 1., 0., 0., 0., 1., 0., 0., 0., 1. ]
projection: !!opencv-matrix
   rows: 4
   cols: 4
   dt: d
   data: [ 1.0026733709141176e+03, 0., 9.5955552780476421e+02, 0., 0.,
       9.9937595642637643e+02, 4.7210512130052348e+02, 0., 0., 0., 1.,
       0., 0., 0., 0., 1. ]

运行

rosrun kinect2_bridge kinect2_bridge _depth_method:=cpu _reg_method:=cpu

rosrun ORB_SLAM2 RGBD /home/miao/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/miao/catkin_ws/src/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml

ORB_SLAM2为系数的三维点云,无法应用于导航和避障,且无法保存。

https://blog.csdn.net/YunLaowang/article/details/92809234

原文地址:https://www.cnblogs.com/miaorn/p/14342317.html