| 1 | %if exist('images_read'); |
---|
| 2 | % active_images = active_images & images_read; |
---|
| 3 | %end; |
---|
| 4 | |
---|
| 5 | var2fix = 'dX_default'; |
---|
| 6 | |
---|
| 7 | fixvariable; |
---|
| 8 | |
---|
| 9 | var2fix = 'dY_default'; |
---|
| 10 | |
---|
| 11 | fixvariable; |
---|
| 12 | |
---|
| 13 | var2fix = 'map'; |
---|
| 14 | |
---|
| 15 | fixvariable; |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | if ~exist('n_ima'), |
---|
| 19 | data_calib; |
---|
| 20 | end; |
---|
| 21 | |
---|
| 22 | check_active_images; |
---|
| 23 | |
---|
| 24 | if ~exist(['I_' num2str(ind_active(1))]), |
---|
| 25 | ima_read_calib; |
---|
| 26 | if isempty(ind_read), |
---|
| 27 | disp('Cannot extract corners without images'); |
---|
| 28 | return; |
---|
| 29 | end; |
---|
| 30 | end; |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | fprintf(1,'\nExtraction of the grid corners on the images\n'); |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | if (exist('map')~=1), map = gray(256); end; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | if exist('dX'), |
---|
| 40 | dX_default = dX; |
---|
| 41 | end; |
---|
| 42 | |
---|
| 43 | if exist('dY'), |
---|
| 44 | dY_default = dY; |
---|
| 45 | end; |
---|
| 46 | |
---|
| 47 | if exist('n_sq_x'), |
---|
| 48 | n_sq_x_default = n_sq_x; |
---|
| 49 | end; |
---|
| 50 | |
---|
| 51 | if exist('n_sq_y'), |
---|
| 52 | n_sq_y_default = n_sq_y; |
---|
| 53 | end; |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | if ~exist('dX_default')|~exist('dY_default'); |
---|
| 57 | |
---|
| 58 | % Setup of JY - 3D calibration rig at Intel (new at Intel) - use units in mm to match Zhang |
---|
| 59 | dX_default = 30; |
---|
| 60 | dY_default = 30; |
---|
| 61 | |
---|
| 62 | % Setup of JY - 3D calibration rig at Google - use units in mm to match Zhang |
---|
| 63 | dX_default = 100; |
---|
| 64 | dY_default = 100; |
---|
| 65 | |
---|
| 66 | end; |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | if ~exist('n_sq_x_default')|~exist('n_sq_y_default'), |
---|
| 70 | n_sq_x_default = 10; |
---|
| 71 | n_sq_y_default = 10; |
---|
| 72 | end; |
---|
| 73 | |
---|
| 74 | if ~exist('wintx_default')|~exist('winty_default'), |
---|
| 75 | wintx_default = max(round(nx/128),round(ny/96)); |
---|
| 76 | winty_default = wintx_default; |
---|
| 77 | clear wintx winty |
---|
| 78 | end; |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | if ~exist('wintx') | ~exist('winty'), |
---|
| 82 | clear_windows; % Clear all the window sizes (to re-initiate) |
---|
| 83 | end; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | if ~exist('dont_ask'), |
---|
| 88 | dont_ask = 0; |
---|
| 89 | end; |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | if ~dont_ask, |
---|
| 93 | ima_numbers = input('Number(s) of image(s) to process ([] = all images) = '); |
---|
| 94 | else |
---|
| 95 | ima_numbers = []; |
---|
| 96 | end; |
---|
| 97 | |
---|
| 98 | if isempty(ima_numbers), |
---|
| 99 | ima_proc = 1:n_ima; |
---|
| 100 | else |
---|
| 101 | ima_proc = ima_numbers; |
---|
| 102 | end; |
---|
| 103 | |
---|
| 104 | |
---|
| 105 | % Useful option to add images: |
---|
| 106 | kk_first = ima_proc(1); %input('Start image number ([]=1=first): '); |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | if exist(['wintx_' num2str(kk_first)]), |
---|
| 110 | |
---|
| 111 | eval(['wintxkk = wintx_' num2str(kk_first) ';']); |
---|
| 112 | |
---|
| 113 | if isempty(wintxkk) | isnan(wintxkk), |
---|
| 114 | |
---|
| 115 | disp('Window size for corner finder (wintx and winty):'); |
---|
| 116 | wintx = input(['wintx ([] = ' num2str(wintx_default) ') = ']); |
---|
| 117 | if isempty(wintx), wintx = wintx_default; end; |
---|
| 118 | wintx = round(wintx); |
---|
| 119 | winty = input(['winty ([] = ' num2str(winty_default) ') = ']); |
---|
| 120 | if isempty(winty), winty = winty_default; end; |
---|
| 121 | winty = round(winty); |
---|
| 122 | |
---|
| 123 | fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1); |
---|
| 124 | |
---|
| 125 | end; |
---|
| 126 | |
---|
| 127 | else |
---|
| 128 | |
---|
| 129 | disp('Window size for corner finder (wintx and winty):'); |
---|
| 130 | wintx = input(['wintx ([] = ' num2str(wintx_default) ') = ']); |
---|
| 131 | if isempty(wintx), wintx = wintx_default; end; |
---|
| 132 | wintx = round(wintx); |
---|
| 133 | winty = input(['winty ([] = ' num2str(winty_default) ') = ']); |
---|
| 134 | if isempty(winty), winty = winty_default; end; |
---|
| 135 | winty = round(winty); |
---|
| 136 | |
---|
| 137 | fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1); |
---|
| 138 | |
---|
| 139 | end; |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | if ~dont_ask, |
---|
| 143 | fprintf(1,'Do you want to use the automatic square counting mechanism (0=[]=default)\n'); |
---|
| 144 | manual_squares = input(' or do you always want to enter the number of squares manually (1,other)? '); |
---|
| 145 | if isempty(manual_squares), |
---|
| 146 | manual_squares = 0; |
---|
| 147 | else |
---|
| 148 | manual_squares = ~~manual_squares; |
---|
| 149 | end; |
---|
| 150 | else |
---|
| 151 | manual_squares = 0; |
---|
| 152 | end; |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | for kk = ima_proc, |
---|
| 156 | if exist(['I_' num2str(kk)]), |
---|
| 157 | click_ima_calib; |
---|
| 158 | active_images(kk) = 1; |
---|
| 159 | else |
---|
| 160 | eval(['dX_' num2str(kk) ' = NaN;']); |
---|
| 161 | eval(['dY_' num2str(kk) ' = NaN;']); |
---|
| 162 | |
---|
| 163 | eval(['wintx_' num2str(kk) ' = NaN;']); |
---|
| 164 | eval(['winty_' num2str(kk) ' = NaN;']); |
---|
| 165 | |
---|
| 166 | eval(['x_' num2str(kk) ' = NaN*ones(2,1);']); |
---|
| 167 | eval(['X_' num2str(kk) ' = NaN*ones(3,1);']); |
---|
| 168 | |
---|
| 169 | eval(['n_sq_x_' num2str(kk) ' = NaN;']); |
---|
| 170 | eval(['n_sq_y_' num2str(kk) ' = NaN;']); |
---|
| 171 | end; |
---|
| 172 | end; |
---|
| 173 | |
---|
| 174 | |
---|
| 175 | check_active_images; |
---|
| 176 | |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | % Fix potential non-existing variables: |
---|
| 180 | |
---|
| 181 | for kk = 1:n_ima, |
---|
| 182 | if ~exist(['x_' num2str(kk)]), |
---|
| 183 | eval(['dX_' num2str(kk) ' = NaN;']); |
---|
| 184 | eval(['dY_' num2str(kk) ' = NaN;']); |
---|
| 185 | |
---|
| 186 | eval(['x_' num2str(kk) ' = NaN*ones(2,1);']); |
---|
| 187 | eval(['X_' num2str(kk) ' = NaN*ones(3,1);']); |
---|
| 188 | |
---|
| 189 | eval(['n_sq_x_' num2str(kk) ' = NaN;']); |
---|
| 190 | eval(['n_sq_y_' num2str(kk) ' = NaN;']); |
---|
| 191 | end; |
---|
| 192 | |
---|
| 193 | if ~exist(['wintx_' num2str(kk)]) | ~exist(['winty_' num2str(kk)]), |
---|
| 194 | |
---|
| 195 | eval(['wintx_' num2str(kk) ' = NaN;']); |
---|
| 196 | eval(['winty_' num2str(kk) ' = NaN;']); |
---|
| 197 | |
---|
| 198 | end; |
---|
| 199 | end; |
---|
| 200 | |
---|
| 201 | string_save = 'save calib_data active_images ind_active wintx winty n_ima type_numbering N_slots first_num image_numbers format_image calib_name Hcal Wcal nx ny map dX_default dY_default dX dY wintx_default winty_default'; |
---|
| 202 | |
---|
| 203 | for kk = 1:n_ima, |
---|
| 204 | string_save = [string_save ' X_' num2str(kk) ' x_' num2str(kk) ' n_sq_x_' num2str(kk) ' n_sq_y_' num2str(kk) ' wintx_' num2str(kk) ' winty_' num2str(kk) ' dX_' num2str(kk) ' dY_' num2str(kk)]; |
---|
| 205 | end; |
---|
| 206 | |
---|
| 207 | eval(string_save); |
---|
| 208 | |
---|
| 209 | disp('done'); |
---|
| 210 | |
---|
| 211 | return; |
---|
| 212 | |
---|
| 213 | go_calib_optim; |
---|
| 214 | |
---|