Kalibr进行IMU+相机的标定

环境:Ubuntu18.04
Kalibr代码连接:https://github.com/ethz-asl/kalibr

1.安装依赖

  • ROS
  • sudo apt-get install python-setuptools python-rosinstall ipython libeigen3-dev libboost-all-dev doxygen libopencv-dev ros-melodic-vision-opencv ros-melodic-image-transport-plugins ros-melodic-cmake-modules software-properties-common libpoco-dev python-matplotlib python-scipy python-git python-pip ipython libtbb-dev libblas-dev liblapack-dev python-catkin-tools libv4l-dev python-igraph

2.编译源码

mkdir ~/kalibr_ws/src
cd ~/kalibr_ws/src
git clone https://github.com/ethz-asl/Kalibr.git
git clone https://github.com/gaowenliang/code_utils

在code_utils下面找到sumpixel_test.cpp,修改#include "backward.hpp"为 #include “code_utils/backward.hpp”,然后运行catkin build

若错误提示:code_utils/backward.hpp:216:30: fatal error: elfutils/libdw.h: No such file or directory compilation terminated.
运行: sudo apt-get install libdw-dev 安装对应的库即可,一般安装这个就可以,如果这样还不可以试试:sudo apt-get install elfutils

cd ~/kalibr_ws/src
git clone https://github.com/gaowenliang/imu_utils
cd ~/kalibr_ws
catkin build -DCMAKE_BUILD_TYPE=Release -j4

2.1. or使用docker

可能Ubunutu20.04或者较新的内核会编译不过,可以使用docker

# Install xhost
 sudo apt-get install x11-xserver-utils

# Allow docker container to use your display
xhost +

先完成后面数据集采集步骤再继续

切换到存放bag的地方

# 进入docker
sudo docker run -it --rm -v $(pwd):/mnt -e DISPLAY=unix$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix:rw xqms/kalibr

source workspace/devel/setup.bash 
cd mnt/

No module named scipy.optimize
sudo apt-get install python-scipy

3.标定

运行前必须先source
source ~/kalibr_workspace/devel/setup.bash

标定板下载地址:https://github.com/ethz-asl/kalibr/wiki/downloads
一些需要注意的参数
Kalibr进行IMU+相机的标定_第1张图片

0. 数据包录制

rosbag record /camera/imu /camera/color/image_raw -O "D455_calibrate"

Kalibr标定需要的bag录制方法:https://www.youtube.com/watch?app=desktop&v=puNXsnrYWTY

文字版总结如下:

  • 保证图像能够涵盖整个棋盘格
  • 分别在x,y,z轴上进行充分平移,各来回三次
  • 分别在x,y,z轴上进行充分旋转,各三次

数据包应最好保证图像帧率20Hz以上,IMU频率200Hz以上

1. 先标定相机内参(Kalibr)

内参需要将相机帧率改为4Hz以保证有较大的方差
前一步录制的为20hz以上的图像节点,需要重新转为4hz节点

ROS提供了改变 topic 发布频率的功能包throttle应该默认集成在ros里不需额外安装

播放原数据包同时录制新的数据包,由于只需要校正内参,因此仅录制图像节点

rosrun topic_tools throttle messages /camera/color/image_raw 4.0
rosbag play D455_calibrate.bag
rosbag record /camera/color/image_raw_throttle -O "D455_calibrate_4hz"

了解清楚需要哪种类型的内参,本项目是应用于VINS-MONO,其内参如下

distortion_parameters:
   k1: 0.1481673767163673
   k2: -0.3265784602517599
   p1: -0.0009037876294980409
   p2: -0.00013311074486353
projection_parameters:
   fx: 601.8642495505338
   fy: 603.1325281600197
   cx: 326.9084579754477
   cy: 236.8014449465978

Kalibr支持相机模型参考:https://github.com/ethz-asl/kalibr/wiki/supported-models

VINS-MONO中对应着
相机模型:pinhole camera model (pinhole)
畸变模型:radial-tangential (radtan)

因此kalibr的models选择pinhole-radtan

执行相机内参校正:
kalibr_calibrate_cameras --target ./april_6x6_80x80cm.yaml --bag ./D455_calibrate_4hz.bag --models pinhole-radtan --topics /camera/color/image_raw_throttle

这里的标定板以及yaml可以从这里下载https://github.com/ethz-asl/kalibr/wiki/downloads
也可以进行自定义,参考:https://github.com/ethz-asl/kalibr/wiki/calibration-targets

校正完成后会在目录生成文件camchain-.D455_calibrate_4hz.yaml
打开camchain-.D455_calibrate_4hz.yaml将里面的节点名字改为正常帧率的节点名字

2. 标定IMU内参(imu_utils)

可以尝试:https://github.com/IntelRealSense/librealsense/tree/master/tools/rs-imu-calibration
创建d455.launch,内容如下:

<launch>

    <node pkg="imu_utils" type="imu_an" name="imu_an" output="screen">
        
        
        
        
        
    node>

launch>

运行IMU内参标定roslaunch imu_utils d455.launch
参数max_time_min表示获取imu数据时间,30表示30分钟,尽量保证30分钟以上,运行时,保持IMU静止不动

运行结束生成结果文件d455_imu_param.yaml

3. 联合标定相机和IMU(Kalibr)

参考Kalibr上面Download页面里的IMU的imu_adis16448.yaml文件,将上述IMU标定内参填入,如下

rostopic: /camera/imu
update_rate: 400.0 #Hz

accelerometer_noise_density: 2.1415441070477007e-02 #continous
accelerometer_random_walk: 5.2980835582240333e-04
gyroscope_noise_density: 2.6578618657601121e-03 #continous
gyroscope_random_walk: 2.6764204443528370e-05

执行
kalibr_calibrate_imu_camera --target ./april_6x6_80x80cm.yaml --bag ./D455_calibrate.bag --cam camchain-.calibrate_d455.yaml --imu ./imu_d455.yaml

运行结束生成结果文件results-imucam-.D455_calibrate.txt

参考

标定过程参考:

  • OpenVINS的教程https://docs.openvins.com/gs-calibration.html
  • https://www.freesion.com/article/4137168496/
  • 多相机多imu标定方法https://github.com/ethz-asl/kalibr/wiki/calibrating-the-vi-sensor

IMU标定:利用imu_utils和code_utils进行标定

  • imu_utils:https://github.com/gaowenliang/imu_utils
  • code_utils:https://github.com/gaowenliang/code_utils

相关教程:

  • https://www.freesion.com/article/4137168496/
  • https://blog.csdn.net/fang794735225/article/details/92804030
  • https://blog.csdn.net/heyijia0327/article/details/83583360

4.疑难杂症

编译kalibr_allan报错
https://blog.csdn.net/weixin_43247057/article/details/101211669
不需要用kalibr_allan标定辣!

你可能感兴趣的:(SLAM,Apriltag,自动驾驶,c++,人工智能,slam)