# Kalibr 文件参考：逐个字段说明

> Kalibr 的 camchain.yaml、camchain-imucam.yaml、imu.yaml 和 target.yaml 中的每一个字段，加上结果文件、报告、相机模型和畸变模型以及命令行工具，逐一说明其含义、单位，以及填错时会出什么问题。

Page: https://egocam.ai/zh-cn/kalibr/kalibr-file-reference/

[Kalibr](https://github.com/ethz-asl/kalibr) 是 ETH Zurich 的 Autonomous Systems Lab 开发的开源标定工具箱。它的 [wiki](https://github.com/ethz-asl/kalibr/wiki) 列出了它能求解的问题：多相机标定、相机–IMU（惯性测量单元）标定、多 IMU 标定和卷帘快门相机标定。它读写的所有东西都是小的 YAML 文件，而 Kalibr 出的问题，大多是其中某个文件里的一个数字填错了。

本页逐个讲解这些文件中的每一个字段。它们背后的概念（内参、外参、畸变、IMU 噪声），请先看[相机标定指南](https://egocam.ai/zh-cn/calibration/camera-calibration/)和 [IMU 标定指南](https://egocam.ai/zh-cn/calibration/imu-calibration/)。做事的顺序见 [Kalibr 工作流程](https://egocam.ai/zh-cn/kalibr/kalibr-workflow/)。

下面的字段名和检查规则读自 Kalibr wiki 和 Kalibr 源代码（`master` 分支，提交 `1f60227`，2024 年 3 月）。wiki 与代码不一致的地方，以代码为准，并注明了差异。

## 文件一览

| 文件 | 由谁写出 | 由谁读取 | 内容 |
|---|---|---|---|
| `target.yaml` | 你 | 每个标定工具 | 标定板的类型和尺寸 |
| `imu.yaml`（输入） | 你 | `kalibr_calibrate_imu_camera` | IMU 的噪声值、采样率和 ROS 话题（topic） |
| `<bag>-camchain.yaml` | `kalibr_calibrate_cameras` | `kalibr_calibrate_imu_camera`、`kalibr_camera_validator` | 每台相机的模型、内参、畸变、分辨率、话题，以及相机到相机的变换 |
| `<bag>-camchain-imucam.yaml` | `kalibr_calibrate_imu_camera` | 你自己的软件 | camchain 的内容，加上每台相机的 IMU 变换和时间偏移 |
| `<bag>-imu.yaml`（输出） | `kalibr_calibrate_imu_camera` | 你自己的软件 | IMU 的噪声值，加上它的模型、位姿和时间偏移；如果你要求了，还有它的内参 |
| `<bag>-results-cam.txt`、`<bag>-results-imucam.txt` | 两个标定程序 | 你 | 文本形式的结果摘要 |
| `<bag>-report-cam.pdf`、`<bag>-report-imucam.pdf` | 两个标定程序 | 你 | 各种图 |

表中的文件名是源代码实际写出的名字：bag 的名字在前（例如 `cam_april-camchain.yaml`）。wiki 的写法顺序相反，写作 `camchain-%BAGNAME%.yaml`。

## Kalibr 如何命名变换

Kalibr 中的每个变换都是一个 4×4 齐次矩阵，写作 `T_a_b`。**`T_a_b` 接收一个在坐标系 b 中表示的点，返回同一个点在坐标系 a 中的表示**。[YAML 格式页面](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats)用它自己的话说：cam1 的 `T_cn_cnm1` 就是 `T_c1_c0`，它 "takes cam0 to cam1 coordinates"（意为：把 cam0 坐标变到 cam1 坐标），而 `T_cam_imu` 是 "transformation from IMU to camera coordinates (T_c_i)"（意为：从 IMU 坐标到相机坐标的变换（T_c_i））。源代码使用同样的约定，有 "T_cN_b: from imu to camera N coords"（意为：T_cN_b：从 imu 坐标到相机 N 坐标）这样的注释，并且把相机看到的标定板计算为 `T_c_w = T_cN_b * T_b_w`。

> **Diagram:** How Kalibr names its transforms. T_a_b takes a point given in frame b and returns it in frame a. Each camera block in camchain-imucam.yaml stores T_cam_imu (IMU to that camera), and every camera after cam0 stores T_cn_cnm1 (the previous camera to this one, so cam1 holds T_c1_c0).

由此得出的都是普通的矩阵代数：

- **布局**。左上角的 3×3 块是旋转 R，最右边一列是平移 t，最下面一行是 `[0, 0, 0, 1]`。点的变换为 `p_a = R · p_b + t`。
- **单位**。平移量以米为单位。
- **平移量是从坐标系 a 看到的坐标系 b 的原点**。在 `T_cam_imu` 中，t 是 IMU 在相机坐标中的位置，而不是相机在 IMU 坐标中的位置。
- **求逆**。`T_b_a` 是 `T_a_b` 的逆：旋转为 Rᵀ，平移为 −Rᵀt。相机–IMU 结果文件把两个方向都打印出来，标记为 `T_ci` 和 `T_ic`。
- **连乘**。内侧的下标相消：`T_c1_imu = T_c1_c0 · T_c0_imu`。Kalibr 就是这样沿着相机链得到每台相机的 IMU 变换的。

把变换的方向读反是很容易犯的错误，而且没有任何东西提醒你。一个快速的检查办法是拿尺子对照平移量：[Kalibr wiki 上的 RealSense 教程](https://github.com/ethz-asl/kalibr/wiki/Calibrating-Intel-RealSense-Cameras)说要 "Sanity check your final rotation and translation with hand-measured values."（意为：用手工测量的值对最终的旋转和平移做合理性检查。）

## camchain.yaml：每台相机一个块

相机链（camera chain）文件为每台相机设一个顶层键，即 `cam0`、`cam1` 等，顺序与把话题交给 `kalibr_calibrate_cameras` 的顺序相同。[多相机指南](https://github.com/ethz-asl/kalibr/wiki/multiple-camera-calibration)说，`--topics` 和 `--models` 的顺序 "determine[s] the internal camera numbering in the output"（意为：决定了输出中相机的内部编号）。cam0 是相机链的起点。

这是 wiki 的示例，只保留了前两台相机：

```yaml
# Example values, from the Kalibr wiki's YAML formats page
cam0:
  camera_model: pinhole
  intrinsics: [461.629, 460.152, 362.680, 246.049]
  distortion_model: radtan
  distortion_coeffs: [-0.27695497, 0.06712482, 0.00087538, 0.00011556]
  T_cam_imu:
  - [0.01779318, 0.99967549,-0.01822936, 0.07008565]
  - [-0.9998017, 0.01795239, 0.00860714,-0.01771023]
  - [0.00893160, 0.01807260, 0.99979678, 0.00399246]
  - [0.0, 0.0, 0.0, 1.0]
  timeshift_cam_imu: -8.121e-05
  rostopic: /cam0/image_raw
  resolution: [752, 480]
cam1:
  camera_model: omni
  intrinsics: [0.80065662, 833.006, 830.345, 373.850, 253.749]
  distortion_model: radtan
  distortion_coeffs: [-0.33518750, 0.13211436, 0.00055967, 0.00057686]
  T_cn_cnm1:
  - [ 0.99998854, 0.00216014, 0.00427195,-0.11003785]
  - [-0.00221074, 0.99992702, 0.01187697, 0.00045792]
  - [-0.00424598,-0.01188627, 0.99992034,-0.00064487]
  - [0.0, 0.0, 0.0, 1.0]
  T_cam_imu:
  - [ 0.01567142, 0.99978002,-0.01393948,-0.03997419]
  - [-0.99966203, 0.01595569, 0.02052137,-0.01735854]
  - [ 0.02073927, 0.01361317, 0.99969223, 0.00326019]
  - [0.0, 0.0, 0.0, 1.0]
  timeshift_cam_imu: -8.681e-05
  rostopic: /cam1/image_raw
  resolution: [752, 480]
```

### 相机块中的每个键

| 键 | 类型和单位 | 由谁写出 | 含义 |
|---|---|---|---|
| `camera_model` | 字符串：`pinhole`、`omni`、`eucm` 或 `ds` | 相机标定 | 投影模型 |
| `intrinsics` | 浮点数列表；焦距和主点以像素为单位 | 相机标定 | 投影模型的参数，顺序见下一张表 |
| `distortion_model` | 字符串：`radtan`、`equidistant`、`fov` 或 `none` | 相机标定 | 镜头畸变模型 |
| `distortion_coeffs` | 浮点数列表，无单位 | 相机标定 | 畸变模型的参数：4 个、4 个、1 个或 0 个 |
| `resolution` | `[width, height]`，整数，像素 | 相机标定 | 这组内参所对应的图像尺寸 |
| `rostopic` | 字符串 | 相机标定 | bag 中这台相机图像的 ROS 话题 |
| `cam_overlaps` | 相机编号列表 | 相机标定 | 还有哪些相机与这台相机同时看到了标定板 |
| `T_cn_cnm1` | 4×4 矩阵，米 | 相机标定（从 cam1 起） | 从前一台相机到这台相机 |
| `T_cam_imu` | 4×4 矩阵，米 | 相机–IMU 标定 | 从 IMU 到这台相机 |
| `timeshift_cam_imu` | 浮点数，秒 | 相机–IMU 标定（除非关闭了时间标定） | 把它加到相机时间戳上，得到 IMU 时间 |
| `line_delay` | 浮点数，每个图像行的秒数 | 仅卷帘快门标定 | 一个图像行与下一行之间的时间 |

wiki 的 YAML 页面把 `camera_model` 列为 "(pinhole / omni)"，把 `distortion_model` 列为 "(radtan / equidistant)"，但源代码对两者各接受四种取值，如上表所列。`cam_overlaps` 和 `line_delay` 根本不在 YAML 页面上；它们来自源代码。

### camera_model 和 intrinsics

内参向量的长度和顺序取决于相机模型。源代码对两者都做检查，并拒绝填错的文件。

| `camera_model` | `intrinsics` 的顺序 | 个数 | 源代码强制的取值范围 |
|---|---|---|---|
| `pinhole` | `[fu, fv, pu, pv]` | 4 | 除共同检查外没有其他限制 |
| `omni` | `[xi, fu, fv, pu, pv]` | 5 | xi ≥ 0 |
| `ds` | `[xi, alpha, fu, fv, pu, pv]` | 6 | 0 ≤ alpha < 1 |
| `eucm` | `[alpha, beta, fu, fv, pu, pv]` | 6 | 0 ≤ alpha < 1，beta ≥ 0 |

对每一种模型，源代码还检查焦距和主点是小数并且不为负。

每个数字的含义：

- **fu、fv：焦距，以像素为单位**，每个图像轴一个。在针孔模型中，与光轴成 θ 角的光线落在距主点 fu · tan θ 像素处。所以对于针孔相机，fu ≈ (width / 2) / tan(水平视场角 / 2)，这可以用来对照镜头的规格书做快速检查。在像素为正方形的传感器上，fu 和 fv 应当非常接近。在 omni 模型中，它们是统一模型的广义焦距，在 Double Sphere 论文中写作 γ，不能与针孔焦距直接比较。
- **pu、pv：主点，以像素为单位**。即光轴与传感器相交的位置，从图像左上角量起。它应当在图像中心附近，但很少恰好在中心。
- **xi（omni）：镜面参数**。wiki 称它为 "mirror parameter (only omni)"（意为：镜面参数（仅 omni））。点先被投影到一个单位球面上，xi 是投影中心到球心的距离。xi = 0 就是针孔模型。源代码中的投影写作 `u = fu · x / (z + xi · d) + pu`，其中 d 是点到相机的距离。
- **xi、alpha（ds）：Double Sphere（双球）模型的参数**。点被投影到两个相距 xi 的单位球面上，然后投影到一个平移了 alpha / (1 − alpha) 的针孔像平面上（[Usenko, Demmel and Cremers, 2018](https://arxiv.org/abs/1807.08957)）。
- **alpha、beta（eucm）：扩展统一模型的参数**。与统一模型相同，只是球面变成了由 beta 决定形状的椭球面。源代码计算 `d = sqrt(beta · (x² + y²) + z²)` 和 `u = fu · x / (alpha · d + (1 − alpha) · z) + pu`。Double Sphere 论文指出 "the EUCM degrades to a regular UCM for β = 1"（意为：当 β = 1 时，EUCM 退化为普通的 UCM），也就是 alpha 形式的统一模型。

如果焦距错了，每条视线的方向都会错，错的比例越靠近图像边缘越大。如果主点错了，每条视线的方向都会倾斜。两者都直接影响深度和位姿。

### distortion_model 和 distortion_coeffs

| `distortion_model` | `distortion_coeffs` | 个数 | 可搭配的模型 |
|---|---|---|---|
| `radtan` | `[k1, k2, r1, r2]`（源代码把后两个称为 p1、p2） | 4 | `pinhole`、`omni` |
| `equidistant` | `[k1, k2, k3, k4]` | 4 | `pinhole`（源代码会停止并报 "Omni with equidistant model not yet supported!"（意为：尚不支持 omni 与 equidistant 模型的组合！）） |
| `fov` | `[w]` | 1 | `pinhole` |
| `none` | `[]` | 0 | 全部四种；对 `eucm` 和 `ds` 是唯一的选择 |

畸变作用在归一化图像坐标 (x, y) 上，在投影模型之后、焦距和主点之前。以下公式来自 Kalibr 源代码：

- **radtan（径向–切向）**。设 r² = x² + y²：
  `x' = x · (1 + k1·r² + k2·r⁴) + 2·p1·x·y + p2·(r² + 2x²)` 和
  `y' = y · (1 + k1·r² + k2·r⁴) + p1·(r² + 2y²) + 2·p2·x·y`。
  k1 和 k2 是径向项：负的 k1 把点拉向中心（桶形畸变），正的 k1 把点向外推（枕形畸变）。p1 和 p2 是切向项，来自镜头与传感器不完全平行。wiki 把这个模型链接到 [OpenCV 的模型](https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a)；它就是 k3 = 0 的 OpenCV 模型，顺序相同。
- **equidistant（等距）**。设 θ = atan(r)：`θd = θ · (1 + k1·θ² + k2·θ⁴ + k3·θ⁶ + k4·θ⁸)`，点按 θd / r 缩放。这就是 [Kannala–Brandt](https://doi.org/10.1109/TPAMI.2006.153) 多项式，wiki 把它链接到 [OpenCV 的鱼眼模型](https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html#details)。在 YAML 中它拼作 `equidistant`；在命令行上是 `equi`。
- **fov（视场角）**。只有一个参数 w，以弧度为单位：`rd = atan(2 · r · tan(w / 2)) / w`。在 [Devernay and Faugeras (2001)](https://doi.org/10.1007/PL00013269) 中，w "approximately corresponds to the field-of-view of an ideal fisheye lens"（意为：近似对应于理想鱼眼镜头的视场角），这是 Double Sphere 论文对它的概括。
- **none**。没有畸变；全部工作由投影模型完成。

系数填错的影响在图像中部最小，那里 r 小；在边缘最大，那里畸变最大。在边缘处，表现为去畸变后本该是直线的线不直，以及重投影误差随到中心的距离增大。

### resolution

`[width, height]`，以像素为单位，是两个整数。内参只在这个尺寸下有效。如果相机之后以不同的分辨率、裁剪或像素合并（binning）模式运行，这份标定就不再适用于它。

原因在于单位。焦距和主点 `[fu, fv, pu, pv]` 是以这幅图像的像素为单位测量的。2 × 2 像素合并模式使每个像素覆盖的角度加倍，所以这四个数大致都减半；裁剪保持焦距不变，但主点会移动裁剪的偏移量。在将来拍摄素材所用的模式下重新标定，就不必去猜。

### rostopic

bag 中存放这台相机图像的 ROS 话题，例如 `/cam0/image_raw`。它必须与 bag 完全一致，否则工具找不到任何图像。

### cam_overlaps

一个列表，列出标定过程中与这台相机有共同标定板观测的其他相机的编号，例如双目对中 cam0 下的 `cam_overlaps: [1]`。源代码根据相机图写出它：两台相机在同一个同步帧中都看到标定板时，它们就被连接起来。多相机工具要求每台相机都与其他相机相连；如果不是，它会停止并报 "Cameras are not connected through mutual observations, please check the dataset. Maybe adjust the approx. sync. tolerance."（意为：相机之间没有通过共同观测连接起来，请检查数据集。也许应调整近似同步容差。）

### T_cn_cnm1

从相机链中前一台相机（n − 1）到这台相机（n）的变换：用 wiki 的话说，是 "camera extrinsic transformation, always with respect to the last camera in the chain (e.g. cam1: T_cn_cnm1 = T_c1_c0, takes cam0 to cam1 coordinates)"（意为：相机外参变换，总是相对于相机链中的上一台相机（例如 cam1：T_cn_cnm1 = T_c1_c0，把 cam0 坐标变到 cam1 坐标））。cam0 没有这一项。其平移量的范数就是两台相机之间的基线，以米为单位；结果文件把它打印为 "baseline norm"（意为：基线范数）。在上面的示例中，平移量在 x 方向约为 −0.110 m，所以 cam1 距 cam0 11 cm。

如果它错了，双目深度就错了。基线偏差 1%，会使每个双目深度偏差约 1%。

### T_cam_imu

从 IMU 到这台相机的变换，即 "transformation from IMU to camera coordinates (T_c_i)"（意为：从 IMU 坐标到相机坐标的变换（T_c_i））。每台相机都有自己的一个。它由 `kalibr_calibrate_imu_camera` 添加。它的平移量是 IMU 在这台相机坐标系中的位置，你可以拿尺子对照设备的机械图纸来检查。在示例中，旋转矩阵的元素都接近 0 或 ±1：IMU 与相机是正交对齐安装的，只是它的轴有交换和翻转。

### timeshift_cam_imu

这台相机的时间戳与 IMU 的时间戳之间的时间偏移，以秒为单位："timeshift between camera and IMU timestamps in seconds (t_imu = t_cam + shift)"（意为：相机时间戳与 IMU 时间戳之间的时间偏移，以秒为单位（t_imu = t_cam + shift））。把它加到相机时间戳上，就得到 IMU 时钟上的同一时刻。wiki 的示例是 −8.121e-05 s，约 0.08 ms。这一估计背后的论文是 [Furgale, Rehder and Siegwart (2013)](https://doi.org/10.1109/IROS.2013.6696514)，它预期这个偏移包含 "fixed communication and filter delays plus half the exposure time as the images are timestamped at the start of the exposure time."（意为：固定的通信延迟和滤波延迟，再加上曝光时间的一半，因为图像的时间戳打在曝光开始的时刻。）

> **Diagram:** timeshift_cam_imu is the number of seconds to add to a camera timestamp to get the same instant on the IMU clock: t_imu = t_cam + shift. A negative value means the image's true IMU-clock time is earlier than its camera timestamp.

只有在时间标定开启时才会写出它，而开启是默认设置；`--no-time-calibration` 会把它关闭。如果用错了符号，误差不会消失，反而加倍。这个偏移的好坏完全取决于它所依据的时间戳。多 IMU 页面说 "The most common failure mode of kalibr appears to be incorrect timestamps provided by the user"（意为：kalibr 最常见的失败模式看来是用户提供的时间戳不正确），Furgale 的论文则警告 "For sensor setups without a common clock, the time offset may be different from start up to start up and subject to drift over longer periods of time"（意为：对于没有公共时钟的传感器配置，时间偏移可能每次启动都不同，并且在较长时间内会漂移）。

### line_delay

只由卷帘快门工具 `kalibr_calibrate_rs_cameras` 写出：相邻图像行之间的延迟，以秒为单位。源代码把每个像素的时间平移 line_delay × 它的行号。wiki 说卷帘快门工具 "currently only supports a single camera, and cannot calibrate an IMU alongside it."（意为：目前只支持单台相机，并且不能同时标定 IMU。）

## imu.yaml：输入文件

这个文件由你自己在相机–IMU 标定之前编写。[YAML 格式页面](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats)给出了这个示例：

```yaml
# Example values, from the Kalibr wiki's YAML formats page
#Accelerometers
accelerometer_noise_density: 1.86e-03   #Noise density (continuous-time)
accelerometer_random_walk:   4.33e-04   #Bias random walk

#Gyroscopes
gyroscope_noise_density:     1.87e-04   #Noise density (continuous-time)
gyroscope_random_walk:       2.66e-05   #Bias random walk

rostopic:                    /imu0      #the IMU ROS topic
update_rate:                 200.0      #Hz (for discretization of the values above)
```

六个键全部必填，并且源代码会拒绝为零或为负的噪声值或采样率。

| 键 | 符号 | 单位 | 含义 |
|---|---|---|---|
| `accelerometer_noise_density` | σa | m/s² · 1/√Hz | 加速度计白噪声，连续时间 |
| `accelerometer_random_walk` | σba | m/s³ · 1/√Hz | 加速度计零偏游走得有多快 |
| `gyroscope_noise_density` | σg | rad/s · 1/√Hz | 陀螺仪白噪声，连续时间 |
| `gyroscope_random_walk` | σbg | rad/s² · 1/√Hz | 陀螺仪零偏游走得有多快 |
| `update_rate` | 1/Δt | Hz | IMU 的采样率 |
| `rostopic` | – | – | bag 中 IMU 消息的 ROS 话题 |

这些符号和单位就是 wiki 的 [IMU 噪声模型页面](https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model)表 1 中的符号和单位。同一个模型独立地应用于每个轴，三个轴使用相同的值。

### 这些数字背后的噪声模型

Kalibr 把每个传感器的每个轴建模为：真值，加上缓慢变化的零偏 b(t)，再加上白噪声 n(t)。对陀螺仪就是 `ω̃(t) = ω(t) + b(t) + n(t)`。wiki 把 n 描述为 "an additive noise term that fluctuates very rapidly"（意为：一个波动非常快的加性噪声项），把 b 描述为 "a slowly varying sensor bias"（意为：一个缓慢变化的传感器零偏）。

- **噪声密度（σg、σa）**。白噪声的强度：它越高，"the more "noisy" your gyro measurements"（意为：你的陀螺仪测量值就越“嘈杂”）。
- **随机游走（σbg、σba）**。零偏被建模为随机游走：它的变化率是强度为 σb 的白噪声。"The higher the bias variations in your gyro or accel are, the higher these parameters need to be set."（意为：你的陀螺仪或加速度计的零偏变化越大，这些参数就需要设得越高。）

### 连续时间和离散时间

文件中的两个噪声密度是**连续时间**的值。每个采样的噪声更大，并且取决于采样率：

- 每个采样的白噪声：`σd = σ / √Δt = σ · √(update_rate)`
- 每一步的零偏随机游走：`σbd = σb · √Δt`

源代码正是这样做的，把噪声密度除以 √(1 / update_rate)。所以示例中的陀螺仪，在 200 Hz 下为 1.87e-04 rad/s/√Hz，每个采样的噪声约为 2.6e-03 rad/s。

这就是 `update_rate` 重要的原因。如果它错了，Kalibr 假定的每个采样的噪声就错了，给 IMU 的权重也随之出错。wiki 补充了一条限制：这种换算假定传感器自身的低通滤波器已经去除了高于采样率一半的噪声（"an ideal decimation stage"（意为：一个理想的抽取环节））。wiki 说，如果你只是丢弃采样来降低采样率，就不能这样换算噪声密度。

### 由规格书得到这些值

wiki 解释了规格书上的名称如何对应到这些字段：

- **白噪声**值 "are often specified in the datasheet"（意为：通常在规格书中给出）。对陀螺仪，它们常被称为**角度随机游走**（angular random walk），对加速度计则称为**速度随机游走**（velocity random walk）。wiki 说这些名称 "A bit misleading"（意为：有点误导）：白噪声只有经过积分之后才成为随机游走。其他厂商把它称为 "rate noise density"（意为：角速率噪声密度）、"acceleration noise density"（意为：加速度噪声密度）或 "noise density"（意为：噪声密度）。
- **零偏随机游走** "rarely directly specified in the datasheet"（意为：很少在规格书中直接给出）。规格书通常给出的是**运行中零偏（不）稳定性**（in-run bias (in)stability），即 Allan 偏差曲线的最低点，它可以与白噪声一起用来找出 "reasonable values"（意为：合理的值）。

单位换算是普通的算术。下面用的是示意性的规格书数值，不是任何具体的器件：

| 规格书上的写法 | 换算 | Kalibr 的值 |
|---|---|---|
| 陀螺仪噪声 0.007 °/s/√Hz | × π / 180 | 1.22e-04 rad/s/√Hz |
| 陀螺仪角度随机游走 0.3 °/√h | × (π / 180) / 60 | 8.7e-05 rad/s/√Hz |
| 加速度计噪声 120 µg/√Hz | × 9.80665e-6 | 1.18e-03 m/s²/√Hz |
| 加速度计速度随机游走 0.03 m/s/√h | ÷ 60 | 5.0e-04 m/s²/√Hz |

因子 60 是 √3600，即一小时的秒数开平方。

### 由 Allan 偏差得到这些值

Allan 偏差是自己测量这些值的标准方法：让 IMU 完全静止地录制很长时间，然后在双对数坐标上画出它的平均值的游走量随平均时间 τ 的变化。wiki 从这张图上读出 Kalibr 的值：

- **噪声密度**：曲线在 τ = 1 s 处的值，位于斜率为 −½ 的那一段上。
- **随机游走**：拟合出的斜率为 +½ 的直线在 τ = 3 s 处的值。

对于录制，wiki 建议把 [allan_variance_ros](https://github.com/ori-drs/allan_variance_ros) "directly on ~15-24 hour dataset recording of the IMU being stationary"（意为：直接用在约 15 到 24 小时的 IMU 静止录制数据集上）。这种方法在 [IMU 标定指南](https://egocam.ai/zh-cn/calibration/imu-calibration/)中有更深入的讲解。

### 放大噪声值

放在工作台上静止不动的 IMU 是最理想的情况。wiki 直白地说，这个模型 "is derived from a sensor which does not undergo motion, and at constant temperature"（意为：是由一个不运动、并处于恒定温度下的传感器推导出来的），所以 "clearly, the model is optimistic"（意为：显然，这个模型偏乐观）。如果原样使用静态得到的值，意味着 "Kalibr will tend to trust your IMU measurements too much, and its solution will not be optimal."（意为：Kalibr 会倾向于过分信任你的 IMU 测量值，它的解也不会是最优的。）它的建议是："From our experience, for lowest-cost sensors, increasing the noise model parameters by a factor of 10x or more may be necessary."（意为：根据我们的经验，对于最低成本的传感器，可能需要把噪声模型参数放大 10 倍或更多。）除此之外，wiki 没有给出确切的倍数；要靠报告中的残差图（见下文）来判断。

## imu.yaml：输出文件

`kalibr_calibrate_imu_camera` 还会写出 `<bag>-imu.yaml`。源代码根据每个输入的 IMU 文件生成它，保留输入中的每个键，并加上结果。它为每个 IMU 设一个顶层键，即 `imu0`、`imu1` 等，顺序与传给 `--imu` 的顺序相同。第一个 IMU 是参考 IMU，它的坐标系就是 "body"（机体）坐标系。

| 键 | 出现于 | 含义 |
|---|---|---|
| 全部六个输入键 | 每个 IMU | 从输入文件复制 |
| `model` | 每个 IMU | 使用的 IMU 模型：`calibrated`、`scale-misalignment` 或 `scale-misalignment-size-effect` |
| `T_i_b` | 每个 IMU | 4×4，米：从 body 坐标系（imu0）到这个 IMU。结果文件把它标记为 "imu0 to imuN"（意为：imu0 到 imuN）。对 imu0 是单位矩阵 |
| `time_offset` | 每个 IMU | 秒：这个 IMU 相对 imu0 的偏移，打印为 "time offset with respect to IMU0"（意为：相对 IMU0 的时间偏移）。除非使用了 `--imu-delay-by-correlation`，否则为 0 |
| `accelerometers: M` | `scale-misalignment` 及以上 | 3×3 矩阵：加速度计的比例系数和轴失准 |
| `gyroscopes: M` | `scale-misalignment` 及以上 | 3×3 矩阵：陀螺仪的比例系数和轴失准 |
| `gyroscopes: A` | `scale-misalignment` 及以上 | 3×3 矩阵，(rad/s)/(m/s²)：有多少加速度漏进了陀螺仪的读数 |
| `gyroscopes: C_gyro_i` | `scale-misalignment` 及以上 | 3×3 旋转矩阵：陀螺仪三轴组相对 IMU（加速度计）坐标系的朝向 |
| `accelerometers: rx_i, ry_i, rz_i` | `scale-misalignment-size-effect` | 三维向量，米：加速度计每个轴的位置 |

这三种 IMU 模型来自 [Rehder et al. (2016)](https://doi.org/10.1109/ICRA.2016.7487628)，"Extending kalibr"，[多 IMU 页面](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)说输出的 "Naming corresponds to quantities documented in"（意为：命名对应于……中记载的各个量）那篇论文。每个矩阵的作用如下，依据源代码：

- **`calibrated`**（默认）假定 IMU 的内参已经被修正。[相机–IMU 指南](https://github.com/ethz-asl/kalibr/wiki/camera-imu-calibration)说这些内参 "need to be calibrated beforehand and its correction applied to the raw measurements. If not, one should use an IMU model which calibrates these values."（意为：需要事先标定，并把修正应用到原始测量值上。如果没有，就应当使用一个会标定这些量的 IMU 模型。）
- **`scale-misalignment`** 为每个传感器增加 M，它把比例系数和轴失准合在一起。源代码把它们作为一个从单位矩阵出发的下三角矩阵 M 来估计：对角线上是比例系数，接近 1；对角线以下的元素是小的失准项。陀螺仪还有 A，即线加速度对其读数的影响（常称为 g 敏感度，g-sensitivity），按完整的 3×3 矩阵估计；以及 C_gyro_i，即陀螺仪各轴与加速度计各轴之间的旋转。在源代码中，建模的陀螺仪读数是 `M · ω + A · a`，两者都在陀螺仪坐标系中表示。
- **`scale-misalignment-size-effect`** 还会确定加速度计每个轴的位置。据我们所知，“尺寸效应”（size effect）的产生，是因为有些 IMU 把加速度计的每个轴放在略有不同的位置，所以器件旋转时各轴感受到的加速度不同。在源代码中，`rx_i` 固定为零，`ry_i` 和 `rz_i` 被估计，这与 wiki 的描述相符："the displacement of the accelerometer y- and z-axis with respect to its x-axis"（意为：加速度计 y 轴和 z 轴相对其 x 轴的位移）。

## target.yaml：标定板

[标定板页面](https://github.com/ethz-asl/kalibr/wiki/calibration-targets)列出了三种标定板类型。所有长度都以米为单位。源代码的检查要求每个个数都是不小于 3 的整数，每个长度都是正的小数。长度要带小数点书写，例如 `0.06` 或 `1.0`：只写 `1` 会被读成整数，通不过检查。

### Aprilgrid

wiki 推荐 Aprilgrid，因为 "partially visible calibration boards can be used"（意为：只有部分可见的标定板也可以使用），并且 "pose of the target is fully resolved (no flips)"（意为：标定板的位姿可以完全确定（不会翻转））。

```yaml
# Example values, from the Kalibr wiki's calibration targets page
target_type: 'aprilgrid' #gridtype
tagCols: 6               #number of apriltags
tagRows: 6               #number of apriltags
tagSize: 0.088           #size of apriltag, edge to edge [m]
tagSpacing: 0.3          #ratio of space between tags to tagSize
                         #example: tagSize=2m, spacing=0.5m --> tagSpacing=0.25[-]
```

| 键 | 类型和单位 | 含义 |
|---|---|---|
| `target_type` | `'aprilgrid'` | 标定板类型 |
| `tagCols` | 整数 ≥ 3 | 横向的标签数 |
| `tagRows` | 整数 ≥ 3 | 纵向的标签数 |
| `tagSize` | 米 | 一个标签的宽度，跨过其黑色边框 "edge to edge"（意为：从边到边） |
| `tagSpacing` | 比值，无单位 | 标签之间的间隙除以 `tagSize` |

**`tagSpacing` 是一个比值，不是长度**。wiki 的示例：2 m 的标签、0.5 m 的间隙，得到 `tagSpacing: 0.25`。源代码证实了这一点：标定板的角点被放在 `(1 + tagSpacing) · tagSize` 的整数倍处，[代码注释](https://github.com/ethz-asl/kalibr/blob/master/aslam_cv/aslam_cameras_april/src/GridCalibrationTargetAprilgrid.cpp)写的是 "tagSpacing [m] = tagSpacing*tagSize"（意为：以米为单位的标签间距 = tagSpacing*tagSize）。如果在这里填以米为单位的间隙，例如填 `0.026` 而不是 `0.3`，每个角点的位置都会错。

> **Diagram:** On an Aprilgrid, tagSize is the width of one tag across its black border, in metres. tagSpacing is not a length: it is the gap between tags divided by tagSize. The small black squares fill the gaps at the tag corners.

源代码还显示了关于 Aprilgrid 的以下几点：

- 标签是 AprilTag 36h11 标记（[Olson, 2011](https://doi.org/10.1109/ICRA.2011.5979561)），用 Michael Kaess 的 AprilTag 实现来检测，wiki 对此有致谢说明。
- 每个标签给出四个角点，所以 6 × 6 的网格有 144 个。
- Kalibr 自带的 PDF 生成器在每个标签角处的间隙里加上小的黑色方块，每个方块宽 `tagSpacing · tagSize`。它的注释说这些方块 "make corners symmetric (decreases the effect of motion blur in the subpix refinement...)"（意为：使角点对称（减小运动模糊在亚像素细化中的影响……））。
- 一帧只有在看到足够多的标签时才算数：两个标定程序都把最小数量设为 `tagRows` 和 `tagCols` 中较大的一个再加一。在 6 × 6 的网格上，就是 7 个标签。[代码注释](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_camera_calibration/CameraCalibrator.py)给出了理由："enforce more than one row --> pnp solution can be bad if all points are almost on a line"（意为：强制要求多于一行 --> 如果所有点几乎在一条直线上，pnp 的解可能很差）。
- wiki 警告："Make sure to hide all external Apriltags while collecting the calibration dataset."（意为：采集标定数据集时，务必把所有外部的 Apriltag 遮起来。）

### 棋盘格

```yaml
# Example values, from the Kalibr wiki's calibration targets page
target_type: 'checkerboard' #gridtype
targetCols: 6               #number of internal chessboard corners
targetRows: 7               #number of internal chessboard corners
rowSpacingMeters: 0.06      #size of one chessboard square [m]
colSpacingMeters: 0.06      #size of one chessboard square [m]
```

| 键 | 类型和单位 | 含义 |
|---|---|---|
| `target_type` | `'checkerboard'` | 标定板类型 |
| `targetCols` | 整数 ≥ 3 | 横向的内部角点数，不是方格数 |
| `targetRows` | 整数 ≥ 3 | 纵向的内部角点数，不是方格数 |
| `rowSpacingMeters` | 米 | 一个方格沿行方向的尺寸 |
| `colSpacingMeters` | 米 | 一个方格沿列方向的尺寸 |

一块 7 × 8 个方格的标定板有 6 × 7 个内部角点。数成方格数而不是角点数，是棋盘格始终检测不到的一个常见原因。

### 圆点网格

```yaml
# Example values, from the Kalibr wiki's calibration targets page
target_type: 'circlegrid'  #gridtype
targetCols: 6              #number of circles (cols)
targetRows: 7              #number of circles (rows)
spacingMeters: 0.02        #distance between circles [m]
asymmetricGrid: False      #use asymmetric grid (opencv) [bool]
```

| 键 | 类型和单位 | 含义 |
|---|---|---|
| `target_type` | `'circlegrid'` | 标定板类型 |
| `targetCols` | 整数 ≥ 3 | 横向的圆点数 |
| `targetRows` | 整数 ≥ 3 | 纵向的圆点数 |
| `spacingMeters` | 米 | 圆点之间的距离 |
| `asymmetricGrid` | `True` 或 `False` | `True` 表示 OpenCV 的非对称圆点网格 |

wiki 说这些是 "The standard OpenCV symmetric and asymmetric circle grids"（意为：标准的 OpenCV 对称和非对称圆点网格）。

棋盘格和圆点网格是对称的，所以它们的位姿可能翻转。相机–IMU 指南警告说，使用它们时 "movements which could lead to flips in the target pose estimates have to be avoided"（意为：必须避免可能导致标定板位姿估计翻转的运动），并推荐使用 Aprilgrid "to avoid this problem entirely"（意为：来彻底避免这个问题）。

### 测量打印出来的标定板

永远不要相信你让打印机打印的尺寸。wiki 写道："Most printers will scale the target during the printing process. Make sure to remeasure the important sizes and adjust the target configuration accordingly."（意为：大多数打印机在打印过程中会缩放标定板。务必重新测量重要的尺寸，并相应地调整标定板配置。）

- **Aprilgrid**：跨过一个标签的黑色外边缘测量 `tagSize`，并测量两个相邻标签之间的间隙。然后 `tagSpacing = gap / tagSize`。跨多个标签测量再相除可以减小误差：n 个标签和它们之间的 n − 1 个间隙的总跨度为 `tagSize · (n + (n − 1) · tagSpacing)`。
- **棋盘格**：在每个方向上跨尽可能多的方格测量，再除以方格数。
- **圆点网格**：跨多个圆点测量圆心到圆心的距离，再相除。

wiki 关于标定板的其他规则：让标定板保持 "as flat as possible. Best is to glue it to a rigid plate such as aluminum or acrylic glass"（意为：尽可能平整。最好把它粘在铝板或亚克力板这样的刚性板上），并保留 "a white border around the calibration target of min. the size of one grid element (or the detection might be unsuccessful in certain lighting conditions)"（意为：标定板四周至少一个网格单元大小的白边（否则在某些光照条件下检测可能失败））。

YAML 中的标定板小了 1%，会使 Kalibr 估计的每个平移量都小 1%，基线也包括在内，因为在相机标定中，标定板是唯一确定公制尺度的东西。

## 相机模型

Kalibr 的[支持的模型页面](https://github.com/ethz-asl/kalibr/wiki/Supported-models)列出了四种投影模型。在命令行上，`--models` 接收用连字符连接的一个投影模型和一个畸变模型。源代码只接受这七种组合：`pinhole-radtan`、`pinhole-equi`、`pinhole-fov`、`omni-none`、`omni-radtan`、`eucm-none` 和 `ds-none`。

| 模型 | 键 | 内参 | 它是什么 | 适合的镜头 | 原始论文 |
|---|---|---|---|---|---|
| 针孔 | `pinhole` | fu fv pu pv | 经过单个点的直线投影 | 普通镜头和中等广角镜头，配合一个畸变模型 | wiki 列出的是 Kannala and Brandt (2006) |
| 全向（统一） | `omni` | xi fu fv pu pv | 先投影到单位球面上，再投影到偏移了 xi 的针孔上 | 折反射（带反射镜的）相机、广角镜头和鱼眼镜头 | Mei and Rives (2007) |
| 扩展统一 | `eucm` | alpha beta fu fv pu pv | 与统一模型相同，但投影到由 beta 决定形状的椭球面上 | 广角镜头和鱼眼镜头、折反射系统 | Khomutenko, Garcia and Martinet (2016) |
| Double Sphere（双球） | `ds` | xi alpha fu fv pu pv | 先投影到两个相距 xi 的单位球面上，再投影到一个平移了的针孔上 | 大视场角的鱼眼镜头 | Usenko, Demmel and Cremers (2018) |

### 针孔（Pinhole）

其他所有模型都以这种投影为起点：`u = fu · x / z + pu`，`v = fv · y / z + pv`。它只对相机前方的点（z > 0）有效，所以它 "theoretically limits the field-of-view to less than 180°"（意为：在理论上把视场角限制在 180° 以内），Double Sphere 论文还补充说 "in practice, even when distortion model is added the pinhole camera demonstrates suboptimal performance for a field-of-view greater than 120°."（意为：在实践中，即使加上畸变模型，针孔相机在视场角大于 120° 时也表现欠佳。）Kalibr 的 wiki 引用 [Kannala and Brandt (2006)](https://doi.org/10.1109/TPAMI.2006.153) 作为针孔模型的参考文献。

### 全向（统一）模型（Omnidirectional）

出自 [Mei and Rives (2007)](https://doi.org/10.1109/ROBOT.2007.364084)，"Single view point omnidirectional camera calibration from planar grids"。他们的模型 "is based on an exact theoretical projection function to which we add well identified parameters to model real-world errors"（意为：基于一个精确的理论投影函数，我们在其上加入了含义明确的参数来对真实世界中的误差建模），并且他们在 "parabolic, hyperbolic, folded mirror, wide-angle and spherical sensors"（意为：抛物面、双曲面、折叠反射镜、广角和球面传感器）上验证了它。Double Sphere 论文指出，统一模型可以用于鱼眼镜头，"However, it does not fit most fisheye lenses perfectly; thus, an additional distortion model is often added"（意为：然而，它并不能完美地拟合大多数鱼眼镜头；因此常常要再加一个畸变模型），`omni-radtan` 做的就是这件事。

### 扩展统一模型（EUCM）

出自 [Khomutenko, Garcia and Martinet (2016)](https://doi.org/10.1109/LRA.2015.2502921)，"An enhanced unified camera model"。它的摘要写道："The new model applies to catadioptric systems and wide-angle fish-eye cameras, it does not require additional mapping to model distortions, and it takes just two projection parameters more than a simple pinhole model to represent radial distortion"（意为：新模型适用于折反射系统和广角鱼眼相机，不需要额外的映射来对畸变建模，并且只比简单的针孔模型多用两个投影参数来表示径向畸变）。在 Kalibr 中它只能以 `eucm-none` 运行。

### Double Sphere（双球）模型（DS）

出自 [Usenko, Demmel and Cremers (2018)](https://arxiv.org/abs/1807.08957)，"The double sphere camera model"。他们提出这个模型，称它 "that well fits with large field-of-view lenses, is computationally inexpensive and has a closed-form inverse."（意为：能很好地拟合大视场角镜头，计算开销小，并且有闭式的逆。）在他们由 122° 到 195° 的鱼眼镜头和广角镜头组成的测试集上，它与一个八参数的 Kannala–Brandt 模型相比 "less than 1% greater reprojection error"（意为：重投影误差高出不到 1%），而后者 "5-10 times slower"（意为：慢 5 到 10 倍）。在 Kalibr 中它只能以 `ds-none` 运行。

## 畸变模型

| 模型 | YAML 键 | 命令行 | 系数 | 适合拟合什么 | 参考 |
|---|---|---|---|---|---|
| 径向–切向 | `radtan` | `radtan` | k1 k2 r1 r2 | 畸变中等的普通镜头 | [OpenCV](https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a) |
| 等距 | `equidistant` | `equi` | k1 k2 k3 k4 | 广角镜头和鱼眼镜头 | Kannala and Brandt (2006)；[OpenCV fisheye](https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html#details) |
| 视场角 | `fov` | `fov` | w | 广角镜头和鱼眼镜头 | Devernay and Faugeras (2001) |
| 无 | `none` | `none` | – | 不需要额外畸变的模型 | – |

- **径向–切向**是[相机标定页面](https://egocam.ai/zh-cn/calibration/camera-calibration/)上讲的经典模型。它是 r 的多项式，r 是归一化图像中到中心的距离，所以在 r 变大的地方，也就是大角度处，它就力不从心。
- **等距**是 [Kannala–Brandt](https://doi.org/10.1109/TPAMI.2006.153) 模型，作者称它 "suitable for fish-eye lens cameras as well as for conventional and wide-angle lens cameras"（意为：既适用于鱼眼镜头相机，也适用于常规镜头和广角镜头相机）。它是角度 θ 的多项式，而不是 r 的多项式。Double Sphere 论文提出了一点注意事项：当它作为畸变叠加在针孔模型之上使用时，就像 Kalibr 的 `pinhole-equi` 那样，"it has a singularity at z = 0, which makes it unsuitable for fisheye lenses with field-of-view close to 180°"（意为：它在 z = 0 处有奇异点，这使它不适合视场角接近 180° 的鱼眼镜头）。
- **视场角**出自 [Devernay and Faugeras (2001)](https://doi.org/10.1007/PL00013269)，"Straight lines have to be straight"，按其[摘要](https://inria.hal.science/inria-00267247v1)的说法，是为 "low-cost wide-angle or fish-eye lenses"（意为：低成本的广角或鱼眼镜头）而写的。它只有一个参数。在 Double Sphere 论文的测试（表 1）中，FOV 模型在 183° 和 195° 镜头上的平均重投影误差约为最佳模型的两到三倍。

Kalibr 可以在一次运行中为每台相机拟合不同的模型：多相机指南说 "Arbitrary combinations of projection and distortion models can be combined in one calibration run."（意为：在一次标定运行中可以任意组合投影模型和畸变模型。）

## 结果文本文件

### results-cam.txt（相机标定）

源代码为每台相机写出：

| 行 | 含义 |
|---|---|
| `cam0 (/cam0/image_raw):` | 相机编号及其话题 |
| `type:` | 内部的相机几何类，从它的名字可以看出模型 |
| `distortion: [...] +- [...]` | 畸变系数及其标准差 |
| `projection: [...] +- [...]` | 投影参数及其标准差 |
| `reprojection error: [mx, my] +- [sx, sy]` | 重投影误差的均值和标准差，以像素为单位，x 和 y 分开给出 |

然后，对第一台之后的每台相机，有一个 `baseline T_1_0:` 块，其中旋转以四元数 `q` 表示，平移为 `t`，各带标准差。最后是从 `target.yaml` 读到的标定板配置。检查它是否与你测得的相符；打印机造成的偏差和笔误都会体现在这里。

**怎样读重投影误差**。**均值**是 x 方向和 y 方向上带符号误差的平均值，所以它应当接近零；均值远离零说明误差偏向一侧，即存在系统性偏差。**标准差**是误差的离散程度，以像素为单位。参数后面的 "+-" 值是参数的估计标准差：这个值大，说明数据没能把该参数确定下来。

### results-imucam.txt（相机–IMU 标定）

| 小节 | 内容 |
|---|---|
| `Normalized Residuals` | 重投影误差、陀螺仪误差和加速度计误差，各自除以其假定的噪声：均值、中位数和标准差 |
| `Residuals` | 同样的误差，以实际单位表示：像素、rad/s 和 m/s² |
| `Transformation (cam0):` | `T_ci`（imu0 到 cam0）和 `T_ic`（cam0 到 imu0），都是 4×4 矩阵 |
| `timeshift cam0 to imu0: [s] (t_imu = t_cam + shift)` | 该相机的时间偏移 |
| `Baselines:` | 相机到相机的变换，以及它们以米为单位的 "baseline norm"（意为：基线范数） |
| `Gravity vector in target coords: [m/s^2]` | 在标定板坐标系中估计出的重力方向 |
| `Calibration configuration` 和 `IMU configuration` | 读入的各项输入，包括每个 IMU 的噪声密度、它的离散时间形式，以及它的随机游走 |

**怎样读残差**。归一化残差是误差除以告诉 Kalibr 应当预期的标准差：对相机是 `--reprojection-sigma` 的值（默认 1.0 px），对 IMU 是由 `imu.yaml` 得到的离散时间噪声。据我们所知，归一化残差如果远大于几，说明假定的噪声太小，或者数据中有什么地方不对；如果远小于一，说明假定的噪声比数据显示的大得多。未归一化的残差是物理误差：其中以像素为单位的重投影误差，就是用来与相机标定比较的那个量。

## 报告 PDF

### report-cam.pdf（相机标定）

源代码绘制这些页：

| 页 | 显示的内容 |
|---|---|
| Obs. graph（观测图） | 哪些相机同时看到了标定板；边的权重是共同观测的数量。每台相机都必须连通 |
| camera system（相机系统） | 估计出的各相机三维位姿，用来与真实设备比较 |
| cam0: estimated poses（估计位姿） | 标定板相对 cam0 的各个位姿 |
| camN: polar error（极角误差） | 重投影误差随与光轴夹角的变化，外加一张直方图，显示每个角度上看到了多少角点 |
| camN: azimuthal error（方位角误差） | 重投影误差随绕光轴角度的变化，外加一张直方图 |
| camN: reprojection errors（重投影误差） | 左：画在图像上的每个检测到的角点；右：x 和 y 误差的散点图，按图像着色 |
| Outlier corners（离群角点） | 离群角点被剔除的位置，画在图像上 |

角点图让覆盖情况一目了然：标定板应当到达过图像的每个部分，尤其是四角，[相机标定指南](https://egocam.ai/zh-cn/calibration/camera-calibration/)解释了这一点。极角误差的直方图按角度显示同样的信息。根据我们的经验，如果极角误差图上的误差朝着最大角度方向攀升，这就是畸变模型与镜头不匹配，或者图像边缘附近视图太少的最明显的迹象。

### report-imucam.pdf（相机–IMU 标定）

源代码为每个 IMU 绘制：

| 页 | 显示的内容 | 要看什么 |
|---|---|---|
| imu0: estimated poses（估计位姿） | 轨迹 | 各个方向上都有运动 |
| imu0: measurement rates（测量速率） | 采样率随时间的变化，由时间戳之间的间隔得到 | 在预期采样率上的一条平线 |
| imu0: accelerations, angular velocities（加速度、角速度） | 预测值与测量值的对比 | 曲线重合 |
| imu0: acceleration error, angular velocity error（加速度误差、角速度误差） | 各轴的残差，带有位于假定离散时间噪声 ±3σ 处的虚线 | 残差在虚线之内 |
| imu0: accelerometer bias, gyroscope bias（加速度计零偏、陀螺仪零偏） | 估计出的零偏随时间的变化，带有由随机游走得到的 ±3σ 界限 | 零偏在界限之内 |
| camN: reprojection errors（重投影误差） | 误差散点图，带有一个半径为 3 × `--reprojection-sigma` 的虚线圆 | 点在圆内 |

wiki 的 [RealSense 教程](https://github.com/ethz-asl/kalibr/wiki/Calibrating-Intel-RealSense-Cameras)用几行字给出了检查项：

- "Inspect the IMU time dt plot carefully in the PDF report!"（意为：请仔细检查 PDF 报告中的 IMU 时间间隔 dt 图！）
- "Your accelerometer and gyroscope errors are within their 3-sigma bounds (if not then your IMU noise or the dataset are incorrect)"（意为：你的加速度计和陀螺仪误差在各自的 3-sigma 界限之内（如果不在，就是你的 IMU 噪声或数据集不正确））
- "Ensure that your estimated biases do not leave your 3-sigma bounds. If they do leave then your trajectory was too dynamic, or your noise values are not good."（意为：确保估计出的零偏不超出 3-sigma 界限。如果超出了，就是你的轨迹运动过于剧烈，或者你的噪声值不好。）
- "Sanity check your final rotation and translation with hand-measured values."（意为：用手工测量的值对最终的旋转和平移做合理性检查。）

[多 IMU 页面](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)解释了为什么要画 3σ 线：为了 "foster an intuition about the correctness of the noise parameters and models"（意为：帮助建立对噪声参数和模型是否正确的直观认识）。

关于时间戳，[相机–IMU 指南](https://github.com/ethz-asl/kalibr/wiki/camera-imu-calibration)给出了一个 IMU 时间戳不好的例子，"where a burst of IMU are send at a rate of 1ms with gaps of 6ms between"（意为：其中一簇 IMU 数据以 1 ms 的间隔发出，各簇之间有 6 ms 的间隙），并说 "likely your hardware is messed up and you will run into calibration problems."（意为：很可能是你的硬件出了问题，你会在标定中遇到麻烦。）

### 好的数字是什么样的

Kalibr 的文档没有给出重投影误差的合格线。作为一个参考点，[Double Sphere 论文](https://arxiv.org/abs/1807.08957)对五个鱼眼镜头和广角镜头的标定，用其最佳模型得到的平均重投影误差在 0.127 到 0.227 像素之间（表 1）。根据我们的经验，一次清晰、照明良好、覆盖良好的标定，重投影误差远低于一个像素；误差达到一个像素或更大，就是一个信号：在使用结果之前，应当检查模糊、对焦、标定板的测量值和模型。单凭一个低的数字仍然证明不了多少；[相机标定指南](https://egocam.ai/zh-cn/calibration/camera-calibration/)解释了原因。

## 命令行工具

每个工具都可以用 `--h` 列出它的选项，wiki 就是这样演示的。Kalibr 运行在 ROS 1 上；[ROS 2 页面](https://github.com/ethz-asl/kalibr/wiki/ROS2-Calibration-Using-Kalibr)说 "Kalibr requires ROS1 to run"（意为：Kalibr 需要 ROS1 才能运行），并演示了如何转换 ROS 2 bag。

### kalibr_calibrate_cameras

一台或多台相机的内参和外参标定。相机保持静止，标定板移动；[指南](https://github.com/ethz-asl/kalibr/wiki/multiple-camera-calibration)要求 "that neighbouring cameras have overlapping fields of view"（意为：相邻相机的视场有重叠）。

| 参数 | 含义 |
|---|---|
| `--bag` | ROS bag |
| `--topics` | 图像话题，按相机顺序 |
| `--models` | 每个话题一个模型，顺序相同，例如 `pinhole-radtan` |
| `--target` | `target.yaml` |
| `--bag-from-to` | 只使用 bag 中的这一时间段，以秒为单位 |
| `--bag-freq` | 以这个频率提取特征，以 Hz 为单位 |
| `--approx-sync` | 在各相机之间匹配图像的时间容差，以秒为单位（默认 0.02） |
| `--mi-tol` | 加入一幅图像的互信息阈值（默认 0.2）；"Higher means fewer images will be added. Use -1 to force all images."（意为：值越高，加入的图像越少。用 -1 强制使用所有图像。） |
| `--qr-tol` | QR 分解因子的容差（默认 0.02） |
| `--no-shuffle` | 按顺序处理图像，而不是打乱顺序 |
| `--no-outliers-removal`、`--no-final-filtering` | 关闭角点离群值过滤 |
| `--min-views-outlier` | 用来启动离群值统计的视图数（默认 20） |
| `--use-blakezisserman` | 使用 Blake–Zisserman 鲁棒估计器 |
| `--plot-outliers`、`--plot`、`--verbose`、`--show-extraction` | 运行时显示更多信息 |
| `--dont-show-report` | 写出报告但不打开它 |
| `--export-poses` | 把优化后的位姿写入一个 CSV 文件 |

这个工具选择使用哪些图像是 "based on information theoretic measures"（意为：基于信息论的度量），依据的是 Maye, Furgale and Siegwart (2013)。如果它一开始就发散，wiki 的建议是 "just try to restart the calibration as the initial guesses are based on a random pick of images."（意为：重新启动标定试试即可，因为初始猜测是基于随机挑选的图像得出的。）

### kalibr_calibrate_imu_camera

一个或多个 IMU 相对一条已标定相机链的空间和时间标定。标定板保持静止，设备移动。

| 参数 | 含义 |
|---|---|
| `--bag` | 含有图像和 IMU 数据的 ROS bag |
| `--cam` | 来自 `kalibr_calibrate_cameras` 的 camchain（源代码把它拼作 `--cams`；wiki 和工具的用法说明文字写作 `--cam`） |
| `--imu` | 一个或多个 `imu.yaml` 文件；"The first IMU will be the reference IMU"（意为：第一个 IMU 将作为参考 IMU） |
| `--imu-models` | 每个 IMU 一个模型：`calibrated`（默认）、`scale-misalignment` 或 `scale-misalignment-size-effect` |
| `--target` | `target.yaml` |
| `--bag-from-to`、`--bag-freq` | 同上 |
| `--no-time-calibration` | 不估计 `timeshift_cam_imu` |
| `--max-iter` | 最大迭代次数（默认 30） |
| `--recover-covariance` | 同时计算结果的不确定度 |
| `--timeoffset-padding` | 估计过程中时间偏移可以移动多远，以秒为单位（默认 0.03） |
| `--reprojection-sigma` | 假定的角点检测噪声，以像素为单位（默认 1.0） |
| `--imu-delay-by-correlation` | 用相关法估计其他 IMU 相对 imu0 的时间偏移 |
| `--recompute-camera-chain-extrinsics` | 重新估计相机到相机的变换；源代码说这是 "exclusively recommended for debugging purposes"（意为：仅建议用于调试目的） |
| `--perform-synchronization` | 修正时钟的抖动和偏斜；wiki 警告 "this option will alter your timing"（意为：这个选项会改变你的时序），并使估计出的偏移失效 |
| `--show-extraction`、`--extraction-stepping`、`--verbose` | 运行时显示更多信息 |
| `--dont-show-report`、`--export-poses` | 同上 |

### kalibr_bagcreater

用图像文件和 IMU 的 CSV 文件生成一个 ROS bag（[bag 格式页面](https://github.com/ethz-asl/kalibr/wiki/bag-format)）：`kalibr_bagcreater --folder dataset-dir/. --output-bag awsome.bag`。

- 每台相机是一个文件夹，即 `cam0`、`cam1`，每幅图像的文件名是它以纳秒为单位的时间戳，例如 `1385030208726607500.png`。源代码接受 `.bmp`、`.png` 和 `.jpg`。
- IMU 文件是名字以 `imu` 开头的 CSV 文件，例如 `imu0.csv`，表头为 `timestamp,omega_x,omega_y,omega_z,alpha_x,alpha_y,alpha_z`，单位是 "timestamps=[ns], omega=[rad/s], alpha=[m/s^2]"（意为：时间戳的单位是 ns，omega 的单位是 rad/s，alpha 的单位是 m/s^2）。
- 生成的话题是 `/cam0/image_raw`、`/cam1/image_raw` 和 `/imu0`。

### kalibr_bagextractor

反过来：从 bag 中导出图像和 IMU 的 CSV 文件。参数：`--bag`、`--image-topics`、`--imu-topics`、`--output-folder`。

### kalibr_create_target_pdf

绘制一张用于打印的标定板。

| 参数 | 含义 |
|---|---|
| `--type` | `apriltag` 或 `checkerboard` |
| `--nx`、`--ny` | 横向和纵向的标签数（Aprilgrid）或内部角点数（棋盘格）；默认 6 和 7 |
| `--tsize` | 标签尺寸，以米为单位（默认 0.08） |
| `--tspace` | 标签间距 "in fraction of the edge size [0..1]"（意为：以边长的比例表示，取值 [0..1]）（默认 0.3），与 `tagSpacing` 是同一个比值 |
| `--tfam` | AprilTag 标签族（默认 `t36h11`） |
| `--skip-ids` | 要留空的标签 ID |
| `--csx`、`--csy` | 棋盘格方格尺寸，以米为单位（默认 0.05） |
| `--eps` | 同时写出一个 EPS 文件 |
| 输出名 | 文件名（默认 `target`） |

wiki 的示例：`kalibr_create_target_pdf --type apriltag --nx [NUM_COLS] --ny [NUM_ROWS] --tsize [TAG_WIDTH_M] --tspace [TAG_SPACING_PERCENT]`。尽管该示例中写着 "PERCENT"（意为：百分比），这个值是 0.3 这样的比例，而不是 30。这个生成器不能绘制圆点网格。

### 其他工具

| 工具 | 作用 |
|---|---|
| `kalibr_camera_validator --cam camchain.yaml --target target.yaml` | 实时 ROS 检查：显示重投影的角点，并且 "the reprojection error statistics are calculated and displayed for mono and inter-camera reprojection errors"（意为：针对单目重投影误差和相机间重投影误差，计算并显示重投影误差的统计值）（[calibration validator](https://github.com/ethz-asl/kalibr/wiki/calibration-validator)） |
| `kalibr_camera_focus --topic [IMAGE_TOPIC]` | 实时 ROS 对焦辅助工具，显示 "a measure of focus"（意为：一个对焦程度的度量值）（[camera focus](https://github.com/ethz-asl/kalibr/wiki/camera-focus)） |
| `kalibr_calibrate_rs_cameras` | 一台相机的卷帘快门内参，使用 `--model`（`pinhole-radtan-rs`、`pinhole-equi-rs` 或 `omni-radtan-rs`）、`--topic`、`--frame-rate` 和 `--inverse-feature-variance`（[rolling shutter](https://github.com/ethz-asl/kalibr/wiki/Rolling-Shutter-Camera-calibration)） |

## 参考来源

- Kalibr wiki，ETH Zurich ASL：[Home](https://github.com/ethz-asl/kalibr/wiki)、[YAML formats](https://github.com/ethz-asl/kalibr/wiki/Yaml-formats)、[Supported models](https://github.com/ethz-asl/kalibr/wiki/Supported-models)、[IMU noise model](https://github.com/ethz-asl/kalibr/wiki/IMU-Noise-Model)、[Calibration targets](https://github.com/ethz-asl/kalibr/wiki/calibration-targets)、[Multiple camera calibration](https://github.com/ethz-asl/kalibr/wiki/multiple-camera-calibration)、[Camera–IMU calibration](https://github.com/ethz-asl/kalibr/wiki/camera-imu-calibration)、[Multi-IMU and IMU intrinsic calibration](https://github.com/ethz-asl/kalibr/wiki/Multi-IMU-and-IMU-intrinsic-calibration)、[Bag format](https://github.com/ethz-asl/kalibr/wiki/bag-format)、[Calibration validator](https://github.com/ethz-asl/kalibr/wiki/calibration-validator)、[Camera focus](https://github.com/ethz-asl/kalibr/wiki/camera-focus)、[Rolling shutter camera calibration](https://github.com/ethz-asl/kalibr/wiki/Rolling-Shutter-Camera-calibration)、[ROS 2 calibration](https://github.com/ethz-asl/kalibr/wiki/ROS2-Calibration-Using-Kalibr)、[Calibrating Intel RealSense cameras](https://github.com/ethz-asl/kalibr/wiki/Calibrating-Intel-RealSense-Cameras)。
- Kalibr 源代码，[github.com/ethz-asl/kalibr](https://github.com/ethz-asl/kalibr)（提交 `1f60227`）：[ConfigReader.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_common/ConfigReader.py)（全部 YAML 字段和检查）、[kalibr_calibrate_cameras](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_calibrate_cameras)、[kalibr_calibrate_imu_camera](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_calibrate_imu_camera)、[CameraUtils.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_camera_calibration/CameraUtils.py)、[CameraCalibrator.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_camera_calibration/CameraCalibrator.py)、[GridCalibrationTargetAprilgrid.cpp](https://github.com/ethz-asl/kalibr/blob/master/aslam_cv/aslam_cameras_april/src/GridCalibrationTargetAprilgrid.cpp)、[IccSensors.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccSensors.py)、[IccUtil.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccUtil.py)、[IccPlots.py](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_imu_camera_calibration/IccPlots.py)、[kalibr_create_target_pdf](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_create_target_pdf)、[kalibr_bagcreater](https://github.com/ethz-asl/kalibr/blob/master/aslam_offline_calibration/kalibr/python/kalibr_bagcreater)，以及 [aslam_cv/aslam_cameras](https://github.com/ethz-asl/kalibr/tree/master/aslam_cv/aslam_cameras/include/aslam/cameras/implementation) 中的相机模型和畸变模型。
- Furgale, P., Rehder, J. and Siegwart, R. (2013). [Unified temporal and spatial calibration for multi-sensor systems](https://doi.org/10.1109/IROS.2013.6696514). *IEEE/RSJ IROS*, pp. 1280–1286.
- Rehder, J., Nikolic, J., Schneider, T., Hinzmann, T. and Siegwart, R. (2016). [Extending kalibr: Calibrating the extrinsics of multiple IMUs and of individual axes](https://doi.org/10.1109/ICRA.2016.7487628). *IEEE ICRA*, pp. 4304–4311.
- Usenko, V., Demmel, N. and Cremers, D. (2018). [The double sphere camera model](https://arxiv.org/abs/1807.08957). *International Conference on 3D Vision (3DV)*.
- Khomutenko, B., Garcia, G. and Martinet, P. (2016). [An enhanced unified camera model](https://doi.org/10.1109/LRA.2015.2502921). *IEEE Robotics and Automation Letters*, 1(1), pp. 137–144.
- Mei, C. and Rives, P. (2007). [Single view point omnidirectional camera calibration from planar grids](https://doi.org/10.1109/ROBOT.2007.364084). *IEEE ICRA*, pp. 3945–3950.
- Kannala, J. and Brandt, S. S. (2006). [A generic camera model and calibration method for conventional, wide-angle, and fish-eye lenses](https://doi.org/10.1109/TPAMI.2006.153). *IEEE Transactions on Pattern Analysis and Machine Intelligence*, 28(8), pp. 1335–1340.
- Devernay, F. and Faugeras, O. (2001). [Straight lines have to be straight](https://doi.org/10.1007/PL00013269). *Machine Vision and Applications*, 13(1), pp. 14–24（[公开副本和摘要](https://inria.hal.science/inria-00267247v1)）。
- Olson, E. (2011). [AprilTag: A robust and flexible visual fiducial system](https://doi.org/10.1109/ICRA.2011.5979561). *IEEE ICRA*.
- Maye, J., Furgale, P. and Siegwart, R. (2013). Self-supervised calibration for robotic systems. *IEEE Intelligent Vehicles Symposium*，引自 Kalibr 多相机页面。
- OpenCV 文档：[径向–切向畸变](https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga7dfb72c9cf9780a347fbe3d1c47e5d5a)和[鱼眼模型](https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html#details)。
- [allan_variance_ros](https://github.com/ori-drs/allan_variance_ros)，Oxford Robotics Institute。
