-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_bestCalibration_REMOTE_4188.m
70 lines (56 loc) · 3.45 KB
/
C_bestCalibration_REMOTE_4188.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function [cameraParams, trans, rot] = C_bestCalibration(video)
% Define images to process
imageFileNames = {'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal1.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal3.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal5.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cala6.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal7.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal8.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal9.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal10.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal11.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal13.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal14.png',...
'C:\Users\Seeing The Invisible\Google Drive\Uni\Courses\2016 Semester 2\METR4202\Lab 3\METR4202-master\Calibration\cal15.png',...
};
frames = [];
for i=1:numel(imageFileNames)
frames = cat(4,frames, fliplr(imread(imageFileNames{i})));
end
start(video);
display(sprintf('Ready to take reference frame. Press any key to take photo...'));
pause
trigger(video);
[f, ~, ~] = getdata(video);
stop(video);
%Flips left and right to give real view with fliplr
frames = cat(4,frames, fliplr(f));
% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(frames);
% imageFileNames = imageFileNames(imagesUsed);
if (imagesUsed(end) == 0)
error('You are in trouble mister');
end
% Generate world coordinates of the corners of the squares
squareSize = 1.341600e+01; % in units of 'mm'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);
% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'mm', ...
'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', []);
% View reprojection errors
% h1=figure; showReprojectionErrors(cameraParams, 'CameraCentric');
% 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.
originalImage = imread(imageFileNames{1});
undistortedImage = undistortImage(originalImage, cameraParams);
trans = cameraParams.TranslationVectors(end, :);
rot = cameraParams.RotationMatrices(:,:,end);
% See additional examples of how to use the calibration data. At the prompt type:
% showdemo('MeasuringPlanarObjectsExample')
% showdemo('StructureFromMotionExample')
end