首页 > 其他分享 >【matlab工具箱使用】matlab工具箱标定相机

【matlab工具箱使用】matlab工具箱标定相机

时间:2022-12-14 18:56:44浏览次数:67  
标签:... 标定 camera matlab calib 工具箱

前言

印象中之前使用python和matlab都做过相机标定工作,只是没有记录,最近使用matlab工具箱记录下操作步骤。

操作步骤

1.打印一张棋盘格,把它贴在一个平面上,作为标定物,同时记录棋盘格的实际大小。
2.通过调整标定物或摄像机的方向,为标定物拍摄一些不同方向的照片。
3.从照片中提取棋盘格角点。
4.估算理想无畸变的情况下,五个内参和六个外参。
在假设透镜畸变为零的情况下,求解内外参。
利用非线性最小二乘极小化(Levenberg-Marquardt)同时估计包括畸变系数在内的所有参数。
使用第一步的解作为内、外参数的初始估计。然后将畸变系数的初始估计值设为零。

5.应用最小二乘法估算实际存在径向畸变下的畸变系数

 具体操作步骤

step1:启动matlab,在APPS中搜索camera calibrator;

step2: 加载标定板拍摄图片;

 

step3: 输入棋盘格每格的尺寸大小,单位是mm;

step4: 选择需要计算的参数,点击Calibration,开始标定;

 

 step5: 得到标定结果(平均误差小于0.5即可,如果大于0.5,多采一些图,再次标定);

step6: 查看标定结果和生成程序;

标定结果

cameraParams = 

  cameraParameters with properties:

   Camera Intrinsics
                    IntrinsicMatrix: [3×3 double]
                        FocalLength: [1.3097e+03 1.3180e+03]
                     PrincipalPoint: [671.4361 399.7834]
                               Skew: 1.9323
                   RadialDistortion: [-0.4668 0.1950 -0.0949]
               TangentialDistortion: [-0.0026 -6.1137e-04]
                          ImageSize: [720 1280]

   Camera Extrinsics
                   RotationMatrices: [3×3×145 double]
                 TranslationVectors: [145×3 double]

   Accuracy of Estimation
              MeanReprojectionError: 0.0598
                 ReprojectionErrors: [54×2×145 double]
                  ReprojectedPoints: [54×2×145 double]

   Calibration Settings
                        NumPatterns: 145
                        WorldPoints: [54×2 double]
                         WorldUnits: 'millimeters'
                       EstimateSkew: 1
    NumRadialDistortionCoefficients: 3
       EstimateTangentialDistortion: 1


estimationErrors = 

  cameraCalibrationErrors with properties:

    IntrinsicsErrors: [1×1 intrinsicsEstimationErrors]
    ExtrinsicsErrors: [1×1 extrinsicsEstimationErrors]

自动生成matlab脚本;

% Auto-generated by cameraCalibrator app on 12-Dec-2022
%-------------------------------------------------------
imageFileNames = {'/home/xxx/workspace/utils/camera_calib/output_20221212T103356_camera_calib_fov60/TFL_20221212T103406_00000.png',...
    '/home/xxx/workspace/utils/camera_calib/output_20221212T103356_camera_calib_fov60/TFL_20221212T103545_00001.png',...
    '/home/xxx/workspace/utils/camera_calib/output_20221212T103356_camera_calib_fov60/TFL_20221212T103549_00002.png',...}

% Define images to process

% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);

% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);

% Generate world coordinates of the corners of the squares
squareSize = 100;  % in units of 'millimeters'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', true, 'EstimateTangentialDistortion', true, ...
    'NumRadialDistortionCoefficients', 3, 'WorldUnits', 'millimeters', ...
    'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...
    'ImageSize', [mrows, ncols]);

% View reprojection errors
h1=figure; showReprojectionErrors(cameraParams);

% Visualize pattern locations
h2=figure; showExtrinsics(cameraParams, 'CameraCentric');

% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);

% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);

% See additional examples of how to use the calibration data.  At the prompt type:
% showdemo('MeasuringPlanarObjectsExample')
% showdemo('StructureFromMotionExample')

 

参考

1. Matlab工具箱标定_qingfengxiaosong的博客-CSDN博客_matlab标定工具箱

标签:...,标定,camera,matlab,calib,工具箱
From: https://www.cnblogs.com/happyamyhope/p/16975867.html

相关文章