[Stereo Vision (3)] Principles of Zhang Zhengyou Calibration Method

This is a personal study note. I have borrowed a lot of good pictures and articles (references are at the end of the article), mainly to sort out relevant knowledge in order to form my own system. The text expression is pieced together, and the symbolic formula is manually entered. Please point out if there are any mistakes.

1. Camera Calibration

The so-called calibration (calibration) is the process of fitting a parameter model by a large number of observations, and the parameter model fitted here is known, so it is necessary to explore a scheme that can easily obtain a large number of observations as much as possible. It is more helpful to solve the specific single parameter value if it also satisfies some other geometric constraints.
Camera calibration, the purpose is to determine the internal parameter matrix KK of the cameraK , external parameter matrixR , TR, TR , T and distortion coefficientsk 1 , k 2 , k 3 , p 1 , p 2 k_1,k_2,k_3,p_1,p_2k1,k2,k3,p1,p2

Zhang's calibration method provides a convenient solution to obtain a large number of observations, and at the same time, the observations also meet a type of obvious geometric constraints (ie, plane constraints), which can directly solve the internal and external parameters. Its operation method is very simple. You only need to shoot the plane with the calibration plate pattern to complete the camera calibration, which greatly reduces the difficulty of calibration. If you do not pursue high precision, print a checkerboard calibration plate pattern and paste it on an approximately flat hard surface. Calibration can be completed on cardboard, which speeds up the introduction and popularization of stereo vision, and has far-reaching influence. It is an absolute classic in the field of camera calibration.
Leaving aside the distortion coefficient for now, the known image coordinates ppp and world coordinatesP w P_wPwEstablish a projection relationship between internal and external parameters (projection matrix):

λ p = K [ R 3 × 3 T 3 × 1 ] [ P w 1 ] = M [ P w 1 ] \lambda {p}=K \begin{bmatrix} {R_{3\times3}}&{T_{3\times1}}\\ \end{bmatrix} \begin{bmatrix} {P_w}\\ {1}\\ \end{bmatrix}=M\begin{bmatrix} {P_w}\\ {1}\\ \end{bmatrix} p _=K[R3×3T3×1][Pw1]=M[Pw1]

for ri r_iriDenotes the rotation matrix RRR 'siicolumn i , and usettt instead ofT 3 × 1 T_{3\times1}T3×1, assuming that the model plane is in the world coordinate system W = 0 W=0W=On the 0 plane (unified symbols, the world coordinate system hereis consistentthe previous expressionP w ( U , V , W ) P_w(U,V,W)Pw(U,V,W ) ), then

λ p = K [ r 1 r 2 r 3 t ] [ U V 0 1 ] = K [ r 1 r 2 t ] [ U V 1 ] \lambda {p}=K \begin{bmatrix} r_1&r_2&r_3&t\\ \end{bmatrix} \begin{bmatrix} U\\V\\0\\1 \end{bmatrix}= K \begin{bmatrix} r_1&r_2&t\\ \end{bmatrix} \begin{bmatrix} U\\V\\1 \end{bmatrix} p _=K[r1r2r3t] UV01 =K[r1r2t] UV1

As mentioned earlier , points on the world coordinate plane are related to points on their image via a homography matrix:

λ p = HP \ lambda {p}=HPp _=H P
equation,p = [ u , v , 1 ] T p=[u,v,1]^Tp=[u,v,1]T P = [ U , V , 1 ] P=[U,V,1] P=[U,V,1] H = R [ r 1 , , r 2 , t ] H=R[r_1,,r_2,t] H=R[r1,,r2,t ] is3 × 3 3\times 33×3 matrix. still usehi h_ihito represent HHiiin Hcolumn i . have

