利用kalibr标定IMU和相机: https://github.com/ethz-asl/kalibr/wiki/Camera-IMU-calibration#2-collect-images
在开始需要明确几点的是:需要先安装kalibr,该工具主要是标定相机和IMU, 在标定的过程中需要用到IMU和相机的内参文件,这里的内参文件可以用ROS 帮忙获得,或者如果已经有这个文件可以直接用。
接下要做的即安装realsense的ros接口主要是为了方便读取topic来录制rosbag, 因为kalibr在标定的时候需要用rosbag中的数据进行标定;
这里的相机采用realsense d435i 因此在安装标定前要确保相关库已经安装
1. 确保realsense的SDK已经安装:
2. 安装realsense的ros warpper
https://github.com/IntelRealSense/realsense-ros 这是前两步的参考链接,包含安装realsense的SDK和roswarpper
我之前已经安装过ros kinect在Ubuntu16.04的平台上,因此这里直接从catkin的工作空间开始
3. 标定IMU
3.1 安装ceres: https://blog.csdn.net/jz1570551401/article/details/78207208
1. 预安装,其中libgoogle-glog-dev 可能需要再单独安装
sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev
libgoogle-glog-dev libgtest-dev
2. 下载ceres:https://github.com/ceres-solver/ceres-solver
3. 解压文件后进入ceres-master:
mkdir build
cd build
cmake .. //如果这一步骤报错,可以检查一下是具体那个库没有安装成功,再sudo apt-get 对应的库就好
make //大概等几分钟
sudo make install
安装完成后/usr/local/include/ceres 和 /usr/local/lib/ 中
3.2 下载code_utils: https://github.com/gaowenliang/code_utils
解压至catkin下的src文件,然后在code_utils下面找到sumpixel_test.cpp,修改#include "backward.hpp"为 #include “code_utils/backward.hpp”,然后运行catkin_make
错误提示:code_utils/backward.hpp:216:30: fatal error: elfutils/libdw.h: No such file or directory
compilation terminated.
运行: apt-get install libdw-dev 安装对应的库即可,一般安装这个就可以,如果这样还不可以试试:sudo apt-get install elfutils
3.3 下载imu_utils: https://github.com/gaowenliang/imu_utils
再次catkin_make
3.4 接下来就可以就可以标定IMU了:
#imu topic的名字
#标定的时长
将该launch文件保存成imu.launch至src和install下的launch中, 然后在两个终端中同时运行
~/catkin_ws_rs$ roslaunch realsense2_camera rs_camera.launch
~/catkin_ws_rs/install/share/realsense2_camera/launch$ roslaunch imu.launch
运行imu.launch文件的终端中会出现
process[imu_an-1]: started with pid [8274]
[ INFO] [1571305008.871258796]: Loaded imu_topic: /camera/imu
[ INFO] [1571305008.872137757]: Loaded imu_name: d435i
[ INFO] [1571305008.872762617]: Loaded data_save_path: /home/shinan/catkin_ws_rs/src/imu_utils/data/d435i
[ INFO] [1571305008.873749085]: Loaded max_time_min: 30
[ INFO] [1571305008.874493932]: Loaded max_cluster: 100
gyr x num of Cluster 100
gyr y num of Cluster 100
gyr z num of Cluster 100
acc x num of Cluster 100
acc y num of Cluster 100
acc z num of Cluster 100
wait for imu data.
接下来等待30分钟即可,标定完成后imu的参数将会被保存在data_save_path的路径中;
也可以录制bag保存imu数据后进行标定;https://blog.csdn.net/fang794735225/article/details/92804030
将IMU的标定结果保存到文件imu.yaml中:
#Accelerometers
accelerometer_noise_density: 2.4753056458491202e-02 #Noise density (continuous-time)
accelerometer_random_walk: 5.1092097834339175e-04 #Bias random walk
#Gyroscopes
gyroscope_noise_density: 4.0642638745600332e-03 #Noise density (continuous-time)
gyroscope_random_walk: 2.6537322064011450e-05 #Bias random walk
rostopic: /imu0 #the IMU ROS topic
update_rate: 200.0 #Hz (for discretization of the values above)
标定realsense的RGB相机,如果使用的是其他相机可以用opencv采集图像后进行单目标定,这里不多写,主要是标定Realsense的彩色相机:
设定好相机的相关参数后(主要是size 和fps):目前设置图像大小为640*480 帧率为30
roslaunch realsense2_camera rs_camera.launch
启动realsense相机后,可以用rostopic list 查看对应的打开的topics
可以用ros自带的标定方法进行相机标定:
~/catkin_ws_rs$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.035 image:=/camera/color/image_raw
最开始的CALBRATE按钮为灰色,当采集的图像符合条件够就变成绿色,然后可以点击CALIBRATE进行标定,标定结果显示如下:
('D = ', [0.20848791559812113, -0.36507062055202405, 0.012079145675854016, -0.006358054188595459, 0.0])
('K = ', [653.7064773464425, 0.0, 314.4404941629716, 0.0, 654.2058371422769, 261.91335661459755, 0.0, 0.0, 1.0])
('R = ', [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
('P = ', [677.4393920898438, 0.0, 311.13625111082183, 0.0, 0.0, 676.0581665039062, 266.3551872155367, 0.0, 0.0, 0.0, 1.0, 0.0])
将标定的结果保存到.yaml文件中 如下所示:
cam0: #640*480
camera_model: pinhole
intrinsics: [653.7064773464425, 654.2058371422769,314.4404941629716, 261.91335661459755]
distortion_model: radtan
distortion_coeffs: [0.20848791559812113, -0.36507062055202405, 0.012079145675854016, -0.006358054188595459]
rostopic: /camera/color/image_raw
resolution: [640, 480]
准备标定板文件aprilgrid.yaml:
1. 启动realsense相机和imu,所以也要先设置好rs_camera.launch文件中的相关参数;
target_type: 'aprilgrid' #gridtype
tagCols: 6 #number of apriltags
tagRows: 6 #number of apriltags
tagSize: 0.021383 #size of apriltag, edge to edge [m]
tagSpacing: 0.2853 #ratio of space between tags to tagSize 0.61cm/2.1383cm = 0.285273348
#example: tagSize=2m, spacing=0.5m --> tagSpacing=spacing/tagSize = 0.25[-]
2. 为相机和IMU录制数据包,
可以先运行 rosrun image_view image_view image:=/camera/color/image_raw 查看图像, 保证在录制数据包的时候标定板不会超出画面
录制的时候尽量保证图像清晰,不要剧烈移动,采集数据的起始和结束阶段注意别晃动太大,如从桌子上拿起或者放下。如果有这样的动作,在标定阶段应该跳过bag数据集的首尾的数据. 同时尽可能地激活IMU的各个角度,各个方向,可以先依次绕各个轴运动,运动完后来个在空中画8字之类的操作,当然也要注意别运动太剧烈,图像都模糊了。:
rosbag record /camera/color/image_raw /camera/imu -O rgb_imu.bag
3. 进行标定:参数分别是包名称(不用加.bag),相机参数文件,imu参数文件, 标定板文件
~/Project/kalibr_workspace$ kalibr_calibrate_imu_camera --bag ~/Project/kalibr_workspace/rgb_imu.bag.bag --cam ~/Project/kalibr_workspace/camchain.yaml --imu ~/Project/kalibr_workspace/imu.yaml --target ~/Project/kalibr_workspace/aprilgrid.yaml
出现错误提示:
importing libraries
Traceback (most recent call last):
File "/home/shinan/Project/kalibr_workspace/devel/bin/kalibr_calibrate_imu_camera", line 15, in
exec(compile(fh.read(), python_script, 'exec'), context)
File "/home/shinan/Project/kalibr_workspace/src/kalibr-master/aslam_offline_calibration/kalibr/python/kalibr_calibrate_imu_camera", line 5, in
from kalibr_imu_camera_calibration import *
File "/home/shinan/Project/kalibr_workspace/src/kalibr-master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/__init__.py", line 4, in
import IccSensors as sens
File "/home/shinan/Project/kalibr_workspace/src/kalibr-master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccSensors.py", line 16, in
import scipy.optimize
ImportError: No module named scipy.optimize
安装python相关库:
sudo apt-get install python-scipy
标定结果如下:
After Optimization (Results)
==================
Normalized Residuals
----------------------------
Reprojection error (cam0): mean 0.552748299525, median 0.473100512902, std: 0.3640429471
Gyroscope error (imu0): mean 0.215478847361, median 0.161409013393, std: 0.19024901177
Accelerometer error (imu0): mean 0.165613674102, median 0.132037510374, std: 0.129116309678
Residuals
----------------------------
Reprojection error (cam0) [px]: mean 0.552748299525, median 0.473100512902, std: 0.3640429471
Gyroscope error (imu0) [rad/s]: mean 0.0123851576362, median 0.00927736573336, std: 0.0109350130176
Accelerometer error (imu0) [m/s^2]: mean 0.0579749018736, median 0.0462211936851, std: 0.04519859501
Transformation T_cam0_imu0 (imu0 to cam0, T_ci):
[[ 0.9999488 -0.00279248 0.00972605 0.03555196]
[ 0.00297818 0.99981255 -0.01913078 -0.00461578]
[-0.0096708 0.01915877 0.99976968 0.00838297]
[ 0. 0. 0. 1. ]]
cam0 to imu0 time: [s] (t_imu = t_cam + shift)
-0.0280180128084
IMU0:
----------------------------
Model: calibrated
Update rate: 200.0
Accelerometer:
Noise density: 0.0247530564585
Noise density (discrete): 0.350061081538
Random walk: 0.000510920978343
Gyroscope:
Noise density: 0.00406426387456
Noise density (discrete): 0.0574773709247
Random walk: 2.6537322064e-05
T_i_b
[[ 1. 0. 0. 0.]
[ 0. 1. 0. 0.]
[ 0. 0. 1. 0.]
[ 0. 0. 0. 1.]]
time offset with respect to IMU0: 0.0 [s]
Saving camera chain calibration to file: camchain-imucam-homeshinanProjectkalibr_workspacecam_imu640_480_retrgb_imu.bag.yaml
Saving imu calibration to file: imu-homeshinanProjectkalibr_workspacecam_imu640_480_retrgb_imu.bag.yaml
Detailed results written to file: results-imucam-homeshinanProjectkalibr_workspacecam_imu640_480_retrgb_imu.bag.txt
Generating result report...
Timeshift表示的就是IMU相对于camera的延时;
参考博客:https://blog.csdn.net/mxdsdo09/article/details/83514310