[810]  1  %=======================================================================


 2  % Copyright 20082014, LEGI UMR 5519 / CNRS UJF GINP, Grenoble, France


 3  % http://www.legi.grenobleinp.fr


 4  % Joel.Sommeria  Joel.Sommeria (A) legi.cnrs.fr


 5  %


 6  % This file is part of the toolbox UVMAT.


 7  %


 8  % UVMAT is free software; you can redistribute it and/or modify


 9  % it under the terms of the GNU General Public License as published


 10  % by the Free Software Foundation; either version 2 of the license,


 11  % or (at your option) any later version.


 12  %


 13  % UVMAT is distributed in the hope that it will be useful,


 14  % but WITHOUT ANY WARRANTY; without even the implied warranty of


 15  % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the


 16  % GNU General Public License (see LICENSE.txt) for more details.


 17  %=======================================================================


 18 


[725]  19  %if exist('images_read');


 20  % active_images = active_images & images_read;


 21  %end;


 22 


 23  var2fix = 'dX_default';


 24 


 25  fixvariable;


 26 


 27  var2fix = 'dY_default';


 28 


 29  fixvariable;


 30 


 31  var2fix = 'map';


 32 


 33  fixvariable;


 34 


 35 


 36  if ~exist('n_ima'),


 37  data_calib;


 38  end;


 39 


 40  check_active_images;


 41 


 42  if ~exist(['I_' num2str(ind_active(1))]),


 43  ima_read_calib;


 44  if isempty(ind_read),


 45  disp('Cannot extract corners without images');


 46  return;


 47  end;


 48  end;


 49 


 50 


 51  fprintf(1,'\nExtraction of the grid corners on the images\n');


 52 


 53 


 54  if (exist('map')~=1), map = gray(256); end;


 55 


 56 


 57  if exist('dX'),


 58  dX_default = dX;


 59  end;


 60 


 61  if exist('dY'),


 62  dY_default = dY;


 63  end;


 64 


 65  if exist('n_sq_x'),


 66  n_sq_x_default = n_sq_x;


 67  end;


 68 


 69  if exist('n_sq_y'),


 70  n_sq_y_default = n_sq_y;


 71  end;


 72 


 73 


 74  if ~exist('dX_default')~exist('dY_default');


 75 


 76  % Setup of JY  3D calibration rig at Intel (new at Intel)  use units in mm to match Zhang


 77  dX_default = 30;


 78  dY_default = 30;


 79 


 80  % Setup of JY  3D calibration rig at Google  use units in mm to match Zhang


 81  dX_default = 100;


 82  dY_default = 100;


 83 


 84  end;


 85 


 86 


 87  if ~exist('n_sq_x_default')~exist('n_sq_y_default'),


 88  n_sq_x_default = 10;


 89  n_sq_y_default = 10;


 90  end;


 91 


 92  if ~exist('wintx_default')~exist('winty_default'),


 93  wintx_default = max(round(nx/128),round(ny/96));


 94  winty_default = wintx_default;


 95  clear wintx winty


 96  end;


 97 


 98 


 99  if ~exist('wintx')  ~exist('winty'),


 100  clear_windows; % Clear all the window sizes (to reinitiate)


 101  end;


 102 


 103 


 104 


 105  if ~exist('dont_ask'),


 106  dont_ask = 0;


 107  end;


 108 


 109 


 110  if ~dont_ask,


 111  ima_numbers = input('Number(s) of image(s) to process ([] = all images) = ');


 112  else


 113  ima_numbers = [];


 114  end;


 115 


 116  if isempty(ima_numbers),


 117  ima_proc = 1:n_ima;


 118  else


 119  ima_proc = ima_numbers;


 120  end;


 121 


 122 


 123  % Useful option to add images:


 124  kk_first = ima_proc(1); %input('Start image number ([]=1=first): ');


 125 


 126 


 127  if exist(['wintx_' num2str(kk_first)]),


 128 


 129  eval(['wintxkk = wintx_' num2str(kk_first) ';']);


 130 


 131  if isempty(wintxkk)  isnan(wintxkk),


 132 


 133  disp('Window size for corner finder (wintx and winty):');


 134  wintx = input(['wintx ([] = ' num2str(wintx_default) ') = ']);


 135  if isempty(wintx), wintx = wintx_default; end;


 136  wintx = round(wintx);


 137  winty = input(['winty ([] = ' num2str(winty_default) ') = ']);


 138  if isempty(winty), winty = winty_default; end;


 139  winty = round(winty);


 140 


 141  fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);


 142 


 143  end;


 144 


 145  else


 146 


 147  disp('Window size for corner finder (wintx and winty):');


 148  wintx = input(['wintx ([] = ' num2str(wintx_default) ') = ']);


 149  if isempty(wintx), wintx = wintx_default; end;


 150  wintx = round(wintx);


 151  winty = input(['winty ([] = ' num2str(winty_default) ') = ']);


 152  if isempty(winty), winty = winty_default; end;


 153  winty = round(winty);


 154 


 155  fprintf(1,'Window size = %dx%d\n',2*wintx+1,2*winty+1);


 156 


 157  end;


 158 


 159 


 160  if ~dont_ask,


 161  fprintf(1,'Do you want to use the automatic square counting mechanism (0=[]=default)\n');


 162  manual_squares = input(' or do you always want to enter the number of squares manually (1,other)? ');


 163  if isempty(manual_squares),


 164  manual_squares = 0;


 165  else


 166  manual_squares = ~~manual_squares;


 167  end;


 168  else


 169  manual_squares = 0;


 170  end;


 171 


 172 


 173  for kk = ima_proc,


 174  if exist(['I_' num2str(kk)]),


 175  click_ima_calib;


 176  active_images(kk) = 1;


 177  else


 178  eval(['dX_' num2str(kk) ' = NaN;']);


 179  eval(['dY_' num2str(kk) ' = NaN;']);


 180 


 181  eval(['wintx_' num2str(kk) ' = NaN;']);


 182  eval(['winty_' num2str(kk) ' = NaN;']);


 183 


 184  eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);


 185  eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);


 186 


 187  eval(['n_sq_x_' num2str(kk) ' = NaN;']);


 188  eval(['n_sq_y_' num2str(kk) ' = NaN;']);


 189  end;


 190  end;


 191 


 192 


 193  check_active_images;


 194 


 195 


 196 


 197  % Fix potential nonexisting variables:


 198 


 199  for kk = 1:n_ima,


 200  if ~exist(['x_' num2str(kk)]),


 201  eval(['dX_' num2str(kk) ' = NaN;']);


 202  eval(['dY_' num2str(kk) ' = NaN;']);


 203 


 204  eval(['x_' num2str(kk) ' = NaN*ones(2,1);']);


 205  eval(['X_' num2str(kk) ' = NaN*ones(3,1);']);


 206 


 207  eval(['n_sq_x_' num2str(kk) ' = NaN;']);


 208  eval(['n_sq_y_' num2str(kk) ' = NaN;']);


 209  end;


 210 


 211  if ~exist(['wintx_' num2str(kk)])  ~exist(['winty_' num2str(kk)]),


 212 


 213  eval(['wintx_' num2str(kk) ' = NaN;']);


 214  eval(['winty_' num2str(kk) ' = NaN;']);


 215 


 216  end;


 217  end;


 218 


 219  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';


 220 


 221  for kk = 1:n_ima,


 222  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)];


 223  end;


 224 


 225  eval(string_save);


 226 


 227  disp('done');


 228 


 229  return;


 230 


 231  go_calib_optim;


 232 