[ h 1 , h 2 , h 3 ] = Λ K [ r 1 , r 2 , t ] [h_1,h_2,h_3]=\Lambda K[r_1,r_2,t] [h1,h2,h3]=ΛK[r1,r2,t ]
whereΛ \LambdaΛ is any scalar (Λ \LambdaThe existence of Λ is due to the scale invariance of homogeneous coordinates, it can also be considered equal to 1, let it be 1 here, and ignore it later). r 1 r_1r1and r 2 r_2r2is the rotation matrix RRThe column components of R , which are a pair of orthonormal basis. satisfyr 1 T r 2 = 0 , r 1 T r 1 = r 2 T r 2 = 1 r_1^Tr_2=0,r_1^Tr_1=r_2^Tr_2=1r1Tr2=0,r1Tr1=r2Tr2=1 . Contact the above formula:
r 1 = K − 1 h 1 r 2 = K − 1 h 2 r_1=K^{-1}h_1\\r_2=K^{-1}h_2r1=K1h1r2=K1h2
So:
h 1 TK − TK − 1 h 2 = 0 h_1^TK^{-T}K^{-1}h_2=0h1TKTK1h2=0 h 1 T K − T K − 1 h 1 = h 2 T K − T K − 1 h 2 h_1^TK^{-T}K^{-1}h_1=h_2^TK^{-T}K^{-1}h_2 h1TKTK1h1=h2TKTK1h2

It can be seen that the homography matrix HHH and internal reference matrixKKThe elements of K satisfy two linear equation constraints. The homography has 8 degrees of freedom and with 6 extrinsics (3 for rotation and 3 for translation), we can only obtain 2 constraints on the intrinsics.

2. Parameter solution

According to the structure of the paper, it starts from the analytical solution, then proceeds to the nonlinear optimization technique based on the maximum likelihood criterion, and finally considers the camera distortion.

1) Closed solution

