相机校正
Published: 2020-03-16 | Lastmod: 2020-03-17
针孔相机畸变校正 #
畸变模型
世界坐标到相机坐标:
\[ \begin{bmatrix} x\\ y\\ z\end{bmatrix} =R\begin{bmatrix} X\\ Y\\ Z\end{bmatrix}+t \]
相机坐标到归一化平面坐标:
\[ x'=x/z \\[2mm] y'=y/z \\[2mm] r^2 = x'^2 + y'^2 \]
畸变校正:
\[ x''=x'\frac{1+k_1r^2+k_2r^4+k_3r^6}{1+k_4r^2+k_5r^4+k_6r^6}+2p_1x'y'+p_2(r^2+2x'^2) \\[2mm] y''=y'\frac{1+k_1r^2+k_2r^4+k_3r^6}{1+k_4r^2+k_5r^4+k_6r^6}+p_1(r^2+2y'^2)+2p_2x'y' \\[2mm] \]
转化到像素坐标:
\[ u=f_x*x''+c_x \\[2mm] v=f_y*y''+c_y \]
校正方法
使用棋盘格进行图像校正:
- Find corners in chessboard
I used cv2.findChessboardCorners()
to find all the corners, which are the feature points of these images for camera calibration.
The pixel position of each of these corners is stored in imgpoints
variable. Here is some examples:
- Calculate distortion coefficients
The function cv2.calibrateCamera()
is quite useful to calculate the camera distortion coefficients.
All I need to do is to prepare objpoints
variable to store object points, which are the same for all these images.
After this operation, the curved lines are converted back to straight lines. Here is an exmaple to undistort a chessboard image:
- Provide an example of a distortion-corrected image.
One of the test images is corrected using the distortion coefficients derived from the above chessboard calibration procedure. The difference between original image and corrected one is subtle, however, this is a very important step.
鱼眼相机畸变校正 #
畸变表
畸变模型
参考资料 #
Next: Opencv 图像处理
Previous: Odometry