1 | %% Export calibration data (corners + 3D coordinates) to
|
---|
2 | %% text files (in Willson-Heikkila's format or Zhang's format)
|
---|
3 |
|
---|
4 | %% Thanks to Michael Goesele (from the Max-Planck-Institut) for the original suggestion
|
---|
5 | %% of adding this export function to the toolbox.
|
---|
6 |
|
---|
7 |
|
---|
8 | if ~exist('n_ima'),
|
---|
9 | fprintf(1,'ERROR: No calibration data to export\n');
|
---|
10 |
|
---|
11 | else
|
---|
12 |
|
---|
13 | check_active_images;
|
---|
14 |
|
---|
15 | % check_extracted_images;
|
---|
16 |
|
---|
17 | check_active_images;
|
---|
18 |
|
---|
19 | % fprintf(1,'Tool that exports calibration data to Willson-Heikkila, Zhang formats or blue-c formats\n');
|
---|
20 |
|
---|
21 | qformat = 3;
|
---|
22 |
|
---|
23 | if 0
|
---|
24 | while (qformat ~=0)&(qformat ~=1)&(qformat ~=2)&(qformat ~=3),
|
---|
25 |
|
---|
26 | fprintf(1,'Three possible formats of export: 0=Willson and Heikkila, 1=Zhang, 2=blue-c, complete, 3=blue-c, intrinsic\n')
|
---|
27 | qformat = input('Format of export (enter 0, 1, 2, or 3): ');
|
---|
28 |
|
---|
29 | if isempty(qformat)
|
---|
30 | qformat = -1;
|
---|
31 | end;
|
---|
32 |
|
---|
33 | if (qformat ~=0)&(qformat ~=1)&(qformat ~=2)&(qformat ~=3),
|
---|
34 |
|
---|
35 | fprintf(1,'Invalid entry. Try again.\n')
|
---|
36 |
|
---|
37 | end;
|
---|
38 |
|
---|
39 | end;
|
---|
40 | end
|
---|
41 |
|
---|
42 | if qformat == 0
|
---|
43 |
|
---|
44 | fprintf(1,'\nExport of calibration data to text files (Willson and Heikkila''s format)\n');
|
---|
45 | outputfile = input('File basename: ','s');
|
---|
46 |
|
---|
47 | for kk = ind_active,
|
---|
48 |
|
---|
49 | eval(['X_kk = X_' num2str(kk) ';']);
|
---|
50 | eval(['x_kk = x_' num2str(kk) ';']);
|
---|
51 |
|
---|
52 | Xx = [X_kk ; x_kk]';
|
---|
53 |
|
---|
54 | file_name = [outputfile num2str(kk)];
|
---|
55 |
|
---|
56 | disp(['Exporting calibration data (3D world + 2D image coordinates) of image ' num2str(kk) ' to file ' file_name '...']);
|
---|
57 |
|
---|
58 | eval(['save ' file_name ' Xx -ASCII']);
|
---|
59 |
|
---|
60 | end;
|
---|
61 |
|
---|
62 | elseif qformat == 1
|
---|
63 |
|
---|
64 | fprintf(1,'\nExport of calibration data to text files (Zhang''s format)\n');
|
---|
65 | modelfile = input('File basename for the 3D world coordinates: ','s');
|
---|
66 | datafile = input('File basename for the 2D image coordinates: ','s');
|
---|
67 |
|
---|
68 | for kk = ind_active,
|
---|
69 |
|
---|
70 | eval(['X_kk = X_' num2str(kk) ';']);
|
---|
71 | eval(['x_kk = x_' num2str(kk) ';']);
|
---|
72 |
|
---|
73 | if ~exist(['n_sq_x_' num2str(kk)]),
|
---|
74 | n_sq_x = 1;
|
---|
75 | n_sq_y = size(X_kk,2);
|
---|
76 | else
|
---|
77 | eval(['n_sq_x = n_sq_x_' num2str(kk) ';']);
|
---|
78 | eval(['n_sq_y = n_sq_y_' num2str(kk) ';']);
|
---|
79 | end;
|
---|
80 |
|
---|
81 | X = reshape(X_kk(1,:)',n_sq_x+1,n_sq_y+1)';
|
---|
82 | Y = reshape(X_kk(2,:)',n_sq_x+1,n_sq_y+1)';
|
---|
83 | XY = reshape([X;Y],n_sq_y+1,2*(n_sq_x+1));
|
---|
84 |
|
---|
85 | x = reshape(x_kk(1,:)',n_sq_x+1,n_sq_y+1)';
|
---|
86 | y = reshape(x_kk(2,:)',n_sq_x+1,n_sq_y+1)';
|
---|
87 | xy = reshape([x;y],n_sq_y+1,2*(n_sq_x+1));
|
---|
88 |
|
---|
89 | disp(['Exporting calibration data of image ' num2str(kk) ' to files ' modelfile num2str(kk) '.txt and ' datafile num2str(kk) '.txt...']);
|
---|
90 |
|
---|
91 | eval(['save ' modelfile num2str(kk) '.txt XY -ASCII']);
|
---|
92 | eval(['save ' datafile num2str(kk) '.txt xy -ASCII']);
|
---|
93 | end;
|
---|
94 |
|
---|
95 | elseif qformat == 2
|
---|
96 |
|
---|
97 | fprintf(1,'\nExport of complete calibration data to blue-c configuration file\n');
|
---|
98 | % outputfile = input('File basename: ', 's');
|
---|
99 | configfile = [outputfile '.cal'];
|
---|
100 | disp(['Writing ' configfile]);
|
---|
101 |
|
---|
102 | fid = fopen(configfile, 'w');
|
---|
103 | fprintf(fid, 'R11 = %.16f\n', Rc_ext(1,1));
|
---|
104 | fprintf(fid, 'R12 = %.16f\n', Rc_ext(1,2));
|
---|
105 | fprintf(fid, 'R13 = %.16f\n', Rc_ext(1,3));
|
---|
106 | fprintf(fid, 'R21 = %.16f\n', Rc_ext(2,1));
|
---|
107 | fprintf(fid, 'R22 = %.16f\n', Rc_ext(2,2));
|
---|
108 | fprintf(fid, 'R23 = %.16f\n', Rc_ext(2,3));
|
---|
109 | fprintf(fid, 'R31 = %.16f\n', Rc_ext(3,1));
|
---|
110 | fprintf(fid, 'R32 = %.16f\n', Rc_ext(3,2));
|
---|
111 | fprintf(fid, 'R33 = %.16f\n\n', Rc_ext(3,3));
|
---|
112 |
|
---|
113 | fprintf(fid, 't11 = %.16f\n', Tc_ext(1,1));
|
---|
114 | fprintf(fid, 't21 = %.16f\n', Tc_ext(2,1));
|
---|
115 | fprintf(fid, 't31 = %.16f\n\n', Tc_ext(3,1));
|
---|
116 |
|
---|
117 | fprintf(fid, 'K11 = %.16f\n', KK(1,1));
|
---|
118 | fprintf(fid, 'K12 = %.16f\n', KK(1,2));
|
---|
119 | fprintf(fid, 'K13 = %.16f\n', KK(1,3));
|
---|
120 | fprintf(fid, 'K21 = %.16f\n', KK(2,1));
|
---|
121 | fprintf(fid, 'K22 = %.16f\n', KK(2,2));
|
---|
122 | fprintf(fid, 'K23 = %.16f\n', KK(2,3));
|
---|
123 | fprintf(fid, 'K31 = %.16f\n', KK(3,1));
|
---|
124 | fprintf(fid, 'K32 = %.16f\n', KK(3,2));
|
---|
125 | fprintf(fid, 'K33 = %.16f\n\n', KK(3,3));
|
---|
126 |
|
---|
127 | fprintf(fid, 'kc1 = %.16f\n', kc(1));
|
---|
128 | fprintf(fid, 'kc2 = %.16f\n', kc(2));
|
---|
129 | fprintf(fid, 'kc3 = %.16f\n', kc(3));
|
---|
130 | fprintf(fid, 'kc4 = %.16f\n', kc(4));
|
---|
131 |
|
---|
132 | status = fclose(fid);
|
---|
133 |
|
---|
134 | else
|
---|
135 |
|
---|
136 | fprintf(1,'\nExport of intrinsic calibration data to blue-c configuration file\n');
|
---|
137 | % outputfile = input('File basename: ', 's');
|
---|
138 | configfile = outputfile;
|
---|
139 | disp(['Writing ' configfile]);
|
---|
140 |
|
---|
141 | fid = fopen(configfile, 'w');
|
---|
142 |
|
---|
143 | fprintf(fid, 'K11 = %.16f\n', KK(1,1));
|
---|
144 | fprintf(fid, 'K12 = %.16f\n', KK(1,2));
|
---|
145 | fprintf(fid, 'K13 = %.16f\n', KK(1,3));
|
---|
146 | fprintf(fid, 'K21 = %.16f\n', KK(2,1));
|
---|
147 | fprintf(fid, 'K22 = %.16f\n', KK(2,2));
|
---|
148 | fprintf(fid, 'K23 = %.16f\n', KK(2,3));
|
---|
149 | fprintf(fid, 'K31 = %.16f\n', KK(3,1));
|
---|
150 | fprintf(fid, 'K32 = %.16f\n', KK(3,2));
|
---|
151 | fprintf(fid, 'K33 = %.16f\n\n', KK(3,3));
|
---|
152 |
|
---|
153 | fprintf(fid, 'kc1 = %.16f\n', kc(1));
|
---|
154 | fprintf(fid, 'kc2 = %.16f\n', kc(2));
|
---|
155 | fprintf(fid, 'kc3 = %.16f\n', kc(3));
|
---|
156 | fprintf(fid, 'kc4 = %.16f\n', kc(4));
|
---|
157 |
|
---|
158 | status = fclose(fid);
|
---|
159 |
|
---|
160 | end;
|
---|
161 |
|
---|
162 | fprintf(1,'done\n');
|
---|
163 |
|
---|
164 | end;
|
---|