Similarly, replace the middle part of the above equation with a simple matrix (a common operation), let
B = K − TK − 1 = [ B 11 B 12 B 13 B 12 B 22 B 23 B 13 B 23 B 33 ] B=K ^{-T}K^{-1}=\begin{bmatrix} B_{11}&B_{12}&B_{13}\\B_{12}&B_{22}&B_{23}\\B_{13}&B_ {23}&B_{33}\\ \end{bmatrix}B=KTK1= B11B12B13B12B22B23B13B23B33
具体地:
B = [ 1 f x 2 − s f x 2 f y v 0 s − u 0 f y f x 2 f y − s f x 2 f y s 2 f x 2 f y 2 + 1 f y 2 − s ( v 0 s − u 0 f y f x 2 f y 2 ) − v 0 f y 2 v 0 s − u 0 f y f x 2 f y − s ( v 0 s − u 0 f y ) f x 2 f y 2 − v 0 f y 2 ( v 0 s − u 0 f y ) 2 f x 2 f y 2 + v 0 2 f y 2 + 1 ] B=\begin{bmatrix} \Large \frac{1}{f_x^2} & \Large -\frac{s}{f_x^2f_y} & \Large \frac{v_0s-u_0f_y}{f_x^2f_y}\\ \Large-\frac{s}{f_x^2f_y} &\Large \frac{s^2}{f_x^2f_y^2}+\frac{1}{f_y^2} &\Large -\frac{s(v_0s-u_0f_y}{f_x^2f_y^2)} -\frac{v_0}{f_y^2}\\ \Large \frac{v_0s-u_0f_y}{f_x^2f_y} & \Large -\frac{s(v_0s-u_0f_y)}{f_x^2f_y^2} -\frac{v_0}{f_y^2}& \Large\frac{(v_0s-u_0f_y)^2}{f_x^2f_y^2} +\frac{v_0^2}{f_y^2}+1\\ \end{bmatrix} B= fx21fx2fysfx2fyv0su0fyfx2fysfx2fy2s2+fy21fx2fy2s(v0su0fy)fy2v0fx2fyv0su0fyfx2fy2)s(v0su0fyfy2v0fx2fy2(v0su0fy)2+fy2v02+1

HH has been set aboveH 'siii column vectors arehi = [ hi 1 , hi 2 , hi 3 ] T h_i=[h_{i1},h_{i2},h_{i3}]^Thi=[hi 1,hi2,hand 3]T 。则有
h i T B h j = [ h i 1 h i 2 h i 3 ] [ B 11 B 12 B 13 B 12 B 22 B 23 B 13 B 23 B 33 ] [ h j 1 h j 2 h j 3 ] = [ h i 1 B 11 + h i 2 B 12 + h i 3 B 13 h i 1 B 12 + h i 2 B 22 + h i 3 B 23 h i 1 B 13 + h i 2 B 23 + h i 3 B 33 ] [ h j 1 h j 2 h j 3 ] h_i^TBh_j=\begin{bmatrix}h_{i1}&h_{i2}&h_{i3}\end{bmatrix} \begin{bmatrix} B_{11}&B_{12}&B_{13}\\B_{12}&B_{22}&B_{23}\\B_{13}&B_{23}&B_{33}\\ \end{bmatrix} \begin{bmatrix}h_{j1}\\h_{j2}\\h_{j3}\end{bmatrix} \\=\begin{bmatrix}h_{i1}B_{11}+h_{i2}B_{12}+h_{i3}B_{13}&h_{i1}B_{12}+h_{i2}B_{22}+h_{i3}B_{23}&h_{i1}B_{13}+h_{i2}B_{23}+h_{i3}B_{33}\end{bmatrix}\begin{bmatrix}h_{j1}\\h_{j2}\\h_{j3}\end{bmatrix} hiTBhj=[hi 1hi2hand 3] B11B12B13B12B22B23B13B23B33 hj 1hj 2hj3 _ =[hi 1B11+hi2B12+hand 3B13hi 1B12+hi2B22+hand 3B23hi 1B13+hi2B23+hand 3B33] hj 1hj 2hj3 _ = h i 1 h j 1 B 11 + h i 2 h j 1 B 12 + h i 3 h j 1 B 13 + h i 1 h j 2 B 12 + h i 2 h j 2 B 22 + h i 3 h j 2 B 23 + h i 1 h j 3 B 13 + h i 2 h j 3 B 23 + h i 3 h j 3 B 33 =h_{i1}h_{j1}B_{11}+h_{i2}h_{j1}B_{12}+h_{i3}h_{j1}B_{13}+h_{i1}h_{j2}B_{12}+h_{i2}h_{j2}B_{22}+h_{i3}h_{j2}B_{23}+h_{i1}h_{j3}B_{13}+h_{i2}h_{j3}B_{23}+h_{i3}h_{j3}B_{33} =hi 1hj 1B11+hi2hj 1B12+hand 3hj 1B13+hi 1hj 2B12+hi2hj 2B22+hand 3hj 2B23+hi 1hj3 _B13+hi2hj3 _B23+hand 3hj3 _B33 = [ h i 1 h j 1 h i 1 h j 2 + h i 2 h j 1 h i 2 h j 2 h i 3 h j 1 + h i 1 h j 3 h i 3 h j 2 + h i 2 h j 3 h i 3 h j 3 ] [ B 11 B 12 B 22 B 13 B 23 B 33 ] =\begin{bmatrix}h_{i1}h_{j1}&h_{i1}h_{j2}+h_{i2}h_{j1}&h_{i2}h_{j2}&h_{i3}h_{j1}+h_{i1}h_{j3}&h_{i3}h_{j2}+h_{i2}h_{j3}&h_{i3}h_{j3}\end{bmatrix}\begin{bmatrix}B_{11}\\B_{12} \\B_{22}\\B_{13} \\B_{23} \\B_{33}\end{bmatrix} =[hi 1hj 1hi 1hj 2+hi2hj 1hi2hj 2hand 3hj 1+hi 1hj3 _hand 3hj 2+hi2hj3 _hand 3hj3 _] B11B12B22B13B23B33

make

b = [ B 11 , B 12 , B 22 , B 13 , B 23 , B 33 ] T b=[B_{11} ,B_{12} ,B_{22},B_{13} ,B_{23} ,B_{33}]^T b=[B11,B12,B22,B13,B23,B33]T v i j = [ h i 1 h j 1 , h i 1 h j 2 + h i 2 h j 1 , h i 2 h j 2 , h i 3 h j 1 + h i 1 h j 3 , h i 3 h j 2 + h i 2 h j 3 , h i 3 h j 3 ] T v_{ij}=[h_{i1}h_{j1},h_{i1}h_{j2}+h_{i2}h_{j1},h_{i2}h_{j2},h_{i3}h_{j1}+h_{i1}h_{j3},h_{i3}h_{j2}+h_{i2}h_{j3},h_{i3}h_{j3}]^T vij=[hi 1hj 1,hi 1hj 2+hi2hj 1,hi2hj 2,hand 3hj 1+hi 1hj3 _,hand 3hj 2+hi2hj3 _,hand 3hj3 _]T
则有:
h i T B h j = v i j T b h_i^TBh_j=v_{ij}^Tb hiTBhj=vijTb

(Note: The original paper directly gave the above formula, and I was stunned to find out that this formula is not derived, but a coefficient that is calculated first and then extracted, so here I choose to calculate it again, which is helpful for understanding. )

h i T B h j = v i j T b h_i^TBh_j=v_{ij}^Tb hiTBhj=vijTb
and then contact the above homography matrixHHH and internal reference matrixKKThe elements of K satisfy two linear equation constraints, and there are

[ v 11 T ( v 11 − v 22 ) T ] b = 0 \begin{bmatrix}v_{11}^T\\(v_{11}-v_{22})^T\end{bmatrix}b=0 [v11T(v11v22)T]b=0
After the camera shoots the calibration plate pattern in one pose, after extracting the pixel coordinates of the corner points, the corresponding relationship between the world coordinate system and the pixel coordinate system of all corner points can be obtained, and then through the least squares solution of the linear equationsHHunder the current poseH , can get the above formula. But it only has two lines, used to solve the 6-dimensionalbbThe b vector requires at least 3 homography matrices, that is, at least 3 pictures are required to complete the camera calibration. The total equation can be expressed as:
V b = 0 Vb=0Vb=0

  • If the number of pictures is n ≥ 3 n≥3n3 , usually can getbbA unique solution to b (due to scale equivalence, the resultingbbAny multiple of b is still the correct solution).
  • If the number of pictures is n = 2 n=2n=2 , you can impose unbiased constraintss = 0 s=0s=0 , put[ 0 , 1 , 0 , 0 , 0 , 0 ] b [0,1,0,0,0,0]b[0,1,0,0,0,0 ] b is added to the above equation as an additional equation.
  • If the number of pictures is n = 2 n=2n=2 , it can be assumed thatu , v 0 , s u_, v_0, suv0, s are known (for example, they are all 0), andfx, fy f_x, f_yfxfySolve it.

Solve for bbAfter b , all camera intrinsic parameters can be calculated as follows (since bybbThe matrix BBcomposed of bB does not strictly satisfyB = K − TK − 1 B=K^{-T}K^{-1}B=KTK1 , but there is an arbitrary scaling factorλ \lambdaλ (again) satisfiesB = λ K − TK − 1 B=\lambda K^{-T}K^{-1}B=λKTK1):

v 0 = B 12 B 13 − B 11 B 23 B 11 B 22 − B 22 2 v_0=\frac{B_{12}B_{13}-B_{11}B_{23}}{B_{11}B_{22}-B_{22}^2} v0=B11B22B222B12B13B11B23
λ = B 33 − B 13 2 + v 0 ( B 12 B 13 − B 11 B 23 ) B 11 \lambda =B_{33}-\frac{B_{13}^2+v_0(B_{12}B_{13}-B_{11}B_{23})}{B_{11}} l=B33B11B132+v0(B12B13B11B23)
f x = λ B 11 f_x=\sqrt{\frac{\lambda }{B_{11}}} fx=B11l
f y = λ B 11 B 11 B 22 − B 22 2 f_y=\sqrt{\frac{\lambda B_{11}}{B_{11}B_{22}-B_{22}^2}} fy=B11B22B222λB11

s = − B 12 f x 2 f y λ s=-\frac{B_{12}f_x^2f_y}{\lambda} s=lB12fx2fy
u 0 = s v 0 f x − B 13 f x 2 λ u_0=\frac{sv_0}{f_x}-\frac{B_{13}f_x^2}{\lambda} u0=fxsv0lB13fx2

When the internal parameter matrix KKAfter K is solved, the external parameter matrix R, TR, Tof each poseR , T can be further obtained:
r 1 = λ K − 1 h 1 r 2 = λ K − 1 h 2 r 3 = r 1 × r 2 t = λ K − 1 h 3 r_1=\lambda K^{- 1}h_1\\ r_2=\lambda K^{-1}h_2\\ r_3=r_1 \times r_2\\ t=\lambda K^{-1}h_3r1=λK1h1r2=λK1h2r3=r1×r2t=λK1h3
where, λ = 1 ∣ ∣ K − 1 h 1 ∣ ∣ = 1 ∣ ∣ K − 1 h 2 ∣ ∣ \lambda=\frac{1}{|| K^{-1}h_1 ||}=\frac{ 1}{|| K^{-1}h_2 ||}l=∣∣K1h1∣∣1=∣∣K1h2∣∣1. Due to the presence of noise in the data, the calculated matrix RRR usually does not satisfy the nature of the rotation matrix, and the optimal rotation matrix can be obtained by singular value decomposition.

2) Maximum likelihood solution

The above solution is obtained by minimizing an algebraic distance that has no physical meaning. Due to the existence of noise, the solution will not be very accurate. We can obtain a more accurate solution by means of maximum likelihood estimation. nn
for a given calibration plate planen images withmmm points. It is assumed that the noise of image points is independent and identically distributed. The maximum likelihood estimate can be obtained by minimizing the following function:

∑ i = 1 n ∑ j = 1 m ∣ ∣ p i j − p ^ ( K , R i , t i , P j ) ∣ ∣ 2 \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{m}||p_{ij}-\hat p(K,R_i,t_i,P_j)||^2 i=1nj=1m∣∣pijp^(K,Ri,ti,Pj)2

其中 p ^ ( K , R i , t i , P j ) \hat p(K,R_i,t_i,P_j) p^(K,Ri,ti,Pj) is the spatial pointP j P_jPjin image iiProjection point on i . Rotation matrixRRR can be composed of three vectorsrrr means thatrrr is parallel to the axis of rotation and its magnitude (mode length) is equal to the angle of rotation. RRR andrrr through the Rodrigues (Rodrigues) formula linked. The minimization of the above formula is a nonlinear minimization problem, which can be solved by the Levenberg-Marquardt algorithm. This type of problem requires a more accurate initial value, and the closed solution mentioned above can be used as the initial value.

