相机标定之OpenCV&Matlab

来源:互联网 发布:手机最好用防蹭网软件 编辑:程序博客网 时间:2024/05/17 07:14

Camera Calibration

1.OpenCV Camera Calibration

OpenCV提供具体的标定策略和说明文档,可以直接使用,说明文档的位置"D:\opencv\sources\doc\tutorials\calib3d\camera_calibration";

例程的位置“D:\opencv\sources\samples\cpp\camera_calibration.cpp”

如何使用例程呢?首先修改配置文档xml

[html] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. <?xml version="1.0"?>  
  2. <opencv_storage>  
  3. <Settings>  
  4.   <!-- 标定板的宽高各有多少角点Number of inner corners per a item row and column. (square, circle) -->  
  5.   <BoardSize_Width>7</BoardSize_Width>  
  6.   <BoardSize_Height>7</BoardSize_Height>  
  7.     
  8.   <!--标定板上的方块边长,以毫米为单位 The size of a square in some user defined metric system (pixel, millimeter)-->  
  9.   <Square_Size>50</Square_Size>  
  10.     
  11.   <!-- 选择标定模式The type of input used for camera calibration. One of: CHESSBOARD CIRCLES_GRID ASYMMETRIC_CIRCLES_GRID -->  
  12.   <Calibrate_Pattern>"CHESSBOARD"</Calibrate_Pattern>  
  13.     
  14.   <!-- The input to use for calibration. 所采集的标定图像存储的路径及名称xml档  
  15.         To use an input camera -> give the ID of the camera, like "1"  
  16.         To use an input video  -> give the path of the input video, like "/tmp/x.avi"  
  17.         To use an image list   -> give the path to the XML or YAML file containing the list of the images, like "/tmp/circles_list.xml"  
  18.         -->  
  19.   <Input>"./vtDirTest.xml"</Input>  
  20.   <!--  If true (non-zero) we flip the input images around the horizontal axis.-->  
  21.   <Input_FlipAroundHorizontalAxis>0</Input_FlipAroundHorizontalAxis>  
  22.     
  23.   <!-- Time delay between frames in case of camera. -->  
  24.   <Input_Delay>100</Input_Delay>      
  25.     
  26.   <!-- How many frames to use, for calibration. -->  
  27.   <Calibrate_NrOfFrameToUse>25</Calibrate_NrOfFrameToUse>  
  28.   <!-- Consider only fy as a free parameter, the ratio fx/fy stays the same as in the input cameraMatrix.   
  29.        Use or not setting. 0 - False Non-Zero - True-->  
  30.   <Calibrate_FixAspectRatio> 1 </Calibrate_FixAspectRatio>  
  31.   <!-- If true (non-zero) tangential distortion coefficients  are set to zeros and stay zero.-->  
  32.   <Calibrate_AssumeZeroTangentialDistortion>1</Calibrate_AssumeZeroTangentialDistortion>  
  33.   <!-- If true (non-zero) the principal point is not changed during the global optimization.-->  
  34.   <Calibrate_FixPrincipalPointAtTheCenter> 1 </Calibrate_FixPrincipalPointAtTheCenter>  
  35.     
  36.   <!-- 输出标定后的内参/外参以及其他参数的文档名称路径The name of the output log file. -->  
  37.   <Write_outputFileName>"out_camera_vt.xml"</Write_outputFileName>  
  38.   <!-- If true (non-zero) we write to the output file the feature points.-->  
  39.   <Write_DetectedFeaturePoints>1</Write_DetectedFeaturePoints>  
  40.   <!-- If true (non-zero) we write to the output file the extrinsic camera parameters.-->  
  41.   <Write_extrinsicParameters>1</Write_extrinsicParameters>  
  42.   <!-- If true (non-zero) we show after calibration the undistorted images.-->  
  43.   <Show_UndistortedImage>1</Show_UndistortedImage>  
  44.    
  45. </Settings>  
  46. </opencv_storage>  
大概修改上述标注的几个位置,然后运行camera_calibration.cpp即可;

工程下载地址

参考【1】 【2】

因为据说使用Matlab的工具箱进行标定会比较准确,所以计划对比测试两种标定方式;

2.Matlab Calibration

参考【3】 【4】

首先下载toolbox_calib.zip,在【3】中有下载链接;解压之后放在工作目录下,同时跟随【4】进行标定,叙述很详尽;

但因为内容较多,现简略叙述:

2.1 启动标定工具箱

运行calib.m,选择图像载入模式


当图像量大且多时需要使用第二种方式;此处选择标准模式为例:


2.2 载入图像

进入图像所在目录,然后点击Image names按钮


首先输入标定图像序列的名称前缀(不包含数字序号)如上方式,然后选择格式;ok;


2.3 提取角点

点击Extract grid corners按钮,在命令窗口如下述


直接回车,将选择默认模式;窗口的大小为11×11,然后在对每一幅测试图档进行手动设置最外围的四个角点

按逆时针顺序进行选择


此时需要设定每个小方格在现实世界中的宽高,以便随后角点的自动选择;

此处设定为30mm×30mm;只需第一次设定;



然后每一幅图像都需要设置外围的四个角点,这样会不会手酸???

若已经做过一次,可点击load选项,会自动载入Calib_Results.mat中的角点信息;

2.4 标定

在所有的图档都已经角点提取完毕之后,点击Calibration进行标定;


说明

A. 通过Recomp. corners按钮提高标定精确度;

B. Analyse error展示角点误差分布,用鼠标左键点击后,在命令窗口可直接显示该点信息;


C.Add/Suppress images 去除不需要的图档;

D. Show Extrinsic模拟每幅图像采集时的相对相机的位置角度;


其他的慢慢探索,文档【3】【4】相当详细;

为便于后续查找,也上传一份toobox及图档;下载地址


0 0