鱼眼相机的标定比针孔相机的标定的原理与方法类似,这里贴上两种自己亲测可用的方案吧。
首先是张正友的MATLAB工具箱,下载。从这个超链接可以下载工具箱,也有使用方法的介绍。
普通针孔相机的标定过程:
Run the main matlab calibration function calib_gui_normal/calib_gui.m/calib_gui_no_read/calib_gui_fisheye
Reading the images(20): Click on the Image names button, Enter the basename of the calibration images (Image) and the image format (tif).这里当然需要事先把标定照片放在该目录下
Extract the grid corners: Click on the Extract grid corners button.Press "enter" (with an empty argument) to select all the images
(otherwise, you would enter a list of image indices like [2 5 8 10 12] to extract corners of a subset of images).
Then, select the default window size of the corner finder: wintx=winty=5 by pressing "enter" with empty arguments to the wintx and winty question.
(WARNING: try to click accurately on the four corners(LU,RU,RD,LD), at most 5 pixels away from the corners. Otherwise some of the corners might be missed by the detector).
dX=dY=30mm=default values; 手动拾取角点并输入三维网格边长
如果是鱼眼相机,那么这里需要手动标定一下,需要在MATLAB的窗口里输入“run manual_corner_extraction.m”进入手动标定的方式
Main Calibration step: click on the button Calibration.Calibration is done in two steps: first initialization, and then nonlinear optimization.
Recomp. corners button. 自动标出grid corners
Run then another calibration optimization by clicking on Calibration:
click on Save to save the calibration results (intrinsic and extrinsic) in the matlab file Calib_Results.mat
click on Reproject on images to reproject the grids onto the original calibration images.
Click on Analyse error to view the new reprojection error.
click on Show Extrinsic to show the new 3D positions of the grids with respect to the camera.
我用这种方法标定出鱼眼的结果是
Focal Length: fc = [ 497.36165 494.92849 ] +- [ 4.08794 3.82063 ]
Principal point: cc = [ 958.99209 454.68095 ] +- [ 2.38658 1.82875 ]
Skew: alpha_c = [ 0.00000 ] +- [ 0.00000 ] => angle of pixel axes = 90.00000 ? 0.00000 degrees
Fisheye Distortion: kc = [ -0.02813 0.00601 -0.00648 0.00076 ] ? [ 0.02079 0.03954 0.02987 0.00764 ]
Pixel error: err = [ 1.19736 1.50271 ]
更新一下,2016版的matlab的APP里有直接的camera calibrator的应用
但是MATLAB工具箱这种方法不够方便,比如需要手工标定角点,特别考验眼力。所以后来我使用了Opencv的方法。
在《学习Opencv》一书中有针对针孔相机的标定的源码。鱼眼相机的标定与其流程相似,只是要修改相关专门用于fisheye的函数,这些函数在Opencv里也有实现,见鱼眼函数的官方文档。
我把用于针孔相机的标定代码,使用在线方式标定鱼眼相机和离线方式标定鱼眼相机的代码都上传到了GitHub,点击移步GitHub。
用这种方法标定的结果是
像素
相机内参数矩阵:
[483.2704156971429, 0, 960.4974562203088;
0, 486.1219309294918, 459.4646834483839;
0, 0, 1]
畸变系数:
[-0.0258665, 0.0110641, -0.00669646, -2.38718e-05]
总体平均误差:0.14081像素