3) Consider camera distortion

As mentioned above , three radial distortion parameters k 1 , k 2 , k 3 k_1, k_2, k_3 are generally considered during distortion correctionk1k2k3and two tangential distortion parameters p 1 , p 2 p_1, p_2p1p2, in Zhang's calibration, only two radial distortion parameters k 1 , k 2 k_1, k_2 are consideredk1k2. More terms will be considered in practical application, the principle is the same.
Accurate undistorted coordinates cannot be calculated when the internal and external parameters are unknown (the observations are always in error), but the distortion parameters are not considered when estimating the internal and external parameters (biting the tail). It doesn't matter, the concept theory will take action: use the internal and external parameters obtained by the closed solution as the initial value, find the approximate ideal coordinates, and then establish a linear equation system according to the distortion correction formula to solve the approximate k 1 , k 2 k_1, k_2k1k2As an initial value for the following maximum likelihood estimation:
∑ i = 1 n ∑ j = 1 m ∣ ∣ pij − p ^ ( K , k 1 , k 2 , R i , ti , P j ) ∣ ∣ 2 \sum\ limits_{i=1}^{n}\sum\limits_{j=1}^{m}||p_{ij}-\hat p(K,k_1,k_2,R_i,t_i,P_j)||^2i=1nj=1m∣∣pijp^(K,k1,k2,Ri,ti,Pj)2
Solve all internal and external parameters and distortion coefficients by nonlinear solution method.
In fact, because the value of the distortion coefficient is very small, it is also possible to directly set all the initial values ​​of the distortion coefficient to 0, which does not need to solve the linear equation system.

3. Experimental process

Summarize Zhang's calibration process:

  1. Print the calibration pattern and paste it on a flat surface, called the calibration plate.
  2. Take multiple images of the calibration board in different poses by moving the camera or moving the calibration board (number of images >=3).
  3. Detect feature points (corner points or circle center points) on all images.
  4. Solve for all intrinsic and extrinsic parameters using the closed solution method.
  5. Calculate accurate internal and external parameters and distortion coefficients through nonlinear optimization (the initial value of the distortion coefficient can be solved by the distortion correction linear equations or directly assigned to 0).

insert image description here

Calibration board used in the paper

insert image description here

Other Types of Calibration Plates

It’s superficial on paper, and I’ll consider getting started and practicing it later.


Reference:
[1] Zhang Z . A Flexible New Technique for Camera Calibration[J]. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2000, 22(11):1330-1334. [2]
Stereo Vision Getting Started Guide (3): Zhang-style calibration method for camera calibration
[3] Calibration Patterns Explained

Guess you like

Origin blog.csdn.net/m0_50910915/article/details/131082570