2022.8.24
崔星星
已知单张具有3条正交消失线的场景图像(或者至少有2条正交线,此时假设主点为图像中心),则可直接估算相机内参,另外如果已知场景图像中某些物体的实际尺寸或者坐标,则还可估计相机外参旋转矩阵
在基于3个消失点坐标计算已知的情况下,可以分别通过计算相机内参
- 代数方法:
单张图像场景中,三个正交的消失线方向向量 $e_1 =\left\lbrack \begin{array}{c} 1\ 0\ 0 \end{array}\right\rbrack ,e_2 =\left\lbrack \begin{array}{c} 0\ 1\ 0 \end{array}\right\rbrack ,e_3 =\left\lbrack \begin{array}{c} 0\ 0\ 1 \end{array}\right\rbrack$ , 满足投影公式
$\lambda_i \left\lbrack \begin{array}{c} x\ 1 \end{array}\right\rbrack =K*\left\lbrack R,t\right\rbrack *\left\lbrack \begin{array}{c} e_i \ 0 \end{array}\right\rbrack$ , (1)
注意位于无限远处的消失点齐次坐标是 $\left\lbrack \begin{array}{c} e_i \ 0 \end{array}\right\rbrack$ .整理上式,得:
$e_i =\lambda_i R^T K^{-1} \left\lbrack \begin{array}{c} x\ 1 \end{array}\right\rbrack$ , (2)
又由正交性约束,有
${{\left\lbrack \begin{array}{c} x\ 1 \end{array}\right\rbrack }_i }^T K^{-T} K^{-1} {\left\lbrack \begin{array}{c} x\ 1 \end{array}\right\rbrack }_j =0$ , (3)
K的求解通过(3)求解,实现为calIntrinsicFrom3VanishingPts.m函数。
- 几何方法:
四面体PABC为直角四面体(顶点P为互相垂直的三条棱线经过),底面三角形ABC为像平面,A,B,C为图像平面的三个消失点坐标,其中z值为
详细几何分析见calIntrinsicGeometricAnalysis.mlx,实现见calTritetrahedron.m函数。
- 代数方法:
由
$\lambda_i {\left\lbrack \begin{array}{c} x_1 \ x_2 \ 1 \end{array}\right\rbrack }_i ={KRe}_i$ , (4)
两边左乘
$\lambda_i K^{-1} {\left\lbrack \begin{array}{c} x_1 \ x_2 \ 1 \end{array}\right\rbrack }_i ={R*e}_i$ , (5)
注意: ${R*e}1 =\left\lbrack r{1,} r_2 ,r_3 \right\rbrack \left\lbrack \begin{array}{c} 1\ 0\ 0 \end{array}\right\rbrack =r_1$ ,得:
${r_i =\lambda }_i K^{-1} {\left\lbrack \begin{array}{c} x_1 \ x_2 \ 1 \end{array}\right\rbrack }_i$ ,(其中
- 几何方法:
- 代数方法:
这里边计算边分析推导:
syms f u0 v0
syms X [3,1]
syms x [2,1]
syms R [3,3]
syms t [3,1]
展开,写成标量形式,即 $\lambda_i \left\lbrack \begin{array}{c} x_1 \ x_2 \ 1 \end{array}\right\rbrack =\left\lbrack \begin{array}{ccc} f & 0 & u_0 \ 0 & f & v_0 \ 0 & 0 & 1 \end{array}\right\rbrack *\left\lbrack \begin{array}{cccc} R_{11} & R_{12} & R_{13} & t_1 \ R_{21} & R_{22} & R_{23} & t_2 \ R_{31} & R_{32} & R_{33} & t_3 \end{array}\right\rbrack *\left\lbrack \begin{array}{c} X_1 \ X_2 \ X_3 \ 1 \end{array}\right\rbrack$
其中内参矩阵
K = [f,0,u0;0,f,v0;0,0,1]
K = $\displaystyle \left(\begin{array}{ccc} f & 0 & u_0 \ 0 & f & v_0 \ 0 & 0 & 1 \end{array}\right)$
外参旋转矩阵
R
R = $\displaystyle \left(\begin{array}{ccc} R_{1,1} & R_{1,2} & R_{1,3} \ R_{2,1} & R_{2,2} & R_{2,3} \ R_{3,1} & R_{3,2} & R_{3,3} \end{array}\right)$
外参平移向量
t
t = $\displaystyle \left(\begin{array}{c} t_1 \ t_2 \ t_3 \end{array}\right)$
世界坐标点
X
X = $\displaystyle \left(\begin{array}{c} X_1 \ X_2 \ X_3 \end{array}\right)$
像点坐标
x
x = $\displaystyle \left(\begin{array}{c} x_1 \ x_2 \end{array}\right)$
express1 = K*[R,t]*[X;1]
express1 = $\displaystyle \left(\begin{array}{c} f,t_1 +t_3 ,u_0 +X_1 ,{\left(R_{1,1} ,f+R_{3,1} ,u_0 \right)}+X_2 ,{\left(R_{1,2} ,f+R_{3,2} ,u_0 \right)}+X_3 ,{\left(R_{1,3} ,f+R_{3,3} ,u_0 \right)}\ f,t_2 +t_3 ,v_0 +X_1 ,{\left(R_{2,1} ,f+R_{3,1} ,v_0 \right)}+X_2 ,{\left(R_{2,2} ,f+R_{3,2} ,v_0 \right)}+X_3 ,{\left(R_{2,3} ,f+R_{3,3} ,v_0 \right)}\ t_3 +R_{3,1} ,X_1 +R_{3,2} ,X_2 +R_{3,3} ,X_3 \end{array}\right)$
ui = express1(1)./express1(3);
vi = express1(2)./express1(3);
express2 = [ui;vi]-x
express2 = $\displaystyle \begin{array}{l} \left(\begin{array}{c} \frac{f,t_1 +t_3 ,u_0 +X_1 ,{\left(R_{1,1} ,f+R_{3,1} ,u_0 \right)}+X_2 ,{\left(R_{1,2} ,f+R_{3,2} ,u_0 \right)}+X_3 ,{\left(R_{1,3} ,f+R_{3,3} ,u_0 \right)}}{\sigma_1 }-x_1 \ \frac{f,t_2 +t_3 ,v_0 +X_1 ,{\left(R_{2,1} ,f+R_{3,1} ,v_0 \right)}+X_2 ,{\left(R_{2,2} ,f+R_{3,2} ,v_0 \right)}+X_3 ,{\left(R_{2,3} ,f+R_{3,3} ,v_0 \right)}}{\sigma_1 }-x_2 \end{array}\right)\\mathrm{}\\textrm{where}\\mathrm{}\;;\sigma_1 =t_3 +R_{3,1} ,X_1 +R_{3,2} ,X_2 +R_{3,3} ,X_3 \end{array}$
把
$\left\lbrack \begin{array}{ccc} f & 0 & u_0 -x_1 \ 0 & f & v_0 -x_2 \end{array}\right\rbrack \left\lbrack \begin{array}{c} t_1 \ t_2 \ t_3 \end{array}\right\rbrack =\left\lbrack \begin{array}{c} x_1 \left(R_{3,1} X_1 +R_{3,2} X_2 +R_{3,3} X_3 \right)-X_1 \left(R_{1,1} f+R_{3,1} u_0 \right)-X_2 \left(R_{1,2} f+R_{3,2} u_0 \right)-X_3 \left(R_{1,3} f+R_{3,3} u_0 \right)\ x_2 \left(R_{3,1} X_1 +R_{3,2} X_2 +R_{3,3} X_3 \right)-X_1 \left(R_{2,1} f+R_{3,1} v_0 \right)-X_2 \left(R_{2,2} f+R_{3,2} v_0 \right)-X_3 \left(R_{2,3} f+R_{3,3} v_0 \right) \end{array}\right\rbrack$ (6a)
为便于从形式上公式简化,把上式写成如下形式:
$\left\lbrack \begin{array}{ccc} f & 0 & u_0 -x_1 \ 0 & f & v_0 -x_2 \end{array}\right\rbrack \left\lbrack \begin{array}{c} t_1 \ t_2 \ t_3 \end{array}\right\rbrack =\left\lbrack \begin{array}{c} r_3 P_w \left(x_1 -u_0 \right)-f\left(r_1 P_w \right)\ r_3 P_w \left(x_2 -v_0 \right)-f\left(r_2 P_w \right) \end{array}\right\rbrack$ , (6b)
其中: $r_i =\left\lbrack R_{i,1} ,R_{i,2} ,R_{i,3} \right\rbrack ,P_w =\left\lbrack \begin{array}{c} X_1 \ X_2 \ X_3 \end{array}\right\rbrack$ ,其余都为标量值。工程上计算直接使用(6a)式,svd求解即可。
- 几何方法:
Fig1.实际立体图(相机像素坐标系下)
Fig2.实际立体成像图(相机像素坐标系下)
Fig3.实际俯视图(相机像素坐标系下)
数学背景:已知空间中三角形
Fig4.求解Q点示意图
由已知平行性条件,可得下面共面的两条空间直线方程组:
syms l1 l2 l3 x0 y0 z0 x1 y1 z1 x2 y2 z2 x y z real
equ1 = (x-x1)./l1==(y-y1)./l2;
equ2 = (x-x1)./l1==(z-z1)./l3;
equ3 = (x-x2)./(x2-x0)==(y-y2)./(y2-y0);
equ4 = (x-x2)./(x2-x0)==(z-z2)./(z2-z0);
[x,y] =solve([equ1,equ3],[x,y]);
z = simplify(l3*(x-x1)/l1+z1);
Q = [x,y,z]
Q = $\displaystyle \begin{array}{l} \left(\begin{array}{ccc} \sigma_1 & \frac{l_2 ,x_1 ,y_0 +l_2 ,x_0 ,y_2 -l_2 ,x_2 ,y_0 -l_2 ,x_1 ,y_2 -l_1 ,y_0 ,y_1 +l_1 ,y_1 ,y_2 }{l_2 ,x_0 -l_2 ,x_2 -l_1 ,y_0 +l_1 ,y_2 } & z_1 -\frac{l_3 ,{\left(x_1 -\sigma_1 \right)}}{l_1 } \end{array}\right)\\mathrm{}\\textrm{where}\\mathrm{}\;;\sigma_1 =\frac{l_2 ,x_0 ,x_1 -l_2 ,x_1 ,x_2 -l_1 ,x_0 ,y_1 +l_1 ,x_0 ,y_2 -l_1 ,x_2 ,y_0 +l_1 ,x_2 ,y_1 }{l_2 ,x_0 -l_2 ,x_2 -l_1 ,y_0 +l_1 ,y_2 }\end{array}$
实现函数为calQcoord.m。
主要利用相似三角形计算,由Fig2中成像过程,可知
[1] R. Cipolla, T. Drummond and D. Robertson,Camera calibration from vanishing points in images of architectural scenes,1999
[2] Berthold K.P. Horn,Tsai’s camera calibration method revisited,2000
[3] Radu Orghidan,Joaquim Salvi, Camera calibration using two or three vanishing points,2012.