单相机标定精度的评估
本示例演示了如何评估使用 Using the Single Camera Calibrator App 或 estimateCameraParameters 函数估算的相机参数的精度。
概述
相机标定是指利用特殊标定图案的图像来估算相机参数的过程。这些参数包括相机内参、畸变系数和相机外参。对相机进行标定后,有几种方法可以评估估计参数的准确性:
绘制相机与标定图案的相对位置
计算重投影误差
计算参数估计误差
标定相机
利用一组棋盘格标定图案的图像来估计相机参数。
% Create a set of calibration images. images = imageDatastore(fullfile(toolboxdir("vision"), "visiondata", ... "calibration", "mono")); imageFileNames = images.Files; % Detect calibration pattern. [imagePoints, patternDims] = detectCheckerboardPoints(imageFileNames); % Generate world coordinates of the corners of the squares. squareSize = 29; % millimeters worldPoints = patternWorldPoints("checkerboard", patternDims, squareSize); % Calibrate the camera. I = readimage(images, 1); imageSize = [size(I, 1), size(I, 2)]; [params, ~, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ... ImageSize=imageSize);
外参
通过绘制相机与标定图案的相对位置,您可以快速发现标定中的明显错误。使用 showExtrinsics 函数,可以在相机坐标系中绘制标定图案的位置,或者在图案坐标系中绘制相机的位置。检查是否有明显的问题,例如图案位于相机后面,或者相机位于图案后面。同时还要检查图案是否离相机太远或太近。
figure;
showExtrinsics(params, "CameraCentric");
figure;
showExtrinsics(params, "PatternCentric");
重投影误差
重投影误差可作为准确度的定性衡量索引。重投影误差是指在标定图像中检测到的图案关键点与投影到同一图像中的对应世界点之间的距离。showReprojectionErrors 函数可直观地展示每张标定图像中的平均重投影误差。如果总体平均重投影误差过高,请考虑排除误差最大的图像并重新标定。
figure; showReprojectionErrors(params);

估计误差
估计误差反映了每个估计参数的不确定性。estimateCameraParameters 函数可选地返回 estimationErrors 输出,其中包含与每个估计的相机参数相对应的标准误差。返回的标准误差 (单位与相应参数相同)可用于计算置信区间。例如,+/- 对应于 95% 的置信区间。换句话说,某个给定参数的实际值落在其估计值± 范围内的概率为 95%。
displayErrors(estimationErrors, params);
Standard Errors of Estimated Camera Parameters
----------------------------------------------
Intrinsics
----------
Focal length (pixels): [ 714.1884 +/- 3.3219 710.3783 +/- 4.0579 ]
Principal point (pixels):[ 563.6478 +/- 5.3967 355.7255 +/- 3.3036 ]
Radial distortion: [ -0.3536 +/- 0.0091 0.1730 +/- 0.0488 ]
Extrinsics
----------
Rotation vectors:
[ -0.6096 +/- 0.0054 -0.1789 +/- 0.0073 -0.3835 +/- 0.0024 ]
[ -0.7283 +/- 0.0050 -0.0996 +/- 0.0072 0.1964 +/- 0.0027 ]
[ -0.6722 +/- 0.0051 -0.1444 +/- 0.0074 -0.1329 +/- 0.0026 ]
[ -0.5836 +/- 0.0056 -0.2901 +/- 0.0074 -0.5622 +/- 0.0025 ]
[ -0.3157 +/- 0.0065 -0.1441 +/- 0.0075 -0.1067 +/- 0.0011 ]
[ -0.7581 +/- 0.0052 0.1947 +/- 0.0072 0.4324 +/- 0.0030 ]
[ -0.7515 +/- 0.0051 0.0767 +/- 0.0072 0.2070 +/- 0.0029 ]
[ -0.6223 +/- 0.0053 0.0231 +/- 0.0073 0.3663 +/- 0.0024 ]
[ 0.3443 +/- 0.0063 -0.2226 +/- 0.0073 -0.0437 +/- 0.0014 ]
Translation vectors (mm):
[ -146.0514 +/- 6.0391 -26.8688 +/- 3.7318 797.9024 +/- 3.9002 ]
[ -209.4354 +/- 6.9637 -59.4568 +/- 4.3578 921.8196 +/- 4.6295 ]
[ -129.3821 +/- 7.0907 -44.1033 +/- 4.3751 937.6829 +/- 4.4913 ]
[ -151.0046 +/- 6.6905 -27.3256 +/- 4.1339 884.2787 +/- 4.3925 ]
[ -174.9496 +/- 6.7056 -24.3502 +/- 4.1606 886.4959 +/- 4.6686 ]
[ -134.3092 +/- 7.8887 -103.4984 +/- 4.8925 1042.4551 +/- 4.8184 ]
[ -173.9842 +/- 7.6891 -73.1694 +/- 4.7812 1017.2383 +/- 4.8126 ]
[ -202.9443 +/- 7.4327 -87.9094 +/- 4.6482 983.6955 +/- 4.9072 ]
[ -319.8858 +/- 6.3213 -119.8901 +/- 4.0922 829.4580 +/- 4.9591 ]
如何提高标定精度
某项重投影或估计误差是否可接受,取决于您具体应用的精确率要求。不过,如果您已确定标定精度无法接受,可以通过以下几种方法加以改进:
修改标定设置。尝试使用 3 个径向畸变系数,估算切向畸变或倾斜度。
拍摄更多标定图像。图像中的图案必须具有不同的 3D 方向,且应将其定位在视野的各个部分都能检测到关键点的位置。特别是,为了更好地估计畸变系数,关键点位于图像边缘和角点附近这一点非常重要。
排除重投影误差较大的图像,并重新标定。
总结
本示例演示了如何获取和解释相机标定误差。
参考资料
[1] Z. Zhang.A flexible new technique for camera calibration.IEEE Transactions on Pattern Analysis and Machine Intelligence, 22(11):1330-1334, 2000.