-
Notifications
You must be signed in to change notification settings - Fork 0
/
C_bestCalibration_BACKUP_4188.m
142 lines (114 loc) · 6.97 KB
/
C_bestCalibration_BACKUP_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<<<<<<< HEAD
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')
=======
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')
>>>>>>> 1680c7136916d640a85d6cb61fdc5609cb814feb
end