相机投影模型总结

相机投影模型总结

本文旨在总结各种不同的相机投影模型,对于具体建模原理没有涉及。

对于以下的投影操作,此处首先假设已经获得一个待投影的3d点在相机坐标系下的三维坐标[x,y,z][x,y,z]^{\top},接下来通过相机投影后获得的二维像素坐标为[u,v][u,v]^{\top}

针孔模型——pinhole

针孔相机模型一般有四个参数,记为[fx,fy,cx,cy][f_x,f_y,c_x,c_y]^{\top},内参变换如下

[uv]=[fxxz+cxfyyz+cy]\left[\begin{array}{cc}u\\v \end{array}\right] = \left[\begin{array}{cc} f_x \frac{x}{z}+c_x\\ f_y \frac{y}{z}+c_y \end{array}\right]

Unified Camera Model

UCM有五个参数,记为[fx,fy,cx,cy,α][f_x,f_y,c_x,c_y,\alpha]^{\top},其中α[0,1]\alpha \in [0,1],投影变换如下

d=x2+y2+z2[uv]=[fxxαd+(1α)zfyyαd+(1α)z]+[cxcy]\begin{aligned} d&=\sqrt{x^2+y^2+z^2} \\ \left[\begin{array}{cc}u\\v \end{array}\right] &= \left[\begin{array}{cc} f_x\frac{x}{\alpha d + (1-\alpha)z}\\ f_y \frac{y}{\alpha d + (1-\alpha)z}\end{array}\right] + \left[\begin{array}{cc}c_x\\c_y \end{array}\right] \end{aligned}

可以发现,在α=1\alpha=1时,UCM退化为针孔模型。上述投影中在满足如下条件时可认为投影有效:

