您的位置:首页 > 编程语言 > MATLAB

相机标定之OpenCV&Matlab

2015-04-06 21:22 387 查看


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?





<?xml version="1.0"?>

<opencv_storage>

<Settings>

<!-- 标定板的宽高各有多少角点Number of inner corners per a item row and column. (square, circle) -->

<BoardSize_Width>7</BoardSize_Width>

<BoardSize_Height>7</BoardSize_Height>

<!--标定板上的方块边长,以毫米为单位 The size of a square in some user defined metric system (pixel, millimeter)-->

<Square_Size>50</Square_Size>

<!-- 选择标定模式The type of input used for camera calibration. One of: CHESSBOARD CIRCLES_GRID ASYMMETRIC_CIRCLES_GRID -->

<Calibrate_Pattern>"CHESSBOARD"</Calibrate_Pattern>

<!-- The input to use for calibration. 所采集的标定图像存储的路径及名称xml档

To use an input camera -> give the ID of the camera, like "1"

To use an input video -> give the path of the input video, like "/tmp/x.avi"

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"

-->

<Input>"./vtDirTest.xml"</Input>

<!-- If true (non-zero) we flip the input images around the horizontal axis.-->

<Input_FlipAroundHorizontalAxis>0</Input_FlipAroundHorizontalAxis>

<!-- Time delay between frames in case of camera. -->

<Input_Delay>100</Input_Delay>

<!-- How many frames to use, for calibration. -->

<Calibrate_NrOfFrameToUse>25</Calibrate_NrOfFrameToUse>

<!-- Consider only fy as a free parameter, the ratio fx/fy stays the same as in the input cameraMatrix.

Use or not setting. 0 - False Non-Zero - True-->

<Calibrate_FixAspectRatio> 1 </Calibrate_FixAspectRatio>

<!-- If true (non-zero) tangential distortion coefficients are set to zeros and stay zero.-->

<Calibrate_AssumeZeroTangentialDistortion>1</Calibrate_AssumeZeroTangentialDistortion>

<!-- If true (non-zero) the principal point is not changed during the global optimization.-->

<Calibrate_FixPrincipalPointAtTheCenter> 1 </Calibrate_FixPrincipalPointAtTheCenter>

<!-- 输出标定后的内参/外参以及其他参数的文档名称路径The name of the output log file. -->

<Write_outputFileName>"out_camera_vt.xml"</Write_outputFileName>

<!-- If true (non-zero) we write to the output file the feature points.-->

<Write_DetectedFeaturePoints>1</Write_DetectedFeaturePoints>

<!-- If true (non-zero) we write to the output file the extrinsic camera parameters.-->

<Write_extrinsicParameters>1</Write_extrinsicParameters>

<!-- If true (non-zero) we show after calibration the undistorted images.-->

<Show_UndistortedImage>1</Show_UndistortedImage>

</Settings>

</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及图档;下载地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: