---
# System prepended metadata

title: Camera IMU Calibration

---

# Camera IMU Calibration
## Equipment
* imx219 x 2
* imu (unknown)
## Tools
* [kalibr](https://github.com/ethz-asl/kalibr) : 校正雙目＋imu的外參
* [Allan Variance ROS](https://github.com/ori-drs/allan_variance_ros) 取得imu的intrinsic
## Tutorials
* [Camera IMU calibration](https://github.com/ethz-asl/kalibr/wiki/camera-imu-calibration)
* [Intel-T265 Example](https://github.com/engcang/vins-application/tree/Intel-T265)
## 我們的測試資料
* 先創建`kalibr_vol` 資料夾 放入以下
    * cam-imu校正用bag:
https://mailntustedutw-my.sharepoint.com/:f:/g/personal/m11102141_ms_ntust_edu_tw/EvWDf4mCAsRBq4ImkkO2qbABf1af379AIMoVrl32cCtcnA?e=UGDKh0

    * april_6x6_80x80cm.yaml & imu-params.yaml :
https://gist.github.com/frakw/cb74f933bd3181d4bd6ddc91cc77542e

校正用bag的info
![](https://hackmd.io/_uploads/ryUuusd2n.png)

## Docker 配置 [hub](https://hub.docker.com/repository/docker/frakw/kalibr-image/general)
```bash=
docker pull frakw/kalibr-image:latest
FOLDER=kalibr_vol資料夾位置
xhost +
docker run -it --device=/dev/dri --group-add video --volume=/tmp/.X11-unix:/tmp/.X11-unix  --gpus all --env="DISPLAY=$DISPLAY" -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all --env="QT_X11_NO_MITSHM=1" -v "$FOLDER:/data" --name=kalibr-container frakw/kalibr-image:latest /bin/bash
```
## 執行校正
### 流程
* 先校正好雙目的外參 **用kalibr_calibrate_cameras**
* 加入imu的內參(imu-params.yaml) 校正雙目＋imu **用kalibr_calibrate_imu_camera**
### 雙目校正
```bash=
# new terminal 一定要有roscore 不然gui跑不出來 會卡住
docker exec -it kalibr-container /bin/bash
roscore
# new terminal 
xhost +
docker exec -it kalibr-container /bin/bash
rosrun kalibr kalibr_calibrate_cameras --bag /data/2023-08-10-00-52-13.bag --topics /rgb1 /rgb2 --models omni-radtan omni-radtan --target /data/april_6x6_80x80cm.yaml
```
跑完上面會在kalibr_vol資料夾中生成以下：
* xxx-camchain.yaml ===> 下個校正會用到
* xxx-report-cam.pdf
* xxx-result-cam.txt
### 雙目 + imu 校正 出現error
```bash=
# new terminal 一定要有roscore 不然gui跑不出來 會卡住
docker exec -it kalibr-container /bin/bash
roscore
# new terminal 
xhost +
docker exec -it kalibr-container /bin/bash
rosrun kalibr kalibr_calibrate_imu_camera --bag /data/2023-08-10-00-52-13.bag --cam /data/2023-08-10-00-52-13-camchain.yaml --imu /data/imu-params.yaml --target /data/april_6x6_80x80cm.yaml --timeoffset-padding 0.3
```
> 非必要不要在指令中添加`--verbose` 因為顯示過程會讓執行變慢很多

## 遭遇問題：
執行到
`Optimization problem initialized with 24196 design variables and 22345 error terms` `The Jacobian matrix is 48558 x 108862` 之後 會出現以下error
```
Spline Coefficient Buffer Exceeded. Set larger buffer margins!
```
![](https://hackmd.io/_uploads/S1e_-idn3.png)
可能解法(試過 但未解決)：
https://github.com/ethz-asl/kalibr/issues/41https://blog.csdn.net/qq_38337524/article/details/115589796
https://blog.csdn.net/qq_39779233/article/details/128704988
--timeoffset-padding 0.1
http://zhaoxuhui.top/blog/2020/09/29/intel-realsense-D435i-calibration-kalibr.html


---

## 單目校正
```bash=
# new terminal 一定要有roscore 不然gui跑不出來 會卡住
docker exec -it kalibr-container /bin/bash
roscore
# new terminal 
xhost +
docker exec -it kalibr-container /bin/bash
rosrun kalibr kalibr_calibrate_cameras --bag /data/2023-09-04_up.bag --topics /rgb1 --models omni-radtan --target /data/april_6x6_80x80cm.yaml

docker exec -it kalibr-container /bin/bash
rosrun kalibr kalibr_calibrate_cameras --bag /data/2023-09-04_down.bag --topics /rgb2 --models omni-radtan --target /data/april_6x6_80x80cm.yaml
```

### 單目 + imu 校正`
```bash=
# new terminal 一定要有roscore 不然gui跑不出來 會卡住
docker exec -it kalibr-container /bin/bash
roscore
# new terminal 
xhost +
docker exec -it kalibr-container /bin/bash
rosrun kalibr kalibr_calibrate_imu_camera --bag /data/2023-09-04_up.bag --cam /data/2023-09-04_up-camchain.yaml --imu /data/imu-params.yaml --target /data/april_6x6_80x80cm.yaml

rosrun kalibr kalibr_calibrate_imu_camera --bag /data/2023-09-04_down.bag --cam /data/2023-09-04_down-camchain.yaml --imu /data/imu-params.yaml --target /data/april_6x6_80x80cm.yaml
```