Realsense d435i内参、外参标定

使用工具code_utils、imu_utils、kalibr对Realsense d435i 内参、外参标定。本文介绍上述工具的安装,及标定方法。

一、code_utils安装

1.建立工作空间
  • mkdir -p calibration_ws/src
2.下载源码
  • cd calibration/src
  • git clone https://github.com/gaowenliang/code_utils.git
3.编译
  • cd …
  • catkin_make

编译可能出错

(1)error1

code_utils-master/src/sumpixel_test.cpp:2:24: fatal error: backward.hpp:No such file or directory
修改:在code_utils下面找到sumpixel_test.cpp,修改#include "backward.hpp"为 #include “code_utils/backward.hpp”,再编译。

(2)error2

/home/ocean/calibration/src/code_utils/include/code_utils/backward.hpp:216:12: fatal error: elfutils/libdw.h: No such file or directory # include
解决:sudo apt-get install libdw-dev

二、imu_utils安装

1.下载源码
  • cd calibration/src
  • git clone https://github.com/gaowenliang/imu_utils.git
2.编译
  • cd …
  • catkin_make

注:在相同工作空间下,先编译code_utils;在clone下imu_utils编译

三、kalibr 安装

1.安装依赖
  • sudo apt-get install python-catkin-tools # ubuntu 16.04, 18.04
  • sudo apt-get install python3-catkin-tools python3-osrf-pycommon # ubuntu 20.04
  • sudo apt-get install -y \
  • git wget autoconf automake nano \
    
  • libeigen3-dev libboost-all-dev libsuitesparse-dev \
    
  • doxygen libopencv-dev \
    
  • libpoco-dev libtbb-dev libblas-dev liblapack-dev libv4l-dev
    
  • sudo apt-get install -y python2.7-dev python-pip python-scipy \
  • python-matplotlib ipython python-wxgtk3.0 python-tk python-igraph # Ubuntu 16.04
    
  • sudo apt-get install -y python3-dev python-pip python-scipy \
  • python-matplotlib ipython python-wxgtk4.0 python-tk python-igraph # Ubuntu 18.04
    
  • sudo apt-get install -y python3-dev python3-pip python3-scipy \
  • python3-matplotlib ipython3 python3-wxgtk4.0 python3-tk python3-igraph # Ubuntu 20.04
    
2.建立工作空间
  • mkdir -p kalibr_ws/src
3.下载源码
  • cd kalibr_ws/src
  • git clone https://github.com/ethz-asl/kalibr.git
4.编译
  • cd …
  • catkin build -DCMAKE_BUILD_TYPE=Release -j4

四、标定

应用上述工具对d435i进行标定,是建立在已完成对d435i驱动安装、配置及校准的基础上,具体可参考另一篇博文Realsense d435i驱动安装、配置及校准

1.imu随机游走标定

imu随机游走标定前,需编写.launch 文件,进入文件

  • cd calibration/src/imu_utils/launch
  • touch d435i.launch
 
     
         #imu topic的名字 
         
         
          #标定的时长 
         
     

(1)运行d435i
  • cd realsense_ws
  • source devel/setup.bash
  • roslaunch realsense2_camera rs_camera.launch
(2)运行标定launch
  • cd calibration_ws
  • roslaunch imu_utils d435i.launch

运行完后会在calibration_ws/src/imu_utils/data/生成文件:Realsense_imu_param.yaml,内容如下:
Realsense d435i内参、外参标定_第1张图片

注:标定过程中,保持静置;也可先录制imu数据再进行标定

2.双目相机内参标定
(1)下载kalibr标定纸

https://github.com/ethz-asl/kalibr/wiki/downloads
可用A4纸打印出来,本文直接在电脑上打开Aprilgrid 6x6 0.8x0.8 m (A0 page) pdf 文件,这样有个好处是可以保证标定纸是绝对平整的。如下图所示:
Realsense d435i内参、外参标定_第2张图片

(2)编写标定板yaml文件

cd /相机标定结果存储
eg:

  • cd kalibr_ws/src/kalibr
  • mkdir data
  • cd data
  • touch checkerboard.yaml
target_type: 'aprilgrid' #gridtype
tagCols: 6               #number of apriltags
tagRows: 6               #number of apriltags
tagSize: 0.022           #size of apriltag, edge to edge [m]
tagSpacing: 0.3          #ratio of space between tags to tagSize

