ubntu16.04下ORB-SLAM2的kinect2在线定位建图
已经安装好kinect2在ros下的驱动,iai_kinectv2
Ubuntu16.04安装kinect v2驱动libfreenect2 ,ROS环境下Kinect v2安装配置
并标定好相机
Ubuntu16.04在ROS下使用iai_kinect2进行向相机标定
成功运行orb_slam2
Ubuntu16.04配置orb_slam2环境,orb_slam的单目数据集,单目实时运行,RGB-D数据集的运行
1.下载
git clone https://github.com/raulmur/ORB_SLAM2
2.修改
修改/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
3.编写kinect2_qhd.yaml
这里借鉴博客kinect2与ORB_SLAM2里的的内容
还需将仿照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.width: 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. ]
4.运行
roslaunch kinect2_bridge kinect2_bridge.launch
cd ~/catkin_ws/src/ORB_SLAM2
rosrun ORB_SLAM2 RGBD /home/yinyin/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/yinyin/catkin_ws/src/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml
ps:calib_color.yaml转kinect2_qhd.yaml方法
猜测:这里用到标定数值的的一半作为相机内参,可能是因为从官网下载的图片是1920 x 1080,而在实验中却是使用qhd,qhd是960 x 540。正好是原来的一半
data: [ 1.0026733709141176e+03, 0., 9.5955552780476421e+02, 0.,
9.9937595642637643e+02, 4.7210512130052348e+02, 0., 0., 1. ]
例如:
fx=1002.67/2=501.335