IPM逆透视变换问题(3):Ground --> Image

该文详细阐述了如何通过一系列的矩阵变换,将世界坐标系中的点转换到图像像素坐标系。首先,介绍了坐标系定义及旋转角度表示,然后依次说明了像素坐标系到图像坐标系、图像坐标系到相机坐标系、相机坐标系到世界坐标系的变换。最终,整合这些变换得到从世界坐标到像素坐标的完整变换矩阵,并指出在仅处理地面上点的情况下,变换矩阵可以简化。

IPM逆透视变换问题(3):Ground --> Image

1. 同样如果前置条件如下:

  1. 坐标系坐标系定义为:世界(右-前-上),相机(右-下-前),像素(右-下);
  2. 旋转角度表示为:绕zzz轴为yawyawyaw偏航角,绕yyy轴为rollrollroll滚转角,绕xxx轴负方向为pitchpitchpitch俯仰角,正负按照右手定则;
  3. 实际上在表达yaw,pitch,rollyaw,pitch,rollyaw,pitch,roll姿态角时默认在(前-左-上)坐标系上进行,因此在表达这些角度时也可以增加一个(前-左-上)坐标系,从乘一次旋转矩阵。

2. 则点从世界坐标系到像素坐标系透视变换如下:

像素坐标系图像坐标系的变换为:
Tpi=Tip−1=[fx0cx0fycy001](16) \begin{aligned} T_{pi} &= T_{ip}^{-1} \\ &=\begin{bmatrix}f_x&0&c_x\\ 0&f_y&c_y\\ 0&0&1\end{bmatrix} \qquad &(16) \end{aligned} Tpi=Tip1=fx000fy0cxcy1(16)

图像坐标系相机坐标系的变换(对齐过程)为:
Tic=[1zc00001zc00001zc0](17) \begin{aligned} T_{ic} &=\begin{bmatrix}\frac{1}{z_c}&0&0&0\\ 0&\frac{1}{z_c}&0&0\\ 0&0&\frac{1}{z_c}&0\end{bmatrix} \qquad &(17) \end{aligned} Tic=zc1000zc1000zc1000(17)

相机坐标系世界坐标系的变换为:
Tcw=Twc−1=Toc−1⋅Two−1=Toc−1⋅Twr−1⋅Twt−1=Toc−1⋅Twx−1⋅Twy−1⋅Twz−1⋅Twt−1Tcw=[100000−1001000001]⋅[10000cos⁡(α)sin⁡(α)00−sin⁡(α)cos⁡(α)00001]⋅[1000010000100001]⋅[cos(γ)sin(γ)00−sin(γ)cos(γ)0000100001]⋅[10000100001−h0001]Tcw=[cos⁡(γ)sin⁡(γ)00−sin⁡(α)sin⁡(γ)sin⁡(α)cos⁡(γ)−cos⁡(α)hcos⁡(α)−cos⁡(α)sin⁡(γ)cos⁡(α)cos⁡(γ)sin⁡(α)−hsin⁡(α)0001](17) \begin{aligned} T_{cw} &= T_{wc}^{-1} \\ &= T_{oc}^{-1} \cdot T_{wo}^{-1} \\ &= T_{oc}^{-1} \cdot T_{wr}^{-1} \cdot T_{wt}^{-1} \\ &= T_{oc}^{-1} \cdot T_{wx}^{-1} \cdot T_{wy}^{-1} \cdot T_{wz}^{-1} \cdot T_{wt}^{-1} \\ T_{cw} &= \begin{bmatrix}1&0&0&0\\ 0&0&-1&0\\ 0&1&0&0\\ 0&0&0&1\end{bmatrix} \cdot \\ &\begin{bmatrix}1&0&0&0\\ 0&\cos \left(α\right)&\sin \left(α\right)&0\\ 0&-\sin \left(α\right)&\cos \left(α\right)&0\\ 0&0&0&1\end{bmatrix} \cdot \begin{bmatrix}1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1\end{bmatrix} \cdot \begin{bmatrix}cos\left(\gamma \right)&sin\left(\gamma \right)&0&0\\ -sin\left(\gamma \right)&cos\left(\gamma \right)&0&0\\ 0&0&1&0\\ 0&0&0&1\end{bmatrix} \cdot \\ &\begin{bmatrix}1&0&0&0\\ 0&1&0&0\\ 0&0&1&-h\\ 0&0&0&1\end{bmatrix}\\ T_{cw} &= \begin{bmatrix}\cos \left(γ\right)&\sin \left(γ\right)&0&0\\ -\sin \left(α\right)\sin \left(γ\right)&\sin \left(α\right)\cos \left(γ\right)&-\cos \left(α\right)&h\cos \left(α\right)\\ -\cos \left(α\right)\sin \left(γ\right)&\cos \left(α\right)\cos \left(γ\right)&\sin \left(α\right)&-h\sin \left(α\right)\\ 0&0&0&1\end{bmatrix} \qquad &(17) \end{aligned} TcwTcwTcw=Twc1=Toc1Two1=Toc1Twr1Twt1=Toc1Twx1Twy1Twz1Twt1=100000100100000110000cos(α)sin(α)00sin(α)cos(α)000011000010000100001cos(γ)sin(γ)00sin(γ)cos(γ)000010000110000100001000h1=cos(γ)sin(α)sin(γ)cos(α)sin(γ)0sin(γ)sin(α)cos(γ)cos(α)cos(γ)00cos(α)sin(α)00hcos(α)hsin(α)1(17)