Ω={xR3z>wd},w={α1α, if α0.5,1αα if α>0.5,\begin{array}{c} \Omega=\left\{\mathbf{x} \in \mathbb{R}^{3} \mid z>-w d\right\}, \\ w=\left\{\begin{array}{ll} \frac{\alpha}{1-\alpha}, & \text { if } \alpha \leq 0.5, \\ \frac{1-\alpha}{\alpha} & \text { if } \alpha>0.5, \end{array}\right. \end{array}

上述投影变换其实是后人新总结的一种参数化形式,UCM最初的建模方式也是有五个参数[γx,γy,cx,cy,ξ][\gamma_{x},\gamma_y,c_x,c_y,\xi]^{\top},投影变换为

π(x,i)=[γxxξd+zγyyξd+z]+[cxcy]d=x2+y2+z2\begin{aligned} \pi(\mathbf{x}, \mathbf{i}) &=\left[\begin{array}{l} \gamma_{x} \frac{x}{\xi d+z} \\ \gamma_{y} \frac{y}{\xi d+z} \end{array}\right]+\left[\begin{array}{l} c_{x} \\ c_{y} \end{array}\right] \\ d &=\sqrt{x^{2}+y^{2}+z^{2}} \end{aligned}

这也是kalibr中的omni相机模型。

Extended Unified Camera Model

有人对UCM进行扩展,扩展后有六个参数[fx,fy,cx,cy,α,β][f_x,f_y,c_x,c_y,\alpha, \beta]^{\top},投影变换如下

d=β(x2+y2)+z2[uv]=[fxxαd+(1α)zfyyαd+(1α)z]+[cxcy]\begin{aligned} d&=\sqrt{\beta (x^2+y^2)+z^2} \\ \left[\begin{array}{cc}u\\v \end{array}\right] &= \left[\begin{array}{cc} f_x\frac{x}{\alpha d + (1-\alpha)z}\\ f_y \frac{y}{\alpha d + (1-\alpha)z}\end{array}\right] + \left[\begin{array}{cc}c_x\\c_y \end{array}\right] \end{aligned}

β=1\beta=1时,EUCM退化成UCM.

double sphere camera model

这是tum在2018年的一篇同名论文中提出的一种用于鱼眼镜头的相机模型,逆运算具有闭式解。此模型也具有6个参数[fx,fy,cx,cy,ξ,α][f_x,f_y,c_x,c_y,\xi,\alpha]^{\top},投影操作如下

d1=x2+y2+z2d2=x2+y2+(ξd1+z)2[uv]=[fxxαd2+(1α)(ξd1+z)fyyαd2+(1α)(ξd1+z)]+[cxcy]\begin{aligned} d_1&=\sqrt{x^2+y^2+z^2} \\ d_2 &= \sqrt{x^2 +y^2+(\xi d_1+z)^2} \\ \left[\begin{array}{cc}u\\v \end{array}\right] &= \left[\begin{array}{cc} f_x\frac{x}{\alpha d_2 + (1-\alpha)(\xi d_1+z)}\\ f_y \frac{y}{\alpha d_2 + (1-\alpha)(\xi d_1+z)}\end{array}\right] + \left[\begin{array}{cc}c_x\\c_y \end{array}\right] \end{aligned}

当满足以下条件时,可以认为上述投影有效

Ω={xR3z>w2d1}w2=w1+ξ2w1ξ+ξ2+1w1={α1α, if α0.51αα if α>0.5\begin{aligned} \Omega &=\left\{\mathbf{x} \in \mathbb{R}^{3} \mid z>-w_{2} d_{1}\right\} \\ w_{2} &=\frac{w_{1}+\xi}{\sqrt{2 w_{1} \xi+\xi^{2}+1}} \\ w_{1} &=\left\{\begin{array}{ll} \frac{\alpha}{1-\alpha}, & \text { if } \alpha \leq 0.5 \\ \frac{1-\alpha}{\alpha} & \text { if } \alpha>0.5 \end{array}\right. \end{aligned}

radial-tangential

径向切向是一种最常见的畸变模型,一般用于普通相机。此处将针孔内参模型与其组合,其参数包括针孔内参参数[fx,fy,cx,cy][f_x,f_y,c_x,c_y]^{\top}与畸变参数[k1,k2,p1,p2][k_1,k_2,p_1,p_2]^{\top},投影过程如下

xn=xzyn=yzr2=xn2+yn2xd=xn(1+k1r2+k2r4)+2p1xnyn+p2(r2+2xn2)yd=yn(1+k1r2+k2r4)+p1(r2+2yn2)+2p2xnyn\begin{aligned} x_n &= \frac{x}{z} \\ y_n &= \frac{y}{z} \\ r^2 &= x_n^2+y_n^2 \\ x_d &= x_n(1+k_1r^2+k_2r^4) + 2p_1x_ny_n+p_2(r^2+2x_n^2) \\ y_d &= y_n(1+k_1r^2+k_2r^4) + p_1(r^2+2y_n^2) + 2p_2x_ny_n \\ \end{aligned}

[uv]=[fxxdfyyd]+[cxcy]\left[\begin{array}{cc} u \\ v \end{array}\right] = \left[\begin{array}{ll} f_{x} x_d \\ f_{y} y_d \end{array}\right] + \left[\begin{array}{l} c_{x} \\ c_{y} \end{array}\right] \\

Kannala-Brandt Camera Model

一般将kalibr中pinhole(内参)+equidistant(畸变)的组合就是此模型,其参数包括针孔内参参数[fx,fy,cx,cy][f_x,f_y,c_x,c_y]^{\top}与畸变参数[k1,k2,k3,k4][k_1,k_2,k_3,k_4]^{\top},畸变参数也可以只有前两个。其整体投影过程如下:

[uv]=[fxd(θ)xrfyd(θ)yr]+[cxcy]r=x2+y2θ=atan2(r,z)d(θ)=θ+k1θ3+k2θ5+k3θ7+k4θ9\begin{aligned} \left[\begin{array}{cc}u\\v \end{array}\right] &=\left[\begin{array}{ll} f_{x} d(\theta) \frac{x}{r} \\ f_{y} d(\theta) \frac{y}{r} \end{array}\right]+\left[\begin{array}{l} c_{x} \\ c_{y} \end{array}\right] \\ r &=\sqrt{x^{2}+y^{2}} \\ \theta &=\operatorname{atan} 2(r, z) \\ d(\theta) &=\theta+k_{1} \theta^{3}+k_{2} \theta^{5}+k_{3} \theta^{7}+k_{4} \theta^{9} \end{aligned}

这其实也是opencv中使用的鱼眼相机模型cv::fisheye,不过opencv的鱼眼相机模型与上述相比,内参变换步骤比针孔模型多了一个参数α\alpha,最终投影变换过程如下

a=xzb=yzr=a2+b2θ=atan(r)d(θ)=θ+k1θ3+k2θ5+k3θ7+k4θ9x=(ad(θ)r)y=(bd(θ)r)\begin{aligned} a &= \frac{x}{z} \\ b &= \frac{y}{z} \\ r &=\sqrt{a^{2}+b^{2}} \\ \theta &= atan(r) \\ d(\theta) &=\theta+k_{1} \theta^{3}+k_{2} \theta^{5}+k_{3} \theta^{7}+k_{4} \theta^{9} \\ x' &= (\frac{ad(\theta)}{r}) \\ y' &= (\frac{bd(\theta)}{r}) \\ \end{aligned}

[uv]=[fx(x+αy)fyy]+[cxcy]\left[\begin{array}{cc} u \\ v \end{array}\right] = \left[\begin{array}{ll} f_{x} (x' + \alpha y') \\ f_{y} y' \end{array}\right] + \left[\begin{array}{l} c_{x} \\ c_{y} \end{array}\right] \\

上述两种投影中,畸变部分是相同的,内参变换部分稍有不同。其中atan2atan2atanatan函数稍有区别,但最终意图一致。

Field-of-View Camera Model

其实在kalibr中其实将FOV描述为一种畸变模型,只有一个参数ww,与针孔内参模型进行组合后参数向量为[fx,fy,cx,cy,w][f_x,f_y,c_x,c_y,w]^{\top},其投影过程如下:

ru=x2+y2rd=atan2(2rutan(w2),z)wr_u=\sqrt{x^2+y^2} \\ r_d = \frac{atan2(2r_utan(\frac{w}{2}),z)}{w} \\

[uv]=[fxrdxrufyrdyru]+[cxcy]\left[\begin{array}{cc}u\\v \end{array}\right] = \left[\begin{array}{cc} f_x r_d \frac{x}{r_u} \\ f_y r_d \frac{y}{r_u}\end{array}\right] + \left[\begin{array}{cc}c_x\\c_y \end{array}\right]

kalibr中相机模型的确定

kalibr中相机模型CameraGeometry分类可以看作四层树的结构,每层分类依据为

    1. 内参模型(pinhole/omni/extendedUnified/DoubleSphere)
    1. 畸变模型(nodistortion/radialTangential/equidistant/Fov)
    1. 曝光方式(globalShutter/rollingShutter)
    1. 掩膜类型(nomask/指定mask)

其中与本文中相关的是内参模型+畸变模型的相机投影模型,其中每种内参模型都定义了一个模板类,而畸变方式通过内参模型类的模板参数来指定。按照上述内参与畸变的自由组合,按理来说kalibr中应该存在16种相机投影模型,但实际上kalibr中仅仅只实现了10种,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
typedef CameraGeometry<PinholeProjection<NoDistortion>, GlobalShutter, NoMask> PinholeCameraGeometry;
typedef CameraGeometry<PinholeProjection<RadialTangentialDistortion>,
GlobalShutter, NoMask> DistortedPinholeCameraGeometry;
typedef CameraGeometry<PinholeProjection<EquidistantDistortion>, GlobalShutter,
NoMask> EquidistantDistortedPinholeCameraGeometry;
typedef CameraGeometry<PinholeProjection<FovDistortion>, GlobalShutter,
NoMask> FovDistortedPinholeCameraGeometry;

typedef CameraGeometry<OmniProjection<NoDistortion>, GlobalShutter, NoMask> OmniCameraGeometry;
typedef CameraGeometry<OmniProjection<RadialTangentialDistortion>,
GlobalShutter, NoMask> DistortedOmniCameraGeometry;
typedef CameraGeometry<OmniProjection<EquidistantDistortion>, GlobalShutter,
NoMask> EquidistantDistortedOmniCameraGeometry;
typedef CameraGeometry<OmniProjection<FovDistortion>, GlobalShutter,
NoMask> FovDistortedOmniCameraGeometry;

typedef CameraGeometry<ExtendedUnifiedProjection<NoDistortion>, GlobalShutter, NoMask> ExtendedUnifiedCameraGeometry;
typedef CameraGeometry<DoubleSphereProjection<NoDistortion>, GlobalShutter, NoMask> DoubleSphereCameraGeometry;
  • 其中针孔内参变换与四种畸变都进行了组合
  • omni也和四种畸变进行了组合:首先通过omni的ξ\xi参数进行归一化投影,然后进行畸变,最后通过omni另外四个参数进行类似针孔的内参变换。
  • 剩下的EUCM与DSCM都是只实现了不加畸变的版本,就是上文中介绍的形式(其实有一部分原因是这两种模型本身就带有畸变建模)

其实可以发现kalibr想要将相机投影通过内参+畸变的形式进行划分管理,可惜很多投影模型中这两部分其实是耦合在一起的。并且不同开源库中对相同投影模型使用了不同的参数化形式,因此相机投影模型这一块在初学者看来会比较繁杂。

参考文献

[1] https://docs.opencv.org/

[2] https://github.com/ethz-asl/kalibr/

[3] The Double Sphere Camera Model (V. Usenko, N. Demmel and D. Cremers), In Proc. of the Int. Conference on 3D Vision (3DV), 2018.


相机投影模型总结
http://line.com/2022/03/21/2022-03-21-camera-model/
作者
Line
发布于
2022年3月21日
许可协议