-
Notifications
You must be signed in to change notification settings - Fork 2
/
saving_calib.m
executable file
·211 lines (163 loc) · 5.74 KB
/
saving_calib.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
if ~exist('n_ima')|~exist('fc'),
fprintf(1,'No calibration data available.\n');
return;
end;
if ~exist('no_image'),
no_image = 0;
end;
if ~exist('est_alpha'),
est_alpha = 0;
end;
if ~exist('center_optim'),
center_optim = 1;
end;
if ~exist('est_aspect_ratio'),
est_aspect_ratio = 1;
end;
if ~exist('est_fc');
est_fc = [1;1]; % Set to zero if you do not want to estimate the focal length (it may be useful! believe it or not!)
end;
if exist('est_dist'),
if length(est_dist) == 4,
est_dist = [est_dist ; 0];
end;
end;
if exist('kc'),
if length(kc) == 4;
kc = [kc;0];
end;
end;
if ~exist('fc_error'),
fc_error = NaN*ones(2,1);
end;
if ~exist('kc_error'),
kc_error = NaN*ones(5,1);
end;
if ~exist('cc_error'),
cc_error = NaN*ones(2,1);
end;
if ~exist('alpha_c_error'),
alpha_c_error = NaN;
end;
check_active_images;
if ~exist('solution_init'), solution_init = []; end;
for kk = 1:n_ima,
if ~exist(['dX_' num2str(kk)]), eval(['dX_' num2str(kk) '= dX;']); end;
if ~exist(['dY_' num2str(kk)]), eval(['dY_' num2str(kk) '= dY;']); end;
end;
if ~exist('solution'),
solution = [];
end;
if ~exist('param_list'),
param_list = solution;
end;
if ~exist('wintx'),
wintx = [];
winty = [];
end;
if ~exist('dX_default'),
dX_default = [];
dY_default = [];
end;
if ~exist('dX'),
dX = [];
end;
if ~exist('dY'),
dY = dX;
end;
if ~exist('map'),
map = [];
end;
if ~exist('wintx_default')|~exist('winty_default'),
wintx_default = max(round(nx/128),round(ny/96));
winty_default = wintx_default;
end;
if ~exist('alpha_c'),
alpha_c = 0;
end;
if ~exist('err_std'),
err_std = [NaN;NaN];
end;
for kk = 1:n_ima,
if ~exist(['y_' num2str(kk)]),
eval(['y_' num2str(kk) ' = NaN*ones(2,1);']);
end;
if ~exist(['n_sq_x_' num2str(kk)]),
eval(['n_sq_x_' num2str(kk) ' = NaN;']);
eval(['n_sq_y_' num2str(kk) ' = NaN;']);
end;
if ~exist(['wintx_' num2str(kk)]),
eval(['wintx_' num2str(kk) ' = NaN;']);
eval(['winty_' num2str(kk) ' = NaN;']);
end;
if ~exist(['Tc_' num2str(kk)]),
eval(['Tc_' num2str(kk) ' = [NaN;NaN;NaN];']);
end;
if ~exist(['omc_' num2str(kk)]),
eval(['omc_' num2str(kk) ' = [NaN;NaN;NaN];']);
eval(['Rc_' num2str(kk) ' = NaN * ones(3,3);']);
end;
if ~exist(['omc_error_' num2str(kk)]),
eval(['omc_error_' num2str(kk) ' = NaN*ones(3,1);']);
end;
if ~exist(['Tc_error_' num2str(kk)]),
eval(['Tc_error_' num2str(kk) ' = NaN*ones(3,1);']);
end;
if ~exist(['Rc_' num2str(kk)]),
eval(['Rc_' num2str(kk) ' = rodrigues(omc_' num2str(kk) ');']);
end;
end;
if ~exist('check_cond'),
check_cond = 1;
end;
if ~exist('MaxIter'),
MaxIter = 30;
end;
save_name = 'Calib_Results';
if exist([ save_name '.mat'])==2,
disp('WARNING: File Calib_Results.mat already exists');
if exist('copyfile'),
pfn = -1;
cont = 1;
while cont,
pfn = pfn + 1;
postfix = ['_old' num2str(pfn)];
save_name = [ 'Calib_Results' postfix];
cont = (exist([ save_name '.mat'])==2);
end;
copyfile('Calib_Results.mat',[save_name '.mat']);
disp(['Copying the current Calib_Results.mat file to ' save_name '.mat']);
if exist('Calib_Results.m')==2,
copyfile('Calib_Results.m',[save_name '.m']);
disp(['Copying the current Calib_Results.m file to ' save_name '.m']);
end;
cont_save = 1;
else
disp('The file Calib_Results.mat is about to be changed.');
cont_save = input('Do you want to continue? ([]=no,other=yes) ','s');
cont_save = ~isempty(cont_save);
end;
else
cont_save = 1;
end;
if cont_save,
save_name = 'Calib_Results';
if exist('calib_name'),
fprintf(1,['\nSaving calibration results under ' save_name '.mat\n']);
string_save = ['save ' save_name ' center_optim param_list active_images ind_active est_alpha est_dist est_aspect_ratio est_fc fc kc cc alpha_c fc_error kc_error cc_error alpha_c_error err_std ex x y solution solution_init wintx winty n_ima type_numbering N_slots first_num image_numbers format_image calib_name nx ny map dX_default dY_default KK inv_KK dX dY wintx_default winty_default no_image check_cond MaxIter'];
for kk = 1:n_ima,
string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' omc_error_' num2str(kk) ' Tc_error_' num2str(kk) ' H_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
end;
else
fprintf(1,['\nSaving calibration results under ' save_name '.mat (no image version)\n']);
string_save = ['save ' save_name ' center_optim param_list active_images ind_active est_alpha est_dist est_aspect_ratio est_fc fc kc cc alpha_c fc_error kc_error cc_error alpha_c_error err_std ex x y solution solution_init wintx winty n_ima nx ny dX_default dY_default KK inv_KK dX dY wintx_default winty_default no_image check_cond MaxIter'];
for kk = 1:n_ima,
string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' y_' num2str(kk) ' ex_' num2str(kk) ' omc_' num2str(kk) ' Rc_' num2str(kk) ' Tc_' num2str(kk) ' omc_error_' num2str(kk) ' Tc_error_' num2str(kk) ' H_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)];
end;
end;
%fprintf(1,'To load later click on Load\n');
eval(string_save);
clear string_save
saving_calib_ascii;
fprintf(1,'done\n');
end;