cameraCalibrator app

close all
clear

% Define images to process
imageFileNames = {'2012_0524_1.JPG',...
    '2012_0524_2.JPG',...
    '2012_0524_3.JPG',...
    };
fprintf('Detect checkerboards in images\n');
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);
Detect checkerboards in images
Warning: The checkerboard must be asymmetric: one side should be even, and
the other should be odd. Otherwise, the orientation of the board may be
detected incorrectly. 
% 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 = 3;  % in units of 'inches'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
    'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'inches', ...
    'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...
    'ImageSize', [mrows, ncols]);
% Display parameter estimation errors
displayErrors(estimationErrors, cameraParams);
			Standard Errors of Estimated Camera Parameters
			----------------------------------------------

Intrinsics
----------
Focal length (pixels):   [ 2524.6825 +/- 4.3166     2518.1892 +/- 4.4630  ]
Principal point (pixels):[ 1017.3758 +/- 3.7191      843.3565 +/- 4.8709  ]
Radial distortion:       [   -0.1903 +/- 0.0098        0.5643 +/- 0.0699  ]

Extrinsics
----------
Rotation vectors:
                         [   -0.8013 +/- 0.0024       -0.2965 +/- 0.0018       -0.6899 +/- 0.0006  ]
                         [    0.6803 +/- 0.0019       -0.6779 +/- 0.0019       -0.2725 +/- 0.0008  ]
                         [    1.2195 +/- 0.0023        0.0899 +/- 0.0021        1.6908 +/- 0.0009  ]

Translation vectors (inches):
                         [  -13.4723 +/- 0.1108        3.9026 +/- 0.1451       75.4292 +/- 0.1327  ]
                         [  -14.9313 +/- 0.0919      -13.5842 +/- 0.1207       61.2792 +/- 0.1374  ]
                         [   16.7684 +/- 0.0879      -12.4416 +/- 0.1169       59.5286 +/- 0.1415  ]
% View reprojection errors
figure; showReprojectionErrors(cameraParams);
% Visualize pattern locations
figure; showExtrinsics(cameraParams, 'CameraCentric');
% 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')