世界坐标系图像像素坐标系的变换为:
Tpw=Tpi⋅Tic⋅Tcw=[fx0cx0fycy001][1zc00001zc00001zc0][cos⁡(γ)sin⁡(γ)00−sin⁡(α)sin⁡(γ)sin⁡(α)cos⁡(γ)−cos⁡(α)hcos⁡(α)−cos⁡(α)sin⁡(γ)cos⁡(α)cos⁡(γ)sin⁡(α)−hsin⁡(α)0001]=1zc[cos⁡(γ)fx−sin⁡(γ)cos⁡(α)cxsin⁡(γ)fx+cos⁡(γ)cos⁡(α)cxsin⁡(α)cx−hsin⁡(α)cx−sin⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)cos⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)sin⁡(α)cy−cos⁡(α)fy−h(sin⁡(α)cy−cos⁡(α)fy)−sin⁡(γ)cos⁡(α)cos⁡(γ)cos⁡(α)sin⁡(α)−hsin⁡(α)](18) \begin{aligned} T_{pw} &= T_{pi} \cdot T_{ic} \cdot T_{cw} \\ &=\begin{bmatrix}f_x&0&c_x\\ 0&f_y&c_y\\ 0&0&1\end{bmatrix} \begin{bmatrix}\frac{1}{z_c}&0&0&0\\ 0&\frac{1}{z_c}&0&0\\ 0&0&\frac{1}{z_c}&0\end{bmatrix} \begin{bmatrix}\cos \left(γ\right)&\sin \left(γ\right)&0&0\\ -\sin \left(α\right)\sin \left(γ\right)&\sin \left(α\right)\cos \left(γ\right)&-\cos \left(α\right)&h\cos \left(α\right)\\ -\cos \left(α\right)\sin \left(γ\right)&\cos \left(α\right)\cos \left(γ\right)&\sin \left(α\right)&-h\sin \left(α\right)\\ 0&0&0&1\end{bmatrix} \\ &= {\normalsize \frac{1}{z_c}\begin{bmatrix} \cos(\gamma)f_x-\sin(\gamma)\cos(\alpha)c_x &\sin(\gamma)f_x+\cos(\gamma)\cos(\alpha)c_x &\sin(\alpha)c_x &-h\sin(\alpha)c_x \\ -\sin(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &\cos(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &\sin(\alpha)c_y-\cos(\alpha)f_y &-h(\sin(\alpha)c_y-\cos(\alpha)f_y) \\ -\sin(\gamma)\cos(\alpha) &\cos(\gamma)\cos(\alpha) &\sin(\alpha)&-h\sin(\alpha)\end{bmatrix}} \qquad &(18) \end{aligned} Tpw=TpiTicTcw=fx000fy0cxcy1zc1000zc1000zc1000cos(γ)sin(α)sin(γ)cos(α)sin(γ)0sin(γ)sin(α)cos(γ)cos(α)cos(γ)00cos(α)sin(α)00hcos(α)hsin(α)1=zc1cos(γ)fxsin(γ)cos(α)cxsin(γ)(sin(α)fy+cos(α)cy)sin(γ)cos(α)sin(γ)fx+cos(γ)cos(α)cxcos(γ)(sin(α)fy+cos(α)cy)cos(γ)cos(α)sin(α)cxsin(α)cycos(α)fysin(α)hsin(α)cxh(sin(α)cycos(α)fy)hsin(α)(18)

世界坐标系的点变换到图像像素坐标系的点的过程为:
[uv1]=Tpw⋅[xwywzw1]=1zc[cos⁡(γ)fx−sin⁡(γ)cos⁡(α)cxsin⁡(γ)fx+cos⁡(γ)cos⁡(α)cxsin⁡(α)cx−hsin⁡(α)cx−sin⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)cos⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)sin⁡(α)cy−cos⁡(α)fy−h(sin⁡(α)cy−cos⁡(α)fy)−sin⁡(γ)cos⁡(α)cos⁡(γ)cos⁡(α)sin⁡(α)−hsin⁡(α)][xwywzw1]=1zc[xw(cos⁡(γ)fx−sin⁡(γ)cxcos⁡(α))+yw(cos⁡(γ)cxcos⁡(α)+sin⁡(γ)fx)+cxzwsin⁡(α)−cxhsin⁡(α)−sin⁡(γ)xw(cos⁡(α)cy+sin⁡(α)fy)+cos⁡(γ)yw(cos⁡(α)cy+sin⁡(α)fy)+zw(sin⁡(α)cy−cos⁡(α)fy)−h(sin⁡(α)cy−cos⁡(α)fy)−sin⁡(γ)xwcos⁡(α)+cos⁡(γ)ywcos⁡(α)+zwsin⁡(α)−hsin⁡(α)](19) \begin{aligned} \begin{bmatrix}u\\ v\\ 1\end{bmatrix} &= T_{pw} \cdot \begin{bmatrix}x_w\\ y_w\\ z_w\\ 1\end{bmatrix} \\ &={\normalsize \frac{1}{z_c}\begin{bmatrix} \cos(\gamma)f_x-\sin(\gamma)\cos(\alpha)c_x &\sin(\gamma)f_x+\cos(\gamma)\cos(\alpha)c_x &\sin(\alpha)c_x &-h\sin(\alpha)c_x \\ -\sin(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &\cos(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &\sin(\alpha)c_y-\cos(\alpha)f_y &-h(\sin(\alpha)c_y-\cos(\alpha)f_y) \\ -\sin(\gamma)\cos(\alpha) &\cos(\gamma)\cos(\alpha) &\sin(\alpha)&-h\sin(\alpha)\end{bmatrix}} \begin{bmatrix}x_w\\ y_w\\ z_w\\ 1\end{bmatrix} \\ &={\normalsize \frac{1}{z_c}\begin{bmatrix} x_w\left(\cos \left(γ\right)f_x-\sin \left(γ\right)c_x\cos \left(α\right)\right)+y_w\left(\cos \left(γ\right)c_x\cos \left(α\right)+\sin \left(γ\right)f_x\right)+c_xz_w\sin \left(α\right)-c_xh\sin \left(α\right)\\ -\sin \left(γ\right)x_w\left(\cos \left(α\right)c_y+\sin \left(α\right)f_y\right)+\cos \left(γ\right)y_w\left(\cos \left(α\right)c_y+\sin \left(α\right)f_y\right)+z_w\left(\sin \left(α\right)c_y-\cos \left(α\right)f_y\right)-h\left(\sin \left(α\right)c_y-\cos \left(α\right)f_y\right)\\ -\sin \left(γ\right)x_w\cos \left(α\right)+\cos \left(γ\right)y_w\cos \left(α\right)+z_w\sin \left(α\right)-h\sin \left(α\right)\end{bmatrix}} \qquad &(19) \end{aligned} uv1=Tpwxwywzw1=zc1cos(γ)fxsin(γ)cos(α)cxsin(γ)(sin(α)fy+cos(α)cy)sin(γ)cos(α)sin(γ)fx+cos(γ)cos(α)cxcos(γ)(sin(α)fy+cos(α)cy)cos(γ)cos(α)sin(α)cxsin(α)cycos(α)fysin(α)hsin(α)cxh(sin(α)cycos(α)fy)hsin(α)xwywzw1=zc1xw(cos(γ)fxsin(γ)cxcos(α))+yw(cos(γ)cxcos(α)+sin(γ)fx)+cxzwsin(α)cxhsin(α)sin(γ)xw(cos(α)cy+sin(α)fy)+cos(γ)yw(cos(α)cy+sin(α)fy)+zw(sin(α)cycos(α)fy)h(sin(α)cycos(α)fy)sin(γ)xwcos(α)+cos(γ)ywcos(α)+zwsin(α)hsin(α)(19)

具体计算时由于只处理地面上的点,即zw=0z_w = 0zw=0,所以TpwT_{pw}Tpw第三列均是与0相乘,为了简化计算第三列可以全部设为0,且最后经过单位化消去了zcz_czc。最后得到计算IPM时从世界地面到像素的变换可从式(18)简化表示为T3×4T_{3\times 4}T3×4

T3×4=[cos⁡(γ)fx−sin⁡(γ)cos⁡(α)cxsin⁡(γ)fx+cos⁡(γ)cos⁡(α)cx0−hsin⁡(α)cx−sin⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)cos⁡(γ)(sin⁡(α)fy+cos⁡(α)cy)0−h(sin⁡(α)cy−cos⁡(α)fy)−sin⁡(γ)cos⁡(α)cos⁡(γ)cos⁡(α)0−hsin⁡(α)](20) \begin{aligned} T_{3\times 4} &= {\normalsize \begin{bmatrix} \cos(\gamma)f_x-\sin(\gamma)\cos(\alpha)c_x &\sin(\gamma)f_x+\cos(\gamma)\cos(\alpha)c_x &0 &-h\sin(\alpha)c_x \\ -\sin(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &\cos(\gamma)(\sin(\alpha)f_y+\cos(\alpha)c_y) &0 &-h(\sin(\alpha)c_y-\cos(\alpha)f_y) \\ -\sin(\gamma)\cos(\alpha) &\cos(\gamma)\cos(\alpha) &0&-h\sin(\alpha)\end{bmatrix}} \qquad &(20) \end{aligned} T3×4=cos(γ)fxsin(γ)cos(α)cxsin(γ)(sin(α)fy+cos(α)cy)sin(γ)cos(α)sin(γ)fx+cos(γ)cos(α)cxcos(γ)(sin(α)fy+cos(α)cy)cos(γ)cos(α)000hsin(α)cxh(sin(α)cycos(α)fy)hsin(α)(20)


同样的如果式(20)中的角度α,γ\alpha,\gammaα,γ取负值,提取最后一列的−h-hh
则所有的 sinsinsin 值取反,同时矩阵的第三列均为0,第四列提取出−h-hh,此时即得到下式:

TIG=[fxcos⁡(γ)+cos⁡(α)sin⁡(γ)cx−fxsin⁡(γ)+cos⁡(α)cos⁡(γ)cx0−sin⁡(α)cxsin⁡(γ)(−fysin⁡(α)+cos⁡(α)cy)cos⁡(γ)(−fysin⁡(α)+cos⁡(α)cy)0−fycos⁡(α)−sin⁡(α)cycos⁡(α)sin⁡(γ)cos⁡(α)cos⁡(γ)0−sin⁡(α)](21) {\color{darkorange} \begin{aligned} T_{IG} &= \begin{bmatrix} f_x\cos(\gamma)+\cos(\alpha) \sin(\gamma)c_x &-f_x\sin(\gamma)+\cos(\alpha) \cos(\gamma)c_x &0 &-\sin(\alpha)c_x \\ \sin(\gamma)(-f_y \sin(\alpha)+\cos(\alpha)c_y) &\cos(\gamma)(-f_y \sin(\alpha)+\cos(\alpha)c_y) &0 &-f_y\cos(\alpha)-\sin(\alpha)c_y \\ \cos(\alpha) \sin(\gamma) &\cos(\alpha) \cos(\gamma) &0 &-\sin(\alpha) \end{bmatrix} \qquad(21) \end{aligned}} TIG=fxcos(γ)+cos(α)sin(γ)cxsin(γ)(fysin(α)+cos(α)cy)cos(α)sin(γ)fxsin(γ)+cos(α)cos(γ)cxcos(γ)(fysin(α)+cos(α)cy)cos(α)cos(γ)000sin(α)cxfycos(α)sin(α)cysin(α)(21)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值