注:tagSize 原大小A0是0.088,A4显示缩小了4倍,也可实际测量得到。

(3)同上运行d435i
(4)录制bag

使用throttle工具降低录制数据频率

  • rosrun topic_tools throttle messages /camera/infra1/image_rect_raw 4.0 /left
  • rosrun topic_tools throttle messages /camera/infra2/image_rect_raw 4.0 /right
  • rosbag record -O d435i_infra_left /left
  • rosbag record -O d435i_infra_right /right

录制完成后,在data文件下会生成d435i_infra_left.bag、d435i_infra_right.bag
注:录制过程中,调整相机角度,尽量在各个方向都采集到数据,但要拍到完整的标定板,否则利用bag数据标定是会报错Detection failed;
录包过程中,可运行rviz,实时观测画面,确保标定板始终在镜头内;
分别录制了左目相机、右目相机bag,在校准过程中发现两者内参并不一样,可能是录制数据差异造成的。

(5)运行标定
  • rosrun kalibr kalibr_calibrate_cameras --target src/Kalibr/data/checkerboard.yaml --bag src/Kalibr/data/d435i_infra_left.bag --models pinhole-radtan --topics /left --bag-from-10 100 --show-extractio

  • rosrun kalibr kalibr_calibrate_cameras --target src/Kalibr/data/checkerboard.yaml --bag src/Kalibr/data/d435i_infra_right.bag --models pinhole-radtan --topics /right --bag-from-10 100 --show-extractio

输出左目结果:d435i_infra_left-camchain.yaml,d435i_infra_left-report-cam.pdf,d435i_infra_left-result-cam.txt,右目结果:d435i_infra_right-camchain.yaml,d435i_infra_right-report-cam.pdf,d435i_infra_right-result-cam.txt
以左目为例显示结果如下图
Realsense d435i内参、外参标定_第3张图片
Realsense d435i内参、外参标定_第4张图片

3.相机-imu外参标定

由于文本主要是为了后续实战vins_fusion,而vins_fusion可以实时优化相机外参,故本文对于kailbr标定相机外参不做介绍,关于vins_fusion可参考另一篇博文。。。。
而使用kailbr标定相机外参与相机内参标定类似,只是需同时录制imu、camera bag包,再调用命令:

  • rosrun kalibr kalibr_calibrate_imu_camera --target src/Kalibr/data/checkerboard.yaml --cam src/Kalibr/data/camchain.yaml --imu src/Kalibr/data/imu.yaml src/Kalibr/data/camimu.bag --show-extraction

其中:
camchain.yaml

cam0: 
camera_model: pinhole 
intrinsics: [391.57645976863694, 392.2173924045597, 326.83301528066227, 235.30947818084246] 
distortion_model: radtan 
distortion_coeffs: [0.007532405272341989, -0.003198723534231893, -0.00015249992792258453, 0.001638891018727039] 
T_cam_imu:#先验,后期优化 
[0.99995, -0.00851610, 0.003972445, 0.043946] 
[0.008539021, 0.9999467,-0.005786767, 0.01996812] 
[-0.0039229529, 0.005820432, 0.999975, 0.01636738] 
[0.0, 0.0, 0.0, 1.0] 
timeshift_cam_imu: 0.002004 
rostopic: /left 
resolution: [640, 480]

intrinsics,distortion_coeffs内参、畸变系数为上述标定的数据,T_cam_imu为初始化参数。

imu.yaml

rostopic: /imu 
update_rate: 200.0 #Hz 
accelerometer_noise_density: 1.7512828345266122e-02 #continous 
accelerometer_random_walk: 4.2528647943077756e-04 
gyroscope_noise_density: 3.3502044635737617e-03 #continous 
gyroscope_random_walk: 4.8760608618583259e-03

为随机游走标定的数据。

参考:

https://blog.csdn.net/u010196944/article/details/127238908
https://github.com/ethz-asl/kalibr/wiki/installation
https://zhuanlan.zhihu.com/p/309287821
https://blog.csdn.net/weixin_45702256/article/details/120553799

你可能感兴趣的:(slam,计算机视觉,自动驾驶)