1. Homography matrix
Before learning the camera calibration solution, first understand a concept: homography matrix, which is defined as a projection mapping from one plane to another plane, so the mapping between the object plane in the world coordinate system and the imaging plane can be understood is a homography relationship. We know that camera calibration generally uses a calibration board for calibration, so the plane in the world coordinate system is the plane of the calibration board.
Assuming a point on the calibration plate plane , the point mapped to the imaging plane is , and the homography relationship is satisfied between the two: , where H is the homography matrix, s is the scale factor, and the homography matrix has 8 parameters, namely 8 parameters need to be solved, so 8 equations are needed, and 8 equations can be obtained through 4 points, so at least 4 points are needed to solve the homography relationship.
opencv provides an interface: fingHomography is used to solve the homography matrix.
2. Basic equations
2.1 Basic variables
Define the point in the pixel coordinate system , which corresponds to the three-dimensional space point in the world coordinate system . For the convenience of calculation, add a 1 to get the augmented vector . According to the small hole imaging principle mentioned in the previous chapter, the relationship between the three-dimensional point and the projected point can be Described as: , where s is the scale factor, and [R,t] is the external parameter rotation and translation matrix. A is the internal reference:
It is the inclination angle of the two coordinate systems, which is not mentioned above, because the two coordinate axes are vertical by default, but they may not be vertical in fact.
2.2 Camera Calibration
We can assume that the z coordinate of the plane world coordinate system of the calibration board is 0, and the i-th column of R is , then we can get:
The homography relationship between the calibration plane and the imaging plane: , with .\
As mentioned before, we can solve the homography matrix H through multiple points on the two planes
suppose ,
According to the above formula can be obtained:
Thus:
Camera imaging has two constraints:
1. The rotation vectors represent the rotation around the x and y axes respectively, so these two vectors are orthogonal, so:
, so that:
2. The rotation vector is a unit vector, so there are:
and
And then get:
3. Closed solution
The two constraints of camera imaging are mentioned above.
Next define intermediate variables
B is a symmetric matrix, so only 6 parameters need to be solved, define
Decompose the column vectors of the homography matrix:
Substitute into the above formula to get:
Substitute into the above formula to get:
By taking N pictures of the calibration board, the above N equations can be put together, and we can get
V is a 2n*6 matrix, b has 6 parameters, and b can be calculated by solving the equation. Since b has 6 parameters, at least 3 homography matrices are required, that is to say, at least 3 different angles need to be taken A picture of the calibration board.
After calculating b, you can solve the camera internal parameters:
Calculate the rotation-translation matrix: , so that:
4. Solving radial distortion parameters
Earlier we talked about the radial distortion model:
Among them , radial distortion generally only considers the first two items:
Therefore:
Wherein is the ideal coordinate of the point in the image coordinate system, that is, the coordinate without any distortion, and is the coordinate of the real point in the image coordinate system, that is, the coordinate after distortion.
In pixel coordinate system:
Wherein is the ideal coordinate of the point in the pixel coordinate system, that is, the coordinate without any distortion, and is the coordinate of the real point in the pixel coordinate system, that is, the coordinate after distortion.
The above equations are expressed in matrix form:
Among them, ( ) can be obtained by solving the internal and external parameters of the camera, and the corner points can be obtained through image recognition, and the same is true for (x, y).
Assuming that n pictures of the calibration board are taken, and each picture has m corner points, an equation can be obtained and written in matrix form:
,in
Solve the equations according to the least square method (minimize the root mean square error to find the best match of the data, which is used to solve the situation where the number of equations is more than the unknown), and the distortion coefficient can be solved according to the above equation.