相机标定 - 坐标系变换

1. 预备知识

1.1 坐标系

  1. 世界坐标系:\(X_w\), \(Y_w\), \(Z_w\)
  2. 摄像机坐标系:\(X_c\), \(Y_c\), \(Z_c\)
  3. 图像坐标系:\(x\), \(y\)
  4. 像素坐标系:\(u\), \(v\)

1.2 参数

1.2.1 相机的内部参数矩阵

\[K= \begin{bmatrix} f_x & s & u_0 \\ 0 & f_y & v_0 \\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} \frac{f}{dx} & s & u_0 \\ 0 & \frac{f}{dy} & v_0 \\ 0 & 0 & 1 \end{bmatrix} \]

其中:
\(f_x, f_y\) 分别为摄像机X轴和Y轴上的像素单位焦距,\(f\) 为摄像机的物理焦距,\(dx, dy\) 为像元尺寸(即每个像素对应的物理尺寸)
\(u_0, v_0\) 为主点偏移,表示图像的像素中心
\(s\) 为图像轴不垂直时的倾斜系数,理想情况下是0。\(s=f_x\tan\alpha\)

像素倾斜的定义如下:

1.2.2 畸变系数

\(k_1\)\(k_2\)\(k_3\):径向畸变系数
\(p_1\)\(p_2\):切向畸变系数

OpenCV 中的畸变系数矩阵:\(\begin{bmatrix}k_1 & k_2 & p_1 & p_2 & k_3\end{bmatrix}\)

1.2.3 相机的外部参数矩阵

\[\begin{bmatrix} R_{3*3} & t_{3*1} \\ 0 & 1 \\ \end{bmatrix} = \begin{bmatrix} I & t_{3*1} \\ 0 & 1 \\ \end{bmatrix} \begin{bmatrix} R_{3*3} & 0 \\ 0 & 1 \\ \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & t_1 \\ 0 & 1 & 0 & t_2 \\ 0 & 0 & 1 & t_3 \\ 0 & 0 & 0 & 1 \end{bmatrix} × \begin{bmatrix} r_{11} & r_{12} & r_{13} & 0 \\ r_{21} & r_{22} & r_{23} & 0 \\ r_{31} & r_{32} & r_{33} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \]

其中:
\(R_{3*3}\):旋转矩阵,描述世界坐标系相对于摄像机坐标系的方向
\(T_{3*1}\):平移矩阵,描述了在摄像机坐标系下,空间原点的位置

2. 变换

2.1 图像坐标系\((x, y)\)至像素坐标系\((u,v)\)

两坐标轴正交:

\[\left\{ \begin{aligned} u & = \frac{x}{dx} + u_0 \\ v & = \frac{y}{dy} + v_0 \end{aligned} \right. \]

一般情况:

\[\left\{ \begin{aligned} u & = u_0 + \frac{x_d}{dx} - \frac{y_d \cot{\theta}}{d_x} \\ v & = v_0 + \frac{y_d}{dy \sin{\theta}} \end{aligned} \right. \]

齐次坐标形式:

\[\begin{bmatrix} u \\ v \\ 1 \end{bmatrix} = \begin{bmatrix} f_u & -f_u\cot{\theta} & u_0 \\ 0 & f_v/\sin{\theta} & v_0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x_d \\ y_d \\ 1 \end{bmatrix} \]

其中:
\(f_u = \frac{1}{d_x}\), \(f_v=\frac{1}{d_y}\)

2.2 相机坐标系\((X_c, Y_c, Z_c)\)至图像坐标系\((x, y)\)

\[Z_c \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} f & 0 & 0 & 0 \\ 0 & f & 0 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} \begin{bmatrix} X_c \\ Y_c \\ Z_c \\ 1 \end{bmatrix} \]

2.3 世界坐标系\((X_w, Y_w, Z_w)\)至相机坐标系\((X_c, Y_c, Z_c)\)

\[\begin{bmatrix} X_c \\ Y_c \\ Z_c \\ 1 \end{bmatrix} = \begin{bmatrix} R_{3*3} & T_{3*1} \\ O & 1 \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix} \]

2.4 从世界坐标系至像素坐标系

\[Z_c \begin{bmatrix} u \\ v \\ 1 \end{bmatrix} = K \begin{bmatrix} R & T \\ 0 & 1 \\ \end{bmatrix} \begin{bmatrix} X_w \\ Y_w \\ Z_w \\ 1 \end{bmatrix} \]

3. 畸变系数

径向畸变(Radial Distortion)

径向畸变有两种,分别是枕型畸变(Pincushion)和桶型畸变(Barrel)

径向畸变系数:

\[\begin{aligned} x_{distorted} & = x(1+k_1r^2+k_2r^4+k_3r^6) \\ y_{distorted} & = y(1+k_1r^2+k_2r^4+k_3r^6) \end{aligned} \]

其中:
\(x, y\):在归一化图像坐标系中未失真的坐标点
\(k_1, k_2, k_3\):径向畸变系数
\(r^2 = x^2 + y^2\)

切向畸变(Tangential Distortion)

当镜头和像平面不平行时,会发生切向畸变。

切向畸变系数:

\[\begin{aligned} x_{distorted} & = x[2p_1xy+p_2(r^2+2x^2)] \\ y_{distorted} & = y[p_1(r^2+2y^2)+2p_2xy] \\ \end{aligned} \]

其中:
\(x, y\):在归一化图像坐标系中未失真的坐标点
\(p_1, p_2\):切向畸变系数
\(r^2 = x^2 + y^2\)

4. 参考

posted @ 2020-06-06 14:25  郑大峰  阅读(722)  评论(0编辑  收藏  举报