[168] | 1 | %'geometry_calib': associated to the GUI geometry_calib to perform geometric calibration from a set of reference points |
---|
| 2 | %------------------------------------------------------------------------ |
---|
| 3 | % function hgeometry_calib = geometry_calib(inputfile,pos) |
---|
[2] | 4 | % |
---|
[168] | 5 | %OUTPUT: |
---|
| 6 | % hgeometry_calib=current handles of the GUI geometry_calib.fig |
---|
[2] | 7 | % |
---|
[168] | 8 | %INPUT: |
---|
| 9 | % inputfile: (optional) name of an xml file containing coordinates of reference points |
---|
| 10 | % pos: (optional) 4 element vector setting the 'Position' of the GUI |
---|
| 11 | % |
---|
[109] | 12 | %A%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
[2] | 13 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
| 14 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 15 | % This file is part of the toolbox UVMAT. |
---|
| 16 | % |
---|
| 17 | % UVMAT is free software; you can redistribute it and/or modify |
---|
| 18 | % it under the terms of the GNU General Public License as published by |
---|
| 19 | % the Free Software Foundation; either version 2 of the License, or |
---|
| 20 | % (at your option) any later version. |
---|
| 21 | % |
---|
| 22 | % UVMAT is distributed in the hope that it will be useful, |
---|
| 23 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 24 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 25 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
| 26 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
| 27 | |
---|
| 28 | function varargout = geometry_calib(varargin) |
---|
| 29 | % GEOMETRY_CALIB M-file for geometry_calib.fig |
---|
| 30 | % GEOMETRY_CALIB, by itself, creates a MenuCoord GEOMETRY_CALIB or raises the existing |
---|
| 31 | % singleton*. |
---|
| 32 | % |
---|
| 33 | % H = GEOMETRY_CALIB returns the handle to a MenuCoord GEOMETRY_CALIB or the handle to |
---|
| 34 | % the existing singleton*. |
---|
| 35 | % |
---|
| 36 | % GEOMETRY_CALIB('CALLBACK',hObject,eventData,handles,...) calls the local |
---|
| 37 | % function named CALLBACK in GEOMETRY_CALIB.M with the given input arguments. |
---|
| 38 | % |
---|
| 39 | % GEOMETRY_CALIB('Property','Value',...) creates a MenuCoord GEOMETRY_CALIB or raises the |
---|
| 40 | % existing singleton*. Starting from the left, property value pairs are |
---|
| 41 | % applied to the GUI before geometry_calib_OpeningFunction gets called. An |
---|
| 42 | % unrecognized property name or invalid value makes property application |
---|
| 43 | % stop. All inputs are passed to geometry_calib_OpeningFcn via varargin. |
---|
| 44 | % |
---|
| 45 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one |
---|
| 46 | % instance to run (singleton)". |
---|
| 47 | % |
---|
| 48 | % See also: GUIDE, GUIDATA, GUIHANDLES |
---|
| 49 | |
---|
| 50 | % Edit the above text to modify the response to help geometry_calib |
---|
| 51 | |
---|
[507] | 52 | % Last Modified by GUIDE v2.5 29-Jul-2012 08:46:09 |
---|
[2] | 53 | |
---|
| 54 | % Begin initialization code - DO NOT edit |
---|
| 55 | gui_Singleton = 1; |
---|
| 56 | gui_State = struct('gui_Name', mfilename, ... |
---|
| 57 | 'gui_Singleton', gui_Singleton, ... |
---|
| 58 | 'gui_OpeningFcn', @geometry_calib_OpeningFcn, ... |
---|
| 59 | 'gui_OutputFcn', @geometry_calib_OutputFcn, ... |
---|
| 60 | 'gui_LayoutFcn', [] , ... |
---|
| 61 | 'gui_Callback', []); |
---|
[128] | 62 | if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once')) |
---|
[2] | 63 | gui_State.gui_Callback = str2func(varargin{1}); |
---|
| 64 | end |
---|
| 65 | |
---|
| 66 | if nargout |
---|
| 67 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); |
---|
| 68 | else |
---|
| 69 | gui_mainfcn(gui_State, varargin{:}); |
---|
| 70 | end |
---|
| 71 | % End initialization code - DO NOT edit |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | % --- Executes just before geometry_calib is made visible. |
---|
| 75 | %INPUT: |
---|
| 76 | %handles: handles of the geometry_calib interface elements |
---|
| 77 | % PlotHandles: set of handles of the elements contolling the plotting |
---|
| 78 | % parameters on the uvmat interface (obtained by 'get_plot_handle.m') |
---|
[60] | 79 | %------------------------------------------------------------------------ |
---|
[116] | 80 | function geometry_calib_OpeningFcn(hObject, eventdata, handles,inputfile,pos) |
---|
[60] | 81 | %------------------------------------------------------------------------ |
---|
[2] | 82 | % Choose default command line output for geometry_calib |
---|
[156] | 83 | |
---|
[2] | 84 | handles.output = hObject; |
---|
| 85 | |
---|
| 86 | % Update handles structure |
---|
| 87 | guidata(hObject, handles); |
---|
[71] | 88 | set(hObject,'DeleteFcn',{@closefcn})% |
---|
[252] | 89 | set(hObject,'WindowButtonDownFcn',{'mouse_alt_gui',handles}) % allows mouse action with right button (zoom for uicontrol display) |
---|
[71] | 90 | |
---|
[2] | 91 | %set the position of the interface |
---|
[156] | 92 | if exist('pos','var')&& length(pos)>=4 |
---|
| 93 | set(hObject,'Position',pos); |
---|
[2] | 94 | end |
---|
[109] | 95 | |
---|
| 96 | %set menu of calibration options |
---|
[121] | 97 | set(handles.calib_type,'String',{'rescale';'linear';'3D_linear';'3D_quadr';'3D_extrinsic'}) |
---|
[116] | 98 | if exist('inputfile','var')&& ~isempty(inputfile) |
---|
[114] | 99 | struct.XmlInputFile=inputfile; |
---|
[494] | 100 | [RootPath,SubDir,RootFile,tild,tild,tild,tild,FileExt]=fileparts_uvmat(inputfile); |
---|
[341] | 101 | if ~strcmp(FileExt,'.xml') |
---|
[494] | 102 | inputfile=fullfile(RootPath,[SubDir '.xml']);%xml file corresponding to the input file |
---|
| 103 | if ~exist(inputfile,'file')% case of civ files , removes the extension for subdir |
---|
| 104 | inputfile=fullfile(RootPath,[regexprep(SubDir,'\..+$','') '.xml']); |
---|
| 105 | if ~exist(inputfile,'file') |
---|
| 106 | inputfile=[fullfile(RootPath,SubDir,RootFile) '.xml'];%old convention |
---|
| 107 | if ~exist(inputfile,'file') |
---|
| 108 | inputfile=''; |
---|
| 109 | end |
---|
| 110 | end |
---|
| 111 | end |
---|
[116] | 112 | end |
---|
[156] | 113 | set(handles.ListCoord,'String',{'......'}) |
---|
| 114 | if exist(inputfile,'file') |
---|
[498] | 115 | Heading=loadfile(handles,inputfile);% load data from the xml file |
---|
[156] | 116 | if isfield(Heading,'Campaign')&& ischar(Heading.Campaign) |
---|
| 117 | struct.Campaign=Heading.Campaign; |
---|
| 118 | end |
---|
| 119 | end |
---|
| 120 | set(hObject,'UserData',struct) |
---|
[2] | 121 | end |
---|
[156] | 122 | |
---|
[2] | 123 | set(handles.ListCoord,'KeyPressFcn',{@key_press_fcn,handles})%set keyboard action function |
---|
| 124 | |
---|
[71] | 125 | |
---|
[17] | 126 | %------------------------------------------------------------------------ |
---|
[2] | 127 | % --- Outputs from this function are returned to the command line. |
---|
| 128 | function varargout = geometry_calib_OutputFcn(hObject, eventdata, handles) |
---|
[17] | 129 | %------------------------------------------------------------------------ |
---|
[2] | 130 | % Get default command line output from handles structure |
---|
| 131 | varargout{1} = handles.output; |
---|
| 132 | varargout{2}=handles; |
---|
[67] | 133 | % |
---|
[60] | 134 | %------------------------------------------------------------------------ |
---|
[2] | 135 | % executed when closing: set the parent interface button to value 0 |
---|
[67] | 136 | function closefcn(gcbo,eventdata) |
---|
[60] | 137 | %------------------------------------------------------------------------ |
---|
[2] | 138 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
[67] | 139 | if ~isempty(huvmat) |
---|
| 140 | handles=guidata(huvmat); |
---|
| 141 | hobject=findobj(handles.axes3,'tag','calib_points'); |
---|
| 142 | if ~isempty(hobject) |
---|
| 143 | delete(hobject) |
---|
| 144 | end |
---|
| 145 | hobject=findobj(handles.axes3,'tag','calib_marker'); |
---|
| 146 | if ~isempty(hobject) |
---|
| 147 | delete(hobject) |
---|
| 148 | end |
---|
[2] | 149 | end |
---|
| 150 | |
---|
[60] | 151 | %------------------------------------------------------------------------ |
---|
[2] | 152 | % --- Executes on button press in calibrate_lin. |
---|
| 153 | function APPLY_Callback(hObject, eventdata, handles) |
---|
[60] | 154 | %------------------------------------------------------------------------ |
---|
[379] | 155 | %% look for the GUI uvmat and check for an image as input |
---|
| 156 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
| 157 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat |
---|
| 158 | FileExt=get(hhuvmat.FileExt,'String'); |
---|
[502] | 159 | % check_input=0; |
---|
| 160 | % if ~isempty(FileExt) |
---|
| 161 | % if ~isempty(imformats(FileExt(2:end))) ||strcmpi(FileExt,'.avi') |
---|
| 162 | % check_input=1; |
---|
| 163 | % end |
---|
| 164 | % end |
---|
| 165 | % % if ~check_input |
---|
| 166 | % msgbox_uvmat('ERROR','open an image with uvmat to perform calibration') |
---|
| 167 | % return |
---|
| 168 | % end |
---|
[379] | 169 | |
---|
| 170 | %% read the current calibration points |
---|
[2] | 171 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 172 | Object=read_geometry_calib(Coord_cell); |
---|
[109] | 173 | Coord=Object.Coord; |
---|
| 174 | % apply the calibration, whose type is selected in handles.calib_type |
---|
| 175 | if ~isempty(Coord) |
---|
| 176 | calib_cell=get(handles.calib_type,'String'); |
---|
| 177 | val=get(handles.calib_type,'Value'); |
---|
| 178 | GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); |
---|
| 179 | else |
---|
| 180 | msgbox_uvmat('ERROR','No calibration points, abort') |
---|
| 181 | return |
---|
| 182 | end |
---|
[114] | 183 | Z_plane=[]; |
---|
[109] | 184 | if ~isempty(Coord) |
---|
[114] | 185 | %check error |
---|
[109] | 186 | X=Coord(:,1); |
---|
| 187 | Y=Coord(:,2); |
---|
| 188 | Z=Coord(:,3); |
---|
| 189 | x_ima=Coord(:,4); |
---|
| 190 | y_ima=Coord(:,5); |
---|
[114] | 191 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); |
---|
[109] | 192 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
| 193 | [GeometryCalib.ErrorMax(1),index(1)]=max(abs(Xpoints-x_ima)); |
---|
| 194 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
| 195 | [GeometryCalib.ErrorMax(2),index(2)]=max(abs(Ypoints-y_ima)); |
---|
[494] | 196 | [tild,ind_dim]=max(GeometryCalib.ErrorMax); |
---|
[109] | 197 | index=index(ind_dim); |
---|
[114] | 198 | %set the Z position of the reference plane used for calibration |
---|
[109] | 199 | if isequal(max(Z),min(Z))%Z constant |
---|
[114] | 200 | Z_plane=Z(1); |
---|
[109] | 201 | GeometryCalib.NbSlice=1; |
---|
[114] | 202 | GeometryCalib.SliceCoord=[0 0 Z_plane]; |
---|
[109] | 203 | end |
---|
| 204 | end |
---|
[114] | 205 | %set the coordinate unit |
---|
[2] | 206 | unitlist=get(handles.CoordUnit,'String'); |
---|
| 207 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
| 208 | GeometryCalib.CoordUnit=unit; |
---|
[114] | 209 | %record the points |
---|
[109] | 210 | GeometryCalib.SourceCalib.PointCoord=Coord; |
---|
[114] | 211 | display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters |
---|
[109] | 212 | |
---|
[114] | 213 | % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) |
---|
[109] | 214 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
| 215 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
| 216 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
[114] | 217 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
| 218 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
| 219 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
[109] | 220 | |
---|
[379] | 221 | %% store the calibration data, by default in the xml file of the currently displayed image |
---|
[191] | 222 | UvData=get(huvmat,'UserData'); |
---|
| 223 | NbSlice_j=1;%default |
---|
| 224 | ZStart=Z_plane; |
---|
| 225 | ZEnd=Z_plane; |
---|
[196] | 226 | volume_scan='n'; |
---|
[191] | 227 | if isfield(UvData,'XmlData') |
---|
| 228 | if isfield(UvData.XmlData,'TranslationMotor') |
---|
| 229 | NbSlice_j=UvData.XmlData.TranslationMotor.Nbslice; |
---|
[196] | 230 | ZStart=UvData.XmlData.TranslationMotor.ZStart/10; |
---|
| 231 | ZEnd=UvData.XmlData.TranslationMotor.ZEnd/10; |
---|
| 232 | volume_scan='y'; |
---|
[191] | 233 | end |
---|
| 234 | end |
---|
[2] | 235 | RootPath=''; |
---|
[341] | 236 | % RootFile=''; |
---|
[121] | 237 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile) |
---|
[2] | 238 | RootPath=get(hhuvmat.RootPath,'String'); |
---|
[502] | 239 | SubDirBase=regexprep(get(hhuvmat.SubDir,'String'),'\..+$',''); |
---|
| 240 | outputfile=[fullfile(RootPath,SubDirBase) '.xml'];%xml file associated with the currently displayed image |
---|
[2] | 241 | else |
---|
[502] | 242 | SubDirBase=''; |
---|
[2] | 243 | question={'save the calibration data and point coordinates in'}; |
---|
[121] | 244 | def={fullfile(RootPath,'ObjectCalib.xml')}; |
---|
[2] | 245 | options.Resize='on'; |
---|
| 246 | answer=inputdlg(question,'save average in a new file',1,def,options); |
---|
| 247 | outputfile=answer{1}; |
---|
| 248 | end |
---|
[84] | 249 | answer=msgbox_uvmat('INPUT_Y-N',{[outputfile ' updated with calibration data'];... |
---|
[2] | 250 | ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... |
---|
[84] | 251 | ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']}); |
---|
[128] | 252 | |
---|
| 253 | %% record the calibration parameters and display the current image of uvmat in the new phys coordinates |
---|
[121] | 254 | if strcmp(answer,'Yes') |
---|
| 255 | if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration |
---|
[213] | 256 | input_key={'Z (first position)','Z (last position)','Z (water surface)', 'refractive index','NbSlice','volume scan (y/n)','tilt angle y axis','tilt angle x axis'}; |
---|
| 257 | input_val=[{num2str(ZEnd)} {num2str(ZStart)} {num2str(ZStart)} {'1.333'} num2str(NbSlice_j) {volume_scan} {'0'} {'0'}]; |
---|
| 258 | answer=inputdlg(input_key,'slice position(s)',ones(1,8), input_val,'on'); |
---|
[191] | 259 | %answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); |
---|
| 260 | GeometryCalib.NbSlice=str2double(answer{5}); |
---|
| 261 | GeometryCalib.VolumeScan=answer{6}; |
---|
| 262 | if isempty(answer) |
---|
[121] | 263 | Z_plane=0; %default |
---|
| 264 | else |
---|
[191] | 265 | Z_plane=linspace(str2double(answer{1}),str2double(answer{2}),GeometryCalib.NbSlice); |
---|
| 266 | end |
---|
[196] | 267 | GeometryCalib.SliceCoord=Z_plane'*[0 0 1]; |
---|
[213] | 268 | GeometryCalib.SliceAngle(:,3)=0; |
---|
| 269 | GeometryCalib.SliceAngle(:,2)=str2double(answer{7})*ones(GeometryCalib.NbSlice,1);%rotation around y axis (to generalise) |
---|
| 270 | GeometryCalib.SliceAngle(:,1)=str2double(answer{8})*ones(GeometryCalib.NbSlice,1);%rotation around x axis (to generalise) |
---|
[196] | 271 | GeometryCalib.InterfaceCoord=[0 0 str2double(answer{3})]; |
---|
[207] | 272 | GeometryCalib.RefractionIndex=str2double(answer{4}); |
---|
[121] | 273 | end |
---|
[498] | 274 | UserData=get(handles.geometry_calib,'UserData'); |
---|
[502] | 275 | |
---|
| 276 | % get the timing from the xml file using the old convention if appropriate |
---|
| 277 | if ~exist(outputfile,'file') && ~isempty(SubDirBase) |
---|
| 278 | oldxml=[fullfile(RootPath,SubDirBase,get(hhuvmat.RootFile,'String')) '.xml']; |
---|
| 279 | if exist(oldxml,'file') |
---|
| 280 | [success,message]=copyfile(oldxml,outputfile);%copy the old xml file to a new one with the new convention |
---|
| 281 | end |
---|
| 282 | end |
---|
[114] | 283 | errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file |
---|
| 284 | if ~strcmp(errormsg,'') |
---|
| 285 | msgbox_uvmat('ERROR',errormsg); |
---|
| 286 | end |
---|
[128] | 287 | |
---|
[84] | 288 | %display image with new calibration in the currently opened uvmat interface |
---|
| 289 | hhh=findobj(hhuvmat.axes3,'Tag','calib_marker');% delete calib points and markers |
---|
| 290 | if ~isempty(hhh) |
---|
[109] | 291 | delete(hhh); |
---|
[84] | 292 | end |
---|
| 293 | hhh=findobj(hhuvmat.axes3,'Tag','calib_points'); |
---|
| 294 | if ~isempty(hhh) |
---|
| 295 | delete(hhh); |
---|
| 296 | end |
---|
[332] | 297 | set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' |
---|
| 298 | set(hhuvmat.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
[498] | 299 | |
---|
[116] | 300 | UserData.XmlInputFile=outputfile;%save the current xml file name |
---|
| 301 | set(handles.geometry_calib,'UserData',UserData) |
---|
[114] | 302 | uvmat('RootPath_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat, show the image in phys coordinates |
---|
| 303 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
| 304 | set(handles.ListCoord,'Value',index)% indicate in the list the point with max deviation (possible mistake) |
---|
| 305 | ListCoord_Callback(hObject, eventdata, handles) |
---|
[84] | 306 | figure(handles.geometry_calib) |
---|
[2] | 307 | end |
---|
[69] | 308 | |
---|
| 309 | %------------------------------------------------------------------ |
---|
[2] | 310 | % --- Executes on button press in calibrate_lin. |
---|
[128] | 311 | |
---|
[2] | 312 | function REPLICATE_Callback(hObject, eventdata, handles) |
---|
[60] | 313 | %------------------------------------------------------------------------ |
---|
[2] | 314 | |
---|
[128] | 315 | %% Apply calibration |
---|
| 316 | calib_cell=get(handles.calib_type,'String'); %#ok<NASGU> |
---|
| 317 | val=get(handles.calib_type,'Value'); %#ok<NASGU> |
---|
| 318 | |
---|
[114] | 319 | %read the current calibration points |
---|
| 320 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 321 | Object=read_geometry_calib(Coord_cell); |
---|
| 322 | Coord=Object.Coord; |
---|
[2] | 323 | |
---|
[114] | 324 | % apply the calibration, whose type is selected in handles.calib_type |
---|
| 325 | if ~isempty(Coord) |
---|
| 326 | calib_cell=get(handles.calib_type,'String'); |
---|
| 327 | val=get(handles.calib_type,'Value'); |
---|
| 328 | GeometryCalib=feval(['calib_' calib_cell{val}],Coord,handles); |
---|
| 329 | else |
---|
| 330 | msgbox_uvmat('ERROR','No calibration points, abort') |
---|
| 331 | return |
---|
| 332 | end |
---|
| 333 | |
---|
| 334 | if ~isempty(Coord) |
---|
| 335 | %check error |
---|
| 336 | X=Coord(:,1); |
---|
| 337 | Y=Coord(:,2); |
---|
| 338 | Z=Coord(:,3); |
---|
| 339 | x_ima=Coord(:,4); |
---|
| 340 | y_ima=Coord(:,5); |
---|
| 341 | [Xpoints,Ypoints]=px_XYZ(GeometryCalib,X,Y,Z); |
---|
| 342 | GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
[341] | 343 | [GeometryCalib.ErrorMax(1)]=max(abs(Xpoints-x_ima)); |
---|
[114] | 344 | GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
[341] | 345 | [GeometryCalib.ErrorMax(2)]=max(abs(Ypoints-y_ima)); |
---|
| 346 | % [EM,ind_dim]=max(GeometryCalib.ErrorMax); |
---|
[114] | 347 | %set the Z position of the reference plane used for calibration |
---|
| 348 | Z_plane=[]; |
---|
| 349 | if isequal(max(Z),min(Z)) |
---|
| 350 | Z_plane=Z(1); |
---|
| 351 | end |
---|
| 352 | answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane)); |
---|
[128] | 353 | Z_plane=str2double(answer_1); |
---|
[114] | 354 | GeometryCalib.NbSlice=1; |
---|
| 355 | GeometryCalib.SliceCoord=[0 0 Z_plane]; |
---|
| 356 | %set the coordinate unit |
---|
| 357 | unitlist=get(handles.CoordUnit,'String'); |
---|
| 358 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
| 359 | GeometryCalib.CoordUnit=unit; |
---|
| 360 | %record the points |
---|
| 361 | GeometryCalib.SourceCalib.PointCoord=Coord; |
---|
| 362 | end |
---|
[128] | 363 | |
---|
| 364 | %% display calibration paprameters |
---|
[114] | 365 | display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters |
---|
| 366 | |
---|
| 367 | % Display extrinsinc parameters (rotation and translation of camera with respect to the phys coordiantes) |
---|
| 368 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
| 369 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
| 370 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
| 371 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
| 372 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
| 373 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
| 374 | |
---|
[128] | 375 | %% open the GUI dataview |
---|
[2] | 376 | h_dataview=findobj(allchild(0),'name','dataview'); |
---|
[12] | 377 | if ~isempty(h_dataview) |
---|
| 378 | delete(h_dataview) |
---|
[2] | 379 | end |
---|
[61] | 380 | CalibData=get(handles.geometry_calib,'UserData');%read the calibration image source on the interface userdata |
---|
[341] | 381 | % InputFile=''; |
---|
[114] | 382 | if isfield(CalibData,'XmlInputFile') |
---|
[128] | 383 | InputDir=fileparts(CalibData.XmlInputFile); |
---|
| 384 | [InputDir,DirName]=fileparts(InputDir); |
---|
[2] | 385 | end |
---|
[12] | 386 | SubCampaignTest='n'; %default |
---|
[128] | 387 | testup=0; |
---|
| 388 | if isfield(CalibData,'SubCampaign') |
---|
| 389 | SubCampaignTest='y'; |
---|
| 390 | dir_ref=CalibData.SubCampaign; |
---|
| 391 | testup=1; |
---|
| 392 | elseif isfield(CalibData,'Campaign') |
---|
| 393 | dir_ref=CalibData.Campaign; |
---|
| 394 | testup=1; |
---|
[2] | 395 | end |
---|
[128] | 396 | while testup |
---|
| 397 | [InputDir,DirName]=fileparts(InputDir); |
---|
| 398 | if strcmp(DirName,dir_ref) |
---|
| 399 | break |
---|
[2] | 400 | end |
---|
| 401 | end |
---|
[128] | 402 | InputDir=fullfile(InputDir,DirName); |
---|
| 403 | answer=msgbox_uvmat('INPUT_TXT','Campaign ?',InputDir); |
---|
| 404 | if strcmp(answer,'Cancel') |
---|
| 405 | return |
---|
[2] | 406 | end |
---|
| 407 | |
---|
[128] | 408 | dataview(answer,SubCampaignTest,GeometryCalib); |
---|
| 409 | |
---|
[60] | 410 | %------------------------------------------------------------------------ |
---|
[2] | 411 | % determine the parameters for a calibration by an affine function (rescaling and offset, no rotation) |
---|
[109] | 412 | function GeometryCalib=calib_rescale(Coord,handles) |
---|
[60] | 413 | %------------------------------------------------------------------------ |
---|
[2] | 414 | X=Coord(:,1); |
---|
[109] | 415 | Y=Coord(:,2);% Z not used |
---|
[2] | 416 | x_ima=Coord(:,4); |
---|
| 417 | y_ima=Coord(:,5); |
---|
[341] | 418 | [px]=polyfit(X,x_ima,1); |
---|
| 419 | [py]=polyfit(Y,y_ima,1); |
---|
| 420 | % T_x=px(2); |
---|
| 421 | % T_y=py(2); |
---|
[2] | 422 | GeometryCalib.CalibrationType='rescale'; |
---|
[121] | 423 | GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y |
---|
[2] | 424 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
[114] | 425 | GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1]; |
---|
| 426 | GeometryCalib.omc=[0 0 0]; |
---|
[2] | 427 | |
---|
[60] | 428 | %------------------------------------------------------------------------ |
---|
[2] | 429 | % determine the parameters for a calibration by a linear transform matrix (rescale and rotation) |
---|
[242] | 430 | |
---|
| 431 | |
---|
[227] | 432 | function GeometryCalib=calib_linear(Coord,handles) |
---|
[60] | 433 | %------------------------------------------------------------------------ |
---|
[2] | 434 | X=Coord(:,1); |
---|
[109] | 435 | Y=Coord(:,2);% Z not used |
---|
[2] | 436 | x_ima=Coord(:,4); |
---|
| 437 | y_ima=Coord(:,5); |
---|
| 438 | XY_mat=[ones(size(X)) X Y]; |
---|
| 439 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
| 440 | a_Y1=XY_mat\y_ima;%transformation matrix for X |
---|
[121] | 441 | R=[a_X1(2),a_X1(3);a_Y1(2),a_Y1(3)]; |
---|
[242] | 442 | epsilon=sign(det(R)); |
---|
[116] | 443 | norm=abs(det(R)); |
---|
[2] | 444 | GeometryCalib.CalibrationType='linear'; |
---|
[238] | 445 | if (a_X1(2)/a_Y1(3))>0 |
---|
[242] | 446 | GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm); |
---|
[238] | 447 | else |
---|
[242] | 448 | GeometryCalib.fx_fy(1)=-sqrt(-(a_X1(2)/a_Y1(3))*norm); |
---|
[238] | 449 | end |
---|
[121] | 450 | GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1); |
---|
[2] | 451 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
[227] | 452 | GeometryCalib.Tx_Ty_Tz=[a_X1(1)/GeometryCalib.fx_fy(1) a_Y1(1)/GeometryCalib.fx_fy(2) 1]; |
---|
[242] | 453 | R(1,:)=R(1,:)/GeometryCalib.fx_fy(1); |
---|
[121] | 454 | R(2,:)=R(2,:)/GeometryCalib.fx_fy(2); |
---|
| 455 | R=[R;[0 0]]; |
---|
[242] | 456 | GeometryCalib.R=[R [0;0;-epsilon]]; |
---|
| 457 | GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0]; |
---|
[109] | 458 | %------------------------------------------------------------------------ |
---|
| 459 | % determine the tsai parameters for a view normal to the grid plane |
---|
[114] | 460 | % NOT USED |
---|
[109] | 461 | function GeometryCalib=calib_normal(Coord,handles) |
---|
| 462 | %------------------------------------------------------------------------ |
---|
| 463 | Calib.f1=str2num(get(handles.fx,'String')); |
---|
| 464 | Calib.f2=str2num(get(handles.fy,'String')); |
---|
[114] | 465 | Calib.k=str2num(get(handles.kc,'String')); |
---|
[109] | 466 | Calib.Cx=str2num(get(handles.Cx,'String')); |
---|
| 467 | Calib.Cy=str2num(get(handles.Cy,'String')); |
---|
| 468 | %default |
---|
| 469 | if isempty(Calib.f1) |
---|
| 470 | Calib.f1=25/0.012; |
---|
| 471 | end |
---|
| 472 | if isempty(Calib.f2) |
---|
| 473 | Calib.f2=25/0.012; |
---|
| 474 | end |
---|
| 475 | if isempty(Calib.k) |
---|
| 476 | Calib.k=0; |
---|
| 477 | end |
---|
| 478 | if isempty(Calib.Cx)||isempty(Calib.Cy) |
---|
| 479 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
| 480 | hhuvmat=guidata(huvmat); |
---|
[332] | 481 | Calib.Cx=str2num(get(hhuvmat.num_Npx,'String'))/2; |
---|
| 482 | Calib.Cx=str2num(get(hhuvmat.num_Npy,'String'))/2; |
---|
[109] | 483 | end |
---|
| 484 | %tsai parameters |
---|
| 485 | Calib.dpx=0.012;%arbitrary |
---|
| 486 | Calib.dpy=0.012; |
---|
| 487 | Calib.sx=Calib.f1*Calib.dpx/(Calib.f2*Calib.dpy); |
---|
| 488 | Calib.f=Calib.f2*Calib.dpy; |
---|
| 489 | Calib.kappa1=Calib.k/(Calib.f*Calib.f); |
---|
[2] | 490 | |
---|
[109] | 491 | %initial guess |
---|
| 492 | X=Coord(:,1); |
---|
| 493 | Y=Coord(:,2); |
---|
| 494 | Zmean=mean(Coord(:,3)); |
---|
| 495 | x_ima=Coord(:,4)-Calib.Cx; |
---|
| 496 | y_ima=Coord(:,5)-Calib.Cy; |
---|
| 497 | XY_mat=[ones(size(X)) X Y]; |
---|
| 498 | a_X1=XY_mat\x_ima; %transformation matrix for X |
---|
| 499 | a_Y1=XY_mat\y_ima;%transformation matrix for Y |
---|
| 500 | R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,-1];% rotation+ z axis reversal (upward) |
---|
| 501 | norm=sqrt(det(-R)); |
---|
| 502 | calib_param(1)=0;% quadratic distortion |
---|
| 503 | calib_param(2)=a_X1(1); |
---|
| 504 | calib_param(3)=a_Y1(1); |
---|
| 505 | calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean; |
---|
[121] | 506 | calib_param(5)=angle(a_X1(2)+1i*a_X1(3)); |
---|
[109] | 507 | display(['initial guess=' num2str(calib_param)]) |
---|
| 508 | |
---|
| 509 | %optimise the parameters: minimisation of error |
---|
[121] | 510 | calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param); |
---|
[109] | 511 | |
---|
| 512 | GeometryCalib.CalibrationType='tsai_normal'; |
---|
| 513 | GeometryCalib.focal=Calib.f; |
---|
| 514 | GeometryCalib.dpx_dpy=[Calib.dpx Calib.dpy]; |
---|
| 515 | GeometryCalib.Cx_Cy=[Calib.Cx Calib.Cy]; |
---|
| 516 | GeometryCalib.sx=Calib.sx; |
---|
| 517 | GeometryCalib.kappa1=calib_param(1); |
---|
| 518 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
| 519 | GeometryCalib.Tx_Ty_Tz=[calib_param(2) calib_param(3) calib_param(4)]; |
---|
| 520 | alpha=calib_param(5); |
---|
| 521 | GeometryCalib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1]; |
---|
| 522 | |
---|
[60] | 523 | %------------------------------------------------------------------------ |
---|
[109] | 524 | function GeometryCalib=calib_3D_linear(Coord,handles) |
---|
[69] | 525 | %------------------------------------------------------------------ |
---|
| 526 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
| 527 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
[78] | 528 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
| 529 | hhuvmat=guidata(huvmat); |
---|
[121] | 530 | coord_files=get(handles.coord_files,'String'); |
---|
| 531 | if ischar(coord_files) |
---|
| 532 | coord_files={coord_files}; |
---|
| 533 | end |
---|
| 534 | if isempty(coord_files{1}) || isequal(coord_files,{''}) |
---|
| 535 | coord_files={}; |
---|
| 536 | end |
---|
| 537 | %retrieve the calibration points stored in the files listed in the popup list coord_files |
---|
| 538 | x_1=Coord(:,4:5)';%px coordinates of the ref points |
---|
[332] | 539 | nx=str2num(get(hhuvmat.num_Npx,'String')); |
---|
| 540 | ny=str2num(get(hhuvmat.num_Npy,'String')); |
---|
[121] | 541 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
| 542 | X_1=Coord(:,1:3)';%phys coordinates of the ref points |
---|
| 543 | n_ima=numel(coord_files)+1; |
---|
| 544 | if ~isempty(coord_files) |
---|
| 545 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used']) |
---|
| 546 | for ifile=1:numel(coord_files) |
---|
| 547 | t=xmltree(coord_files{ifile}); |
---|
| 548 | s=convert(t);%convert to matlab structure |
---|
| 549 | if isfield(s,'GeometryCalib') |
---|
| 550 | if isfield(s.GeometryCalib,'SourceCalib') |
---|
| 551 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord') |
---|
| 552 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord; |
---|
| 553 | Coord_file=zeros(length(PointCoord),5);%default |
---|
| 554 | for i=1:length(PointCoord) |
---|
| 555 | line=str2num(PointCoord{i}); |
---|
| 556 | Coord_file(i,4:5)=line(4:5);%px x |
---|
| 557 | Coord_file(i,1:3)=line(1:3);%phys x |
---|
| 558 | end |
---|
| 559 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); |
---|
| 560 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]); |
---|
| 561 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); |
---|
| 562 | end |
---|
| 563 | end |
---|
| 564 | end |
---|
| 565 | end |
---|
| 566 | end |
---|
| 567 | n_ima=numel(coord_files)+1; |
---|
[109] | 568 | est_dist=[0;0;0;0;0]; |
---|
| 569 | est_aspect_ratio=0; |
---|
| 570 | est_fc=[1;1]; |
---|
| 571 | %fc=[25;25]/0.012; |
---|
| 572 | center_optim=0; |
---|
| 573 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); |
---|
| 574 | GeometryCalib.CalibrationType='3D_linear'; |
---|
[121] | 575 | GeometryCalib.fx_fy=fc'; |
---|
| 576 | %GeometryCalib.focal=fc(2); |
---|
| 577 | %GeometryCalib.dpx_dpy=[1 1]; |
---|
[109] | 578 | GeometryCalib.Cx_Cy=cc'; |
---|
[121] | 579 | %GeometryCalib.sx=fc(1)/fc(2); |
---|
| 580 | GeometryCalib.kc=kc(1); |
---|
| 581 | %GeometryCalib.kappa1=-kc(1)/fc(2)^2; |
---|
[109] | 582 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
| 583 | GeometryCalib.Tx_Ty_Tz=Tc_1'; |
---|
| 584 | GeometryCalib.R=Rc_1; |
---|
[121] | 585 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
| 586 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
| 587 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
| 588 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees |
---|
| 589 | GeometryCalib.ErrorRMS=[]; |
---|
| 590 | GeometryCalib.ErrorMax=[]; |
---|
[109] | 591 | |
---|
| 592 | %------------------------------------------------------------------------ |
---|
| 593 | function GeometryCalib=calib_3D_quadr(Coord,handles) |
---|
| 594 | %------------------------------------------------------------------ |
---|
| 595 | |
---|
| 596 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
| 597 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
| 598 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
| 599 | hhuvmat=guidata(huvmat); |
---|
| 600 | % check_cond=0; |
---|
| 601 | coord_files=get(handles.coord_files,'String'); |
---|
| 602 | if ischar(coord_files) |
---|
| 603 | coord_files={coord_files}; |
---|
| 604 | end |
---|
| 605 | if isempty(coord_files{1}) || isequal(coord_files,{''}) |
---|
| 606 | coord_files={}; |
---|
| 607 | end |
---|
| 608 | |
---|
| 609 | %retrieve the calibration points stored in the files listed in the popup list coord_files |
---|
[114] | 610 | x_1=Coord(:,4:5)';%px coordinates of the ref points |
---|
[332] | 611 | nx=str2num(get(hhuvmat.num_Npx,'String')); |
---|
| 612 | ny=str2num(get(hhuvmat.num_Npy,'String')); |
---|
[114] | 613 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
| 614 | X_1=Coord(:,1:3)';%phys coordinates of the ref points |
---|
[109] | 615 | n_ima=numel(coord_files)+1; |
---|
| 616 | if ~isempty(coord_files) |
---|
| 617 | msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used']) |
---|
| 618 | for ifile=1:numel(coord_files) |
---|
| 619 | t=xmltree(coord_files{ifile}); |
---|
| 620 | s=convert(t);%convert to matlab structure |
---|
| 621 | if isfield(s,'GeometryCalib') |
---|
| 622 | if isfield(s.GeometryCalib,'SourceCalib') |
---|
| 623 | if isfield(s.GeometryCalib.SourceCalib,'PointCoord') |
---|
| 624 | PointCoord=s.GeometryCalib.SourceCalib.PointCoord; |
---|
[121] | 625 | Coord_file=zeros(length(PointCoord),5);%default |
---|
[109] | 626 | for i=1:length(PointCoord) |
---|
| 627 | line=str2num(PointCoord{i}); |
---|
| 628 | Coord_file(i,4:5)=line(4:5);%px x |
---|
| 629 | Coord_file(i,1:3)=line(1:3);%phys x |
---|
| 630 | end |
---|
| 631 | eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']); |
---|
[114] | 632 | eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]); |
---|
[109] | 633 | eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']); |
---|
| 634 | end |
---|
| 635 | end |
---|
| 636 | end |
---|
| 637 | end |
---|
| 638 | end |
---|
| 639 | n_ima=numel(coord_files)+1; |
---|
[108] | 640 | est_dist=[1;0;0;0;0]; |
---|
[109] | 641 | est_aspect_ratio=1; |
---|
| 642 | %est_fc=[0;0]; |
---|
| 643 | %fc=[25;25]/0.012; |
---|
| 644 | center_optim=0; |
---|
[83] | 645 | run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim')); |
---|
[69] | 646 | |
---|
[109] | 647 | GeometryCalib.CalibrationType='3D_quadr'; |
---|
[114] | 648 | GeometryCalib.fx_fy=fc'; |
---|
| 649 | %GeometryCalib.focal=fc(2); |
---|
| 650 | %GeometryCalib.dpx_dpy=[1 1]; |
---|
[69] | 651 | GeometryCalib.Cx_Cy=cc'; |
---|
[114] | 652 | %GeometryCalib.sx=fc(1)/fc(2); |
---|
| 653 | GeometryCalib.kc=kc(1); |
---|
| 654 | %GeometryCalib.kappa1=-kc(1)/fc(2)^2; |
---|
[69] | 655 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
| 656 | GeometryCalib.Tx_Ty_Tz=Tc_1'; |
---|
| 657 | GeometryCalib.R=Rc_1; |
---|
[114] | 658 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
| 659 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
| 660 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
| 661 | GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees |
---|
[109] | 662 | GeometryCalib.ErrorRMS=[]; |
---|
| 663 | GeometryCalib.ErrorMax=[]; |
---|
[69] | 664 | |
---|
[109] | 665 | |
---|
[60] | 666 | %------------------------------------------------------------------------ |
---|
[109] | 667 | function GeometryCalib=calib_3D_extrinsic(Coord,handles) |
---|
| 668 | %------------------------------------------------------------------ |
---|
| 669 | path_uvmat=which('geometry_calib');% check the path detected for source file uvmat |
---|
| 670 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
[116] | 671 | x_1=double(Coord(:,4:5)');%image coordiantes |
---|
| 672 | X_1=double(Coord(:,1:3)');% phys coordinates |
---|
[114] | 673 | huvmat=findobj(allchild(0),'Tag','uvmat'); |
---|
| 674 | hhuvmat=guidata(huvmat); |
---|
[332] | 675 | ny=str2double(get(hhuvmat.num_Npy,'String')); |
---|
[114] | 676 | x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates |
---|
[109] | 677 | n_ima=1; |
---|
[114] | 678 | GeometryCalib.CalibrationType='3D_extrinsic'; |
---|
| 679 | GeometryCalib.fx_fy(1)=str2num(get(handles.fx,'String')); |
---|
| 680 | GeometryCalib.fx_fy(2)=str2num(get(handles.fy,'String')); |
---|
| 681 | GeometryCalib.Cx_Cy(1)=str2num(get(handles.Cx,'String')); |
---|
| 682 | GeometryCalib.Cx_Cy(2)=str2num(get(handles.Cy,'String')); |
---|
| 683 | GeometryCalib.kc=str2num(get(handles.kc,'String')); |
---|
[109] | 684 | fct_path=fullfile(path_UVMAT,'toolbox_calib'); |
---|
| 685 | addpath(fct_path) |
---|
[116] | 686 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%reverse Cx_Cy(2) for calibration (inversion of px ordinate) |
---|
[109] | 687 | % [omc1,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... |
---|
| 688 | % [Calib.f Calib.f*Calib.sx]',... |
---|
| 689 | % [Calib.Cx Calib.Cy]',... |
---|
| 690 | % [-Calib.kappa1*Calib.f^2 0 0 0 0]); |
---|
[114] | 691 | [omc,Tc1,Rc1,H,x,ex,JJ] = compute_extrinsic(x_1,X_1,... |
---|
[116] | 692 | (GeometryCalib.fx_fy)',GeometryCalib.Cx_Cy',[GeometryCalib.kc 0 0 0 0]); |
---|
[109] | 693 | rmpath(fct_path); |
---|
| 694 | GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function |
---|
| 695 | GeometryCalib.Tx_Ty_Tz=Tc1'; |
---|
| 696 | %inversion of z axis |
---|
| 697 | GeometryCalib.R=Rc1; |
---|
[114] | 698 | GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate |
---|
| 699 | GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate |
---|
[116] | 700 | GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate |
---|
[114] | 701 | GeometryCalib.omc=(180/pi)*omc'; |
---|
[109] | 702 | %GeometryCalib.R(3,1:3)=-GeometryCalib.R(3,1:3);%inversion for z upward |
---|
| 703 | |
---|
| 704 | |
---|
[116] | 705 | |
---|
[109] | 706 | %------------------------------------------------------------------------ |
---|
| 707 | %function GeometryCalib=calib_tsai_heikkila(Coord) |
---|
| 708 | % TEST: NOT IMPLEMENTED |
---|
| 709 | %------------------------------------------------------------------ |
---|
| 710 | % path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
| 711 | % path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
| 712 | % path_calib=fullfile(path_UVMAT,'toolbox_calib_heikkila'); |
---|
| 713 | % addpath(path_calib) |
---|
| 714 | % npoints=size(Coord,1); |
---|
| 715 | % Coord(:,1:3)=10*Coord(:,1:3); |
---|
| 716 | % Coord=[Coord zeros(npoints,2) -ones(npoints,1)]; |
---|
| 717 | % [par,pos,iter,res,er,C]=cacal('dalsa',Coord); |
---|
| 718 | % GeometryCalib.CalibrationType='tsai'; |
---|
| 719 | % GeometryCalib.focal=par(2); |
---|
| 720 | |
---|
| 721 | |
---|
| 722 | %------------------------------------------------------------------------ |
---|
| 723 | % --- determine the rms of calibration error |
---|
| 724 | function ErrorRms=error_calib(calib_param,Calib,Coord) |
---|
| 725 | %calib_param: vector of free calibration parameters (to optimise) |
---|
| 726 | %Calib: structure of the given calibration parameters |
---|
| 727 | %Coord: list of phys coordinates (columns 1-3, and pixel coordinates (columns 4-5) |
---|
| 728 | Calib.f=25; |
---|
| 729 | Calib.dpx=0.012; |
---|
| 730 | Calib.dpy=0.012; |
---|
| 731 | Calib.sx=1; |
---|
| 732 | Calib.Cx=512; |
---|
| 733 | Calib.Cy=512; |
---|
| 734 | Calib.kappa1=calib_param(1); |
---|
| 735 | Calib.Tx=calib_param(2); |
---|
| 736 | Calib.Ty=calib_param(3); |
---|
| 737 | Calib.Tz=calib_param(4); |
---|
| 738 | alpha=calib_param(5); |
---|
| 739 | Calib.R=[cos(alpha) sin(alpha) 0;-sin(alpha) cos(alpha) 0;0 0 -1]; |
---|
[2] | 740 | |
---|
[109] | 741 | X=Coord(:,1); |
---|
| 742 | Y=Coord(:,2); |
---|
| 743 | Z=Coord(:,3); |
---|
| 744 | x_ima=Coord(:,4); |
---|
| 745 | y_ima=Coord(:,5); |
---|
| 746 | [Xpoints,Ypoints]=px_XYZ(Calib,X,Y,Z); |
---|
| 747 | ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima))); |
---|
| 748 | ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima))); |
---|
| 749 | ErrorRms=mean(ErrorRms); |
---|
| 750 | |
---|
[60] | 751 | %------------------------------------------------------------------------ |
---|
[2] | 752 | function XImage_Callback(hObject, eventdata, handles) |
---|
[60] | 753 | %------------------------------------------------------------------------ |
---|
[2] | 754 | update_list(hObject, eventdata,handles) |
---|
| 755 | |
---|
[60] | 756 | %------------------------------------------------------------------------ |
---|
[2] | 757 | function YImage_Callback(hObject, eventdata, handles) |
---|
[60] | 758 | %------------------------------------------------------------------------ |
---|
[2] | 759 | update_list(hObject, eventdata,handles) |
---|
| 760 | |
---|
[109] | 761 | %------------------------------------------------------------------------ |
---|
| 762 | % --- Executes on button press in STORE. |
---|
| 763 | function STORE_Callback(hObject, eventdata, handles) |
---|
| 764 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 765 | Object=read_geometry_calib(Coord_cell); |
---|
| 766 | unitlist=get(handles.CoordUnit,'String'); |
---|
| 767 | unit=unitlist{get(handles.CoordUnit,'value')}; |
---|
| 768 | GeometryCalib.CoordUnit=unit; |
---|
| 769 | GeometryCalib.SourceCalib.PointCoord=Object.Coord; |
---|
| 770 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
| 771 | hhuvmat=guidata(huvmat);%handles of elements in the GUI uvmat |
---|
[128] | 772 | % RootPath=''; |
---|
| 773 | % RootFile=''; |
---|
[121] | 774 | if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile) |
---|
[341] | 775 | % testhandle=1; |
---|
[109] | 776 | RootPath=get(hhuvmat.RootPath,'String'); |
---|
| 777 | RootFile=get(hhuvmat.RootFile,'String'); |
---|
| 778 | filebase=fullfile(RootPath,RootFile); |
---|
| 779 | while exist([filebase '.xml'],'file') |
---|
| 780 | filebase=[filebase '~']; |
---|
| 781 | end |
---|
| 782 | outputfile=[filebase '.xml']; |
---|
[114] | 783 | errormsg=update_imadoc(GeometryCalib,outputfile); |
---|
| 784 | if ~strcmp(errormsg,'') |
---|
| 785 | msgbox_uvmat('ERROR',errormsg); |
---|
| 786 | end |
---|
[109] | 787 | listfile=get(handles.coord_files,'string'); |
---|
| 788 | if isequal(listfile,{''}) |
---|
| 789 | listfile={outputfile}; |
---|
| 790 | else |
---|
[128] | 791 | listfile=[listfile;{outputfile}];%update the list of coord files |
---|
[109] | 792 | end |
---|
| 793 | set(handles.coord_files,'string',listfile); |
---|
| 794 | end |
---|
| 795 | set(handles.ListCoord,'Value',1)% refresh the display of coordinates |
---|
| 796 | set(handles.ListCoord,'String',{'......'}) |
---|
| 797 | |
---|
[114] | 798 | % -------------------------------------------------------------------- |
---|
| 799 | % --- Executes on button press in CLEAR_PTS: clear the list of calibration points |
---|
| 800 | function CLEAR_PTS_Callback(hObject, eventdata, handles) |
---|
| 801 | % -------------------------------------------------------------------- |
---|
| 802 | set(handles.ListCoord,'Value',1)% refresh the display of coordinates |
---|
| 803 | set(handles.ListCoord,'String',{'......'}) |
---|
| 804 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
| 805 | |
---|
[109] | 806 | %------------------------------------------------------------------------ |
---|
| 807 | % --- Executes on button press in CLEAR. |
---|
| 808 | function CLEAR_Callback(hObject, eventdata, handles) |
---|
| 809 | %------------------------------------------------------------------------ |
---|
| 810 | set(handles.coord_files,'Value',1) |
---|
| 811 | set(handles.coord_files,'String',{''}) |
---|
| 812 | |
---|
| 813 | %------------------------------------------------------------------------ |
---|
[2] | 814 | function XObject_Callback(hObject, eventdata, handles) |
---|
[109] | 815 | %------------------------------------------------------------------------ |
---|
[2] | 816 | update_list(hObject, eventdata,handles) |
---|
| 817 | |
---|
[109] | 818 | %------------------------------------------------------------------------ |
---|
[2] | 819 | function YObject_Callback(hObject, eventdata, handles) |
---|
[109] | 820 | %------------------------------------------------------------------------ |
---|
[2] | 821 | update_list(hObject, eventdata,handles) |
---|
| 822 | |
---|
[109] | 823 | %------------------------------------------------------------------------ |
---|
[2] | 824 | function ZObject_Callback(hObject, eventdata, handles) |
---|
[109] | 825 | %------------------------------------------------------------------------ |
---|
[2] | 826 | update_list(hObject, eventdata,handles) |
---|
| 827 | |
---|
[60] | 828 | %------------------------------------------------------------------------ |
---|
[2] | 829 | function update_list(hObject, eventdata, handles) |
---|
[60] | 830 | %------------------------------------------------------------------------ |
---|
[149] | 831 | newval(4)=str2double(get(handles.XImage,'String')); |
---|
| 832 | newval(5)=str2double(get(handles.YImage,'String')); |
---|
| 833 | newval(1)=str2double(get(handles.XObject,'String')); |
---|
| 834 | newval(2)=str2double(get(handles.YObject,'String')); |
---|
| 835 | newval(3)=str2double(get(handles.ZObject,'String')); |
---|
| 836 | if isnan(newval(3)) |
---|
| 837 | newval(3)=0;%put z to 0 by default |
---|
[2] | 838 | end |
---|
| 839 | Coord=get(handles.ListCoord,'String'); |
---|
[149] | 840 | Coord(end)=[]; %remove last string '.....' |
---|
[2] | 841 | val=get(handles.ListCoord,'Value'); |
---|
[149] | 842 | data=read_geometry_calib(Coord); |
---|
| 843 | data.Coord(val,:)=newval; |
---|
| 844 | for i=1:size(data.Coord,1) |
---|
| 845 | for j=1:5 |
---|
| 846 | Coord_cell{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
| 847 | end |
---|
| 848 | end |
---|
| 849 | |
---|
| 850 | Tabchar=cell2tab(Coord_cell,' | '); |
---|
| 851 | Tabchar=[Tabchar ;{'......'}]; |
---|
| 852 | set(handles.ListCoord,'String',Tabchar) |
---|
| 853 | |
---|
[60] | 854 | %update the plot |
---|
| 855 | ListCoord_Callback(hObject, eventdata, handles) |
---|
[67] | 856 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
[71] | 857 | |
---|
[60] | 858 | %------------------------------------------------------------------------ |
---|
[2] | 859 | % --- Executes on selection change in ListCoord. |
---|
| 860 | function ListCoord_Callback(hObject, eventdata, handles) |
---|
[60] | 861 | %------------------------------------------------------------------------ |
---|
[71] | 862 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
| 863 | hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
| 864 | hhh=findobj(hplot,'Tag','calib_marker'); |
---|
[2] | 865 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 866 | val=get(handles.ListCoord,'Value'); |
---|
[78] | 867 | if numel(val)>1 |
---|
| 868 | return %no action if several lines have been selected |
---|
| 869 | end |
---|
[71] | 870 | coord_str=Coord_cell{val}; |
---|
[128] | 871 | k=findstr(' | ',coord_str); |
---|
[71] | 872 | if isempty(k)%last line '.....' selected |
---|
| 873 | if ~isempty(hhh) |
---|
| 874 | delete(hhh)%delete the circle marker |
---|
[2] | 875 | end |
---|
[71] | 876 | return |
---|
| 877 | end |
---|
| 878 | %fill the edit boxex |
---|
[149] | 879 | set(handles.XObject,'String',coord_str(1:k(1)-1)) |
---|
| 880 | set(handles.YObject,'String',coord_str(k(1)+3:k(2)-1)) |
---|
| 881 | set(handles.ZObject,'String',coord_str(k(2)+3:k(3)-1)) |
---|
| 882 | set(handles.XImage,'String',coord_str(k(3)+3:k(4)-1)) |
---|
| 883 | set(handles.YImage,'String',coord_str(k(4)+3:end)) |
---|
[71] | 884 | h_menu_coord=findobj(huvmat,'Tag','transform_fct'); |
---|
| 885 | menu=get(h_menu_coord,'String'); |
---|
| 886 | choice=get(h_menu_coord,'Value'); |
---|
| 887 | if iscell(menu) |
---|
| 888 | option=menu{choice}; |
---|
| 889 | else |
---|
| 890 | option='px'; %default |
---|
| 891 | end |
---|
| 892 | if isequal(option,'phys') |
---|
[149] | 893 | XCoord=str2double(coord_str(1:k(1)-1)); |
---|
| 894 | YCoord=str2double(coord_str(k(1)+3:k(2)-1)); |
---|
[71] | 895 | elseif isequal(option,'px')|| isequal(option,'') |
---|
[149] | 896 | XCoord=str2double(coord_str(k(3)+3:k(4)-1)); |
---|
| 897 | YCoord=str2double(coord_str(k(4)+3:end)); |
---|
[71] | 898 | else |
---|
| 899 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be px or phys ') |
---|
| 900 | end |
---|
| 901 | if isempty(XCoord)||isempty(YCoord) |
---|
| 902 | if ~isempty(hhh) |
---|
| 903 | delete(hhh)%delete the circle marker |
---|
[2] | 904 | end |
---|
[71] | 905 | return |
---|
[2] | 906 | end |
---|
[71] | 907 | xlim=get(hplot,'XLim'); |
---|
| 908 | ylim=get(hplot,'YLim'); |
---|
| 909 | ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/20;%defines the size of the circle marker |
---|
| 910 | if isempty(hhh) |
---|
[149] | 911 | set(0,'CurrentFig',huvmat) |
---|
| 912 | set(huvmat,'CurrentAxes',hplot) |
---|
[71] | 913 | rectangle('Curvature',[1 1],... |
---|
| 914 | 'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
| 915 | 'LineStyle','-','Tag','calib_marker'); |
---|
| 916 | else |
---|
| 917 | set(hhh,'Position',[XCoord-ind_range/2 YCoord-ind_range/2 ind_range ind_range]) |
---|
| 918 | end |
---|
[2] | 919 | |
---|
[60] | 920 | %------------------------------------------------------------------------ |
---|
[2] | 921 | % --- Executes on selection change in edit_append. |
---|
| 922 | function edit_append_Callback(hObject, eventdata, handles) |
---|
[60] | 923 | %------------------------------------------------------------------------ |
---|
[2] | 924 | choice=get(handles.edit_append,'Value'); |
---|
[78] | 925 | if choice |
---|
| 926 | set(handles.edit_append,'BackgroundColor',[1 1 0]) |
---|
[177] | 927 | huvmat=findobj(allchild(0),'tag','uvmat'); |
---|
| 928 | if ishandle(huvmat) |
---|
| 929 | hhuvmat=guidata(huvmat); |
---|
| 930 | set(hhuvmat.edit_object,'Value',0) |
---|
| 931 | set(hhuvmat.edit_object,'BackgroundColor',[0.7 0.7 0.7]) |
---|
| 932 | end |
---|
[78] | 933 | else |
---|
| 934 | set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
[2] | 935 | end |
---|
| 936 | |
---|
| 937 | function NEW_Callback(hObject, eventdata, handles) |
---|
| 938 | %A METTRE SOUS UN BOUTON |
---|
| 939 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
| 940 | hchild=get(huvmat,'children'); |
---|
| 941 | hcoord=findobj(hchild,'Tag','menu_coord'); |
---|
| 942 | coordtype=get(hcoord,'Value'); |
---|
| 943 | haxes=findobj(hchild,'Tag','axes3'); |
---|
| 944 | AxeData=get(haxes,'UserData'); |
---|
| 945 | if ~isequal(hcoord,2) |
---|
| 946 | set(hcoord,'Value',2) |
---|
| 947 | huvmat=uvmat(AxeData); |
---|
| 948 | 'relancer uvmat'; |
---|
| 949 | end |
---|
| 950 | if ~isfield(AxeData,'ZoomAxes') |
---|
[42] | 951 | msgbox_uvmat('ERROR','first draw a window around a grid marker') |
---|
[2] | 952 | return |
---|
| 953 | end |
---|
| 954 | XLim=get(AxeData.ZoomAxes,'XLim'); |
---|
| 955 | YLim=get(AxeData.ZoomAxes,'YLim'); |
---|
| 956 | np=size(AxeData.A); |
---|
| 957 | ind_sub_x=round(XLim); |
---|
| 958 | ind_sub_y=np(1)-round(YLim); |
---|
[227] | 959 | Mfiltre=AxeData.A(ind_sub_y(2):ind_sub_y(1) ,ind_sub_x,:); |
---|
[2] | 960 | Mfiltre_norm=double(Mfiltre); |
---|
| 961 | Mfiltre_norm=Mfiltre_norm/sum(sum(Mfiltre_norm)); |
---|
| 962 | Mfiltre_norm=100*(Mfiltre_norm-mean(mean(Mfiltre_norm))); |
---|
| 963 | Atype=class(AxeData.A); |
---|
| 964 | Data.NbDim=2; |
---|
| 965 | Data.A=filter2(Mfiltre_norm,double(AxeData.A)); |
---|
| 966 | Data.A=feval(Atype,Data.A); |
---|
| 967 | Data.AName='image'; |
---|
| 968 | Data.AX=AxeData.AX; |
---|
| 969 | Data.AY=AxeData.AY; |
---|
| 970 | Data.CoordType='px'; |
---|
| 971 | plot_field(Data) |
---|
| 972 | |
---|
[60] | 973 | %------------------------------------------------------------------------ |
---|
[2] | 974 | function MenuPlot_Callback(hObject, eventdata, handles) |
---|
[60] | 975 | %------------------------------------------------------------------------ |
---|
[2] | 976 | huvmat=findobj(allchild(0),'Name','uvmat');%find the current uvmat interface handle |
---|
[128] | 977 | %UvData=get(huvmat,'UserData');%Data associated to the current uvmat interface |
---|
[2] | 978 | hhuvmat=guidata(huvmat); %handles of GUI elements in uvmat |
---|
[128] | 979 | %hplot=findobj(huvmat,'Tag','axes3');%main plotting axis of uvmat |
---|
[60] | 980 | h_menu_coord=findobj(huvmat,'Tag','transform_fct'); |
---|
[2] | 981 | menu=get(h_menu_coord,'String'); |
---|
| 982 | choice=get(h_menu_coord,'Value'); |
---|
| 983 | if iscell(menu) |
---|
| 984 | option=menu{choice}; |
---|
| 985 | else |
---|
| 986 | option='px'; %default |
---|
| 987 | end |
---|
| 988 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 989 | ObjectData=read_geometry_calib(Coord_cell); |
---|
| 990 | %ObjectData=read_geometry_calib(handles);%read the interface input parameters defining the object |
---|
[71] | 991 | if ~isempty(ObjectData.Coord) |
---|
| 992 | if isequal(option,'phys') |
---|
[227] | 993 | ObjectData.Coord=ObjectData.Coord(:,1:3); |
---|
[71] | 994 | elseif isequal(option,'px')||isequal(option,'') |
---|
[227] | 995 | ObjectData.Coord=ObjectData.Coord(:,4:5); |
---|
[71] | 996 | else |
---|
| 997 | msgbox_uvmat('ERROR','the choice in menu_coord of uvmat must be '''', px or phys ') |
---|
| 998 | end |
---|
[2] | 999 | end |
---|
[231] | 1000 | %axes(hhuvmat.axes3) |
---|
| 1001 | set(0,'CurrentFigure',huvmat) |
---|
[517] | 1002 | set(huvmat,'CurrentAxes',hhuvmat.PlotAxes) |
---|
[2] | 1003 | hh=findobj('Tag','calib_points'); |
---|
[71] | 1004 | if ~isempty(ObjectData.Coord) && isempty(hh) |
---|
[2] | 1005 | hh=line(ObjectData.Coord(:,1),ObjectData.Coord(:,2),'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
[71] | 1006 | elseif isempty(ObjectData.Coord)%empty list of points, suppress the plot |
---|
| 1007 | delete(hh) |
---|
[2] | 1008 | else |
---|
| 1009 | set(hh,'XData',ObjectData.Coord(:,1)) |
---|
| 1010 | set(hh,'YData',ObjectData.Coord(:,2)) |
---|
| 1011 | end |
---|
[61] | 1012 | pause(.1) |
---|
| 1013 | figure(handles.geometry_calib) |
---|
[2] | 1014 | |
---|
| 1015 | % -------------------------------------------------------------------- |
---|
| 1016 | function MenuHelp_Callback(hObject, eventdata, handles) |
---|
[116] | 1017 | path_to_uvmat=which('uvmat');% check the path of uvmat |
---|
[2] | 1018 | pathelp=fileparts(path_to_uvmat); |
---|
[116] | 1019 | helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html'); |
---|
[36] | 1020 | if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package') |
---|
[2] | 1021 | else |
---|
[36] | 1022 | addpath (fullfile(pathelp,'uvmat_doc')) |
---|
[2] | 1023 | web([helpfile '#geometry_calib']) |
---|
| 1024 | end |
---|
| 1025 | |
---|
[17] | 1026 | %------------------------------------------------------------------------ |
---|
[2] | 1027 | function MenuCreateGrid_Callback(hObject, eventdata, handles) |
---|
[17] | 1028 | %------------------------------------------------------------------------ |
---|
[36] | 1029 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
[61] | 1030 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
[12] | 1031 | Tinput=[];%default |
---|
| 1032 | if isfield(CalibData,'grid') |
---|
| 1033 | Tinput=CalibData.grid; |
---|
| 1034 | end |
---|
[71] | 1035 | [T,CalibData.grid]=create_grid(Tinput);%display the GUI create_grid |
---|
[61] | 1036 | set(handles.geometry_calib,'UserData',CalibData) |
---|
[2] | 1037 | |
---|
[12] | 1038 | %grid in phys space |
---|
[71] | 1039 | Coord=get(handles.ListCoord,'String'); |
---|
| 1040 | val=get(handles.ListCoord,'Value'); |
---|
| 1041 | data=read_geometry_calib(Coord); |
---|
| 1042 | %nbpoints=size(data.Coord,1); %nbre of calibration points |
---|
| 1043 | data.Coord(val:val+size(T,1)-1,1:3)=T(end:-1:1,:);%update the existing list of phys coordinates from the GUI create_grid |
---|
| 1044 | % for i=1:nbpoints |
---|
| 1045 | % for j=1:5 |
---|
| 1046 | % Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
| 1047 | % end |
---|
| 1048 | % end |
---|
| 1049 | %update the phys coordinates starting from the selected point (down in the |
---|
| 1050 | Coord(end,:)=[]; %remove last string '.....' |
---|
| 1051 | for i=1:size(data.Coord,1) |
---|
| 1052 | for j=1:5 |
---|
[17] | 1053 | Coord{i,j}=num2str(data.Coord(i,j),4);%display coordiantes with 4 digits |
---|
| 1054 | end |
---|
| 1055 | end |
---|
| 1056 | |
---|
| 1057 | %size(data.Coord,1) |
---|
[128] | 1058 | Tabchar=cell2tab(Coord,' | '); |
---|
[71] | 1059 | Tabchar=[Tabchar ;{'......'}]; |
---|
[12] | 1060 | set(handles.ListCoord,'String',Tabchar) |
---|
[2] | 1061 | |
---|
[71] | 1062 | % ----------------------------------------------------------------------- |
---|
| 1063 | % --- automatic grid dectection from local maxima of the images |
---|
[60] | 1064 | function MenuDetectGrid_Callback(hObject, eventdata, handles) |
---|
[71] | 1065 | %------------------------------------------------------------------------ |
---|
[159] | 1066 | %% read the four last point coordinates in pixels |
---|
[108] | 1067 | Coord_cell=get(handles.ListCoord,'String');%read list of coordinates on geometry_calib |
---|
[60] | 1068 | data=read_geometry_calib(Coord_cell); |
---|
| 1069 | nbpoints=size(data.Coord,1); %nbre of calibration points |
---|
[62] | 1070 | if nbpoints~=4 |
---|
[227] | 1071 | msgbox_uvmat('ERROR','four points must have be selected by the mouse to delimitate the phys grid area; the Ox axis will be defined by the two first points') |
---|
[71] | 1072 | return |
---|
[60] | 1073 | end |
---|
[71] | 1074 | corners_X=(data.Coord(end:-1:end-3,4)); %pixel absissa of the four corners |
---|
| 1075 | corners_Y=(data.Coord(end:-1:end-3,5)); |
---|
[60] | 1076 | |
---|
[71] | 1077 | %reorder the last two points (the two first in the list) if needed |
---|
[121] | 1078 | angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1))); |
---|
[62] | 1079 | if abs(angles(4)-angles(2))>abs(angles(3)-angles(2)) |
---|
| 1080 | X_end=corners_X(4); |
---|
| 1081 | Y_end=corners_Y(4); |
---|
| 1082 | corners_X(4)=corners_X(3); |
---|
| 1083 | corners_Y(4)=corners_Y(3); |
---|
| 1084 | corners_X(3)=X_end; |
---|
| 1085 | corners_Y(3)=Y_end; |
---|
| 1086 | end |
---|
| 1087 | |
---|
[227] | 1088 | %% initiate the grid |
---|
| 1089 | CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib |
---|
| 1090 | grid_input=[];%default |
---|
| 1091 | if isfield(CalibData,'grid') |
---|
| 1092 | grid_input=CalibData.grid;%retrieve the previously used grid |
---|
| 1093 | end |
---|
| 1094 | [T,CalibData.grid,white_test]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T |
---|
| 1095 | set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use |
---|
| 1096 | |
---|
| 1097 | |
---|
| 1098 | |
---|
[159] | 1099 | %% read the current image, displayed in the GUI uvmat |
---|
[60] | 1100 | huvmat=findobj(allchild(0),'Name','uvmat'); |
---|
| 1101 | UvData=get(huvmat,'UserData'); |
---|
| 1102 | A=UvData.Field.A; |
---|
| 1103 | npxy=size(A); |
---|
[159] | 1104 | X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm) |
---|
| 1105 | Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm) |
---|
[109] | 1106 | |
---|
[159] | 1107 | %calculate transform matrices for plane projection |
---|
[108] | 1108 | % reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren |
---|
| 1109 | B = [ X Y ones(size(X)) zeros(4,3) -X.*corners_X -Y.*corners_X ... |
---|
| 1110 | zeros(4,3) X Y ones(size(X)) -X.*corners_Y -Y.*corners_Y ]; |
---|
| 1111 | B = reshape (B', 8 , 8 )'; |
---|
| 1112 | D = [ corners_X , corners_Y ]; |
---|
| 1113 | D = reshape (D', 8 , 1 ); |
---|
[121] | 1114 | l = (B' * B)\B' * D; |
---|
[108] | 1115 | Amat = reshape([l(1:6)' 0 0 1 ],3,3)'; |
---|
| 1116 | C = [l(7:8)' 1]; |
---|
| 1117 | |
---|
[159] | 1118 | % transform grid image into 'phys' coordinates |
---|
[114] | 1119 | GeometryCalib.fx_fy=[1 1]; |
---|
| 1120 | GeometryCalib.Tx_Ty_Tz=[Amat(1,3) Amat(2,3) 1]; |
---|
[108] | 1121 | GeometryCalib.R=[Amat(1,1),Amat(1,2),0;Amat(2,1),Amat(2,2),0;C(1),C(2),0]; |
---|
[159] | 1122 | GeometryCalib.CoordUnit='cm'; |
---|
[114] | 1123 | path_uvmat=which('uvmat');% check the path detected for source file uvmat |
---|
| 1124 | path_UVMAT=fileparts(path_uvmat); %path to UVMAT |
---|
| 1125 | addpath(fullfile(path_UVMAT,'transform_field')) |
---|
| 1126 | Data.ListVarName={'AY','AX','A'}; |
---|
| 1127 | Data.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
| 1128 | if ndims(A)==3 |
---|
| 1129 | A=mean(A,3); |
---|
| 1130 | end |
---|
| 1131 | Data.A=A-min(min(A)); |
---|
| 1132 | Data.AY=[npxy(1)-0.5 0.5]; |
---|
| 1133 | Data.AX=[0.5 npxy(2)]; |
---|
[158] | 1134 | Data.CoordUnit='pixel'; |
---|
[114] | 1135 | Calib.GeometryCalib=GeometryCalib; |
---|
[121] | 1136 | DataOut=phys(Data,Calib); |
---|
[114] | 1137 | rmpath(fullfile(path_UVMAT,'transform_field')) |
---|
| 1138 | Amod=DataOut.A; |
---|
| 1139 | Rangx=DataOut.AX; |
---|
| 1140 | Rangy=DataOut.AY; |
---|
[156] | 1141 | if white_test |
---|
[159] | 1142 | Amod=double(Amod);%case of white grid markers: will look for image maxima |
---|
[156] | 1143 | else |
---|
[159] | 1144 | Amod=-double(Amod);%case of black grid markers: will look for image minima |
---|
[156] | 1145 | end |
---|
[114] | 1146 | % figure(12) %display corrected image |
---|
[109] | 1147 | % Amax=max(max(Amod)); |
---|
| 1148 | % image(Rangx,Rangy,uint8(255*Amod/Amax)) |
---|
[114] | 1149 | |
---|
[159] | 1150 | %% detection of local image extrema in each direction |
---|
[88] | 1151 | Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space |
---|
| 1152 | Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space |
---|
[121] | 1153 | ind_range_x=ceil(abs(GeometryCalib.R(1,1)*CalibData.grid.Dx/3));% range of search of image ma around each point obtained by linear interpolation from the marked points |
---|
| 1154 | ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3));% range of search of image ma around each point obtained by linear interpolation from the marked points |
---|
[60] | 1155 | nbpoints=size(T,1); |
---|
| 1156 | for ipoint=1:nbpoints |
---|
| 1157 | i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint)); |
---|
| 1158 | j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint)); |
---|
[109] | 1159 | j0min=max(j0-ind_range_y,1); |
---|
| 1160 | j0max=min(j0+ind_range_y,size(Amod,1)); |
---|
| 1161 | i0min=max(i0-ind_range_x,1); |
---|
| 1162 | i0max=min(i0+ind_range_x,size(Amod,2)); |
---|
| 1163 | Asub=Amod(j0min:j0max,i0min:i0max); |
---|
[60] | 1164 | x_profile=sum(Asub,1); |
---|
| 1165 | y_profile=sum(Asub,2); |
---|
| 1166 | [Amax,ind_x_max]=max(x_profile); |
---|
| 1167 | [Amax,ind_y_max]=max(y_profile); |
---|
[61] | 1168 | %sub-pixel improvement using moments |
---|
| 1169 | x_shift=0; |
---|
| 1170 | y_shift=0; |
---|
[109] | 1171 | if ind_x_max+2<=numel(x_profile) && ind_x_max-2>=1 |
---|
[61] | 1172 | Atop=x_profile(ind_x_max-2:ind_x_max+2); |
---|
| 1173 | x_shift=sum(Atop.*[-2 -1 0 1 2])/sum(Atop); |
---|
| 1174 | end |
---|
[114] | 1175 | if ind_y_max+2<=numel(y_profile) && ind_y_max-2>=1 |
---|
[61] | 1176 | Atop=y_profile(ind_y_max-2:ind_y_max+2); |
---|
| 1177 | y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop); |
---|
| 1178 | end |
---|
[109] | 1179 | Delta(ipoint,1)=(x_shift+ind_x_max+i0min-i0-1)*Dx;%shift from the initial guess |
---|
| 1180 | Delta(ipoint,2)=(y_shift+ind_y_max+j0min-j0-1)*Dy; |
---|
[60] | 1181 | end |
---|
| 1182 | Tmod=T(:,(1:2))+Delta; |
---|
| 1183 | [Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2)); |
---|
[63] | 1184 | for ipoint=1:nbpoints |
---|
| 1185 | Coord{ipoint,1}=num2str(T(ipoint,1),4);%display coordiantes with 4 digits |
---|
| 1186 | Coord{ipoint,2}=num2str(T(ipoint,2),4);%display coordiantes with 4 digits |
---|
[109] | 1187 | Coord{ipoint,3}=num2str(T(ipoint,3),4);%display coordiantes with 4 digits; |
---|
| 1188 | Coord{ipoint,4}=num2str(Xpx(ipoint),4);%display coordiantes with 4 digits |
---|
| 1189 | Coord{ipoint,5}=num2str(Ypx(ipoint),4);%display coordiantes with 4 digits |
---|
[60] | 1190 | end |
---|
[128] | 1191 | Tabchar=cell2tab(Coord(end:-1:1,:),' | '); |
---|
[71] | 1192 | Tabchar=[Tabchar ;{'......'}]; |
---|
[60] | 1193 | set(handles.ListCoord,'Value',1) |
---|
| 1194 | set(handles.ListCoord,'String',Tabchar) |
---|
[67] | 1195 | MenuPlot_Callback(hObject, eventdata, handles) |
---|
[60] | 1196 | |
---|
[71] | 1197 | %----------------------------------------------------------------------- |
---|
| 1198 | function MenuTranslatePoints_Callback(hObject, eventdata, handles) |
---|
| 1199 | %----------------------------------------------------------------------- |
---|
| 1200 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
| 1201 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
| 1202 | Tinput=[];%default |
---|
| 1203 | if isfield(CalibData,'translate') |
---|
| 1204 | Tinput=CalibData.translate; |
---|
| 1205 | end |
---|
| 1206 | T=translate_points(Tinput);%display translate_points GUI and get shift parameters |
---|
| 1207 | CalibData.translate=T; |
---|
| 1208 | set(handles.geometry_calib,'UserData',CalibData) |
---|
| 1209 | %translation |
---|
| 1210 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 1211 | data=read_geometry_calib(Coord_cell); |
---|
| 1212 | data.Coord(:,1)=T(1)+data.Coord(:,1); |
---|
| 1213 | data.Coord(:,2)=T(2)+data.Coord(:,2); |
---|
| 1214 | data.Coord(:,3)=T(3)+data.Coord(:,3); |
---|
| 1215 | data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
| 1216 | for i=1:size(data.Coord,1) |
---|
| 1217 | for j=1:5 |
---|
| 1218 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
| 1219 | end |
---|
| 1220 | end |
---|
[128] | 1221 | Tabchar=cell2tab(Coord,' | '); |
---|
[88] | 1222 | Tabchar=[Tabchar; {'.....'}]; |
---|
[71] | 1223 | %set(handles.ListCoord,'Value',1) |
---|
| 1224 | set(handles.ListCoord,'String',Tabchar) |
---|
| 1225 | |
---|
| 1226 | |
---|
| 1227 | % -------------------------------------------------------------------- |
---|
| 1228 | function MenuRotatePoints_Callback(hObject, eventdata, handles) |
---|
| 1229 | %hcalib=get(handles.calib_type,'parent');%handles of the GUI geometry_calib |
---|
| 1230 | CalibData=get(handles.geometry_calib,'UserData'); |
---|
| 1231 | Tinput=[];%default |
---|
| 1232 | if isfield(CalibData,'rotate') |
---|
| 1233 | Tinput=CalibData.rotate; |
---|
| 1234 | end |
---|
[356] | 1235 | T=rotate_points(Tinput);%display rotate_points GUI to introduce rotation parameters |
---|
[71] | 1236 | CalibData.rotate=T; |
---|
| 1237 | set(handles.geometry_calib,'UserData',CalibData) |
---|
| 1238 | %----------------------------------------------------- |
---|
| 1239 | %rotation |
---|
| 1240 | Phi=T(1); |
---|
| 1241 | O_x=0;%default |
---|
| 1242 | O_y=0;%default |
---|
| 1243 | if numel(T)>=2 |
---|
| 1244 | O_x=T(2);%default |
---|
| 1245 | end |
---|
| 1246 | if numel(T)>=3 |
---|
| 1247 | O_y=T(3);%default |
---|
| 1248 | end |
---|
| 1249 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 1250 | data=read_geometry_calib(Coord_cell); |
---|
| 1251 | r1=cos(pi*Phi/180); |
---|
| 1252 | r2=-sin(pi*Phi/180); |
---|
| 1253 | r3=sin(pi*Phi/180); |
---|
| 1254 | r4=cos(pi*Phi/180); |
---|
| 1255 | x=data.Coord(:,1)-O_x; |
---|
| 1256 | y=data.Coord(:,2)-O_y; |
---|
| 1257 | data.Coord(:,1)=r1*x+r2*y; |
---|
| 1258 | data.Coord(:,2)=r3*x+r4*y; |
---|
| 1259 | % data.Coord(:,[4 5])=data.Coord(:,[4 5]); |
---|
| 1260 | for i=1:size(data.Coord,1) |
---|
| 1261 | for j=1:5 |
---|
| 1262 | Coord{i,j}=num2str(data.Coord(i,j),4);%phys x,y,z |
---|
| 1263 | end |
---|
| 1264 | end |
---|
[148] | 1265 | Tabchar=cell2tab(Coord,' | '); |
---|
[71] | 1266 | Tabchar=[Tabchar;{'......'}]; |
---|
| 1267 | set(handles.ListCoord,'Value',1) |
---|
| 1268 | set(handles.ListCoord,'String',Tabchar) |
---|
| 1269 | |
---|
[109] | 1270 | % -------------------------------------------------------------------- |
---|
| 1271 | function MenuImportPoints_Callback(hObject, eventdata, handles) |
---|
[121] | 1272 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
[109] | 1273 | if isempty(fileinput) |
---|
| 1274 | return |
---|
| 1275 | end |
---|
| 1276 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
| 1277 | GeometryCalib=s.GeometryCalib; |
---|
[114] | 1278 | %GeometryCalib=load_calib(hObject, eventdata, handles) |
---|
[116] | 1279 | calib=reshape(GeometryCalib.PointCoord,[],1); |
---|
[109] | 1280 | for ilist=1:numel(calib) |
---|
| 1281 | CoordCell{ilist}=num2str(calib(ilist)); |
---|
| 1282 | end |
---|
| 1283 | CoordCell=reshape(CoordCell,[],5); |
---|
[128] | 1284 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
[109] | 1285 | Tabchar=[Tabchar;{'......'}]; |
---|
| 1286 | set(handles.ListCoord,'Value',1) |
---|
| 1287 | set(handles.ListCoord,'String',Tabchar) |
---|
| 1288 | MenuPlot_Callback(handles.geometry_calib, [], handles) |
---|
| 1289 | |
---|
| 1290 | % ----------------------------------------------------------------------- |
---|
| 1291 | function MenuImportIntrinsic_Callback(hObject, eventdata, handles) |
---|
| 1292 | %------------------------------------------------------------------------ |
---|
| 1293 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
| 1294 | if isempty(fileinput) |
---|
| 1295 | return |
---|
| 1296 | end |
---|
| 1297 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
| 1298 | GeometryCalib=s.GeometryCalib; |
---|
[114] | 1299 | display_intrinsic(GeometryCalib,handles) |
---|
[109] | 1300 | |
---|
| 1301 | % ----------------------------------------------------------------------- |
---|
| 1302 | function MenuImportAll_Callback(hObject, eventdata, handles) |
---|
| 1303 | %------------------------------------------------------------------------ |
---|
[121] | 1304 | fileinput=browse_xml(hObject, eventdata, handles); |
---|
[109] | 1305 | if ~isempty(fileinput) |
---|
| 1306 | loadfile(handles,fileinput) |
---|
| 1307 | end |
---|
| 1308 | |
---|
| 1309 | % ----------------------------------------------------------------------- |
---|
| 1310 | % --- Executes on menubar option Import/Grid file: introduce previous grid files |
---|
| 1311 | function MenuGridFile_Callback(hObject, eventdata, handles) |
---|
| 1312 | % ----------------------------------------------------------------------- |
---|
[121] | 1313 | inputfile=browse_xml(hObject, eventdata, handles); |
---|
[109] | 1314 | listfile=get(handles.coord_files,'string'); |
---|
| 1315 | if isequal(listfile,{''}) |
---|
| 1316 | listfile={inputfile}; |
---|
| 1317 | else |
---|
[121] | 1318 | listfile=[listfile;{inputfile}];%update the list of coord files |
---|
[109] | 1319 | end |
---|
| 1320 | set(handles.coord_files,'string',listfile); |
---|
| 1321 | |
---|
| 1322 | %------------------------------------------------------------------------ |
---|
[114] | 1323 | % --- 'key_press_fcn:' function activated when a key is pressed on the keyboard |
---|
| 1324 | function key_press_fcn(hObject,eventdata,handles) |
---|
| 1325 | %------------------------------------------------------------------------ |
---|
| 1326 | xx=double(get(handles.geometry_calib,'CurrentCharacter')); %get the keyboard character |
---|
| 1327 | if ismember(xx,[8 127])%backspace or delete |
---|
| 1328 | Coord_cell=get(handles.ListCoord,'String'); |
---|
| 1329 | val=get(handles.ListCoord,'Value'); |
---|
| 1330 | if max(val)<numel(Coord_cell) % the last element '...' has not been selected |
---|
| 1331 | Coord_cell(val)=[];%remove the selected line |
---|
| 1332 | set(handles.ListCoord,'Value',min(val)) |
---|
| 1333 | set(handles.ListCoord,'String',Coord_cell) |
---|
| 1334 | ListCoord_Callback(hObject, eventdata, handles) |
---|
| 1335 | MenuPlot_Callback(hObject,eventdata,handles) |
---|
| 1336 | end |
---|
| 1337 | end |
---|
| 1338 | |
---|
| 1339 | %------------------------------------------------------------------------ |
---|
[109] | 1340 | function fileinput=browse_xml(hObject, eventdata, handles) |
---|
| 1341 | %------------------------------------------------------------------------ |
---|
| 1342 | fileinput=[];%default |
---|
| 1343 | oldfile=''; %default |
---|
[116] | 1344 | UserData=get(handles.geometry_calib,'UserData'); |
---|
[114] | 1345 | if isfield(UserData,'XmlInputFile') |
---|
| 1346 | oldfile=UserData.XmlInputFile; |
---|
[109] | 1347 | end |
---|
| 1348 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
| 1349 | {'*.xml;*.mat', ' (*.xml,*.mat)'; |
---|
| 1350 | '*.xml', '.xml files '; ... |
---|
| 1351 | '*.mat', '.mat matlab files '}, ... |
---|
| 1352 | 'Pick a file',oldfile); |
---|
| 1353 | fileinput=[PathName FileName];%complete file name |
---|
| 1354 | testblank=findstr(fileinput,' ');%look for blanks |
---|
| 1355 | if ~isempty(testblank) |
---|
| 1356 | msgbox_uvmat('ERROR','forbidden input file name or path: no blank character allowed') |
---|
| 1357 | return |
---|
| 1358 | end |
---|
| 1359 | sizf=size(fileinput); |
---|
| 1360 | if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end |
---|
[114] | 1361 | UserData.XmlInputFile=fileinput; |
---|
[109] | 1362 | set(handles.geometry_calib,'UserData',UserData)%record current file foer further use of browser |
---|
| 1363 | |
---|
| 1364 | % ----------------------------------------------------------------------- |
---|
[128] | 1365 | function Heading=loadfile(handles,fileinput) |
---|
[109] | 1366 | %------------------------------------------------------------------------ |
---|
[128] | 1367 | Heading=[];%default |
---|
[121] | 1368 | [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib'); |
---|
[128] | 1369 | if ~isempty(errormsg) |
---|
[502] | 1370 | msgbox_uvmat('ERROR',errormsg) |
---|
[128] | 1371 | return |
---|
| 1372 | end |
---|
| 1373 | if ~isempty(s.Heading) |
---|
| 1374 | Heading=s.Heading; |
---|
| 1375 | end |
---|
| 1376 | |
---|
[116] | 1377 | GeometryCalib=s.GeometryCalib; |
---|
[114] | 1378 | fx=1;fy=1;Cx=0;Cy=0;kc=0; %default |
---|
| 1379 | CoordCell={}; |
---|
| 1380 | Tabchar={};%default |
---|
| 1381 | val_cal=1;%default |
---|
| 1382 | if ~isempty(GeometryCalib) |
---|
| 1383 | % choose the calibration option |
---|
| 1384 | if isfield(GeometryCalib,'CalibrationType') |
---|
| 1385 | calib_list=get(handles.calib_type,'String'); |
---|
| 1386 | for ilist=1:numel(calib_list) |
---|
| 1387 | if strcmp(calib_list{ilist},GeometryCalib.CalibrationType) |
---|
| 1388 | val_cal=ilist; |
---|
| 1389 | break |
---|
| 1390 | end |
---|
| 1391 | end |
---|
| 1392 | end |
---|
| 1393 | display_intrinsic(GeometryCalib,handles)%intrinsic param |
---|
| 1394 | %extrinsic param |
---|
| 1395 | if isfield(GeometryCalib,'Tx_Ty_Tz') |
---|
| 1396 | Tx_Ty_Tz=GeometryCalib.Tx_Ty_Tz; |
---|
| 1397 | set(handles.Tx,'String',num2str(GeometryCalib.Tx_Ty_Tz(1),4)) |
---|
| 1398 | set(handles.Ty,'String',num2str(GeometryCalib.Tx_Ty_Tz(2),4)) |
---|
| 1399 | set(handles.Tz,'String',num2str(GeometryCalib.Tx_Ty_Tz(3),4)) |
---|
| 1400 | end |
---|
| 1401 | if isfield(GeometryCalib,'omc') |
---|
| 1402 | set(handles.Phi,'String',num2str(GeometryCalib.omc(1),4)) |
---|
| 1403 | set(handles.Theta,'String',num2str(GeometryCalib.omc(2),4)) |
---|
| 1404 | set(handles.Psi,'String',num2str(GeometryCalib.omc(3),4)) |
---|
| 1405 | end |
---|
[116] | 1406 | calib=reshape(GeometryCalib.PointCoord,[],1); |
---|
[109] | 1407 | for ilist=1:numel(calib) |
---|
| 1408 | CoordCell{ilist}=num2str(calib(ilist)); |
---|
| 1409 | end |
---|
| 1410 | CoordCell=reshape(CoordCell,[],5); |
---|
[128] | 1411 | Tabchar=cell2tab(CoordCell,' | ');%transform cells into table ready for display |
---|
[109] | 1412 | MenuPlot_Callback(handles.geometry_calib, [], handles) |
---|
| 1413 | end |
---|
[114] | 1414 | set(handles.calib_type,'Value',val_cal) |
---|
[109] | 1415 | Tabchar=[Tabchar;{'......'}]; |
---|
[114] | 1416 | set(handles.ListCoord,'Value',1) |
---|
| 1417 | set(handles.ListCoord,'String',Tabchar) |
---|
| 1418 | |
---|
[109] | 1419 | if isempty(CoordCell)% allow mouse action by default in the absence of input points |
---|
| 1420 | set(handles.edit_append,'Value',1) |
---|
| 1421 | set(handles.edit_append,'BackgroundColor',[1 1 0]) |
---|
| 1422 | else % does not allow mouse action by default in the presence of input points |
---|
| 1423 | set(handles.edit_append,'Value',0) |
---|
| 1424 | set(handles.edit_append,'BackgroundColor',[0.7 0.7 0.7]) |
---|
| 1425 | end |
---|
| 1426 | |
---|
[114] | 1427 | %------------------------------------------------------------------------ |
---|
| 1428 | %---display calibration intrinsic parameters |
---|
| 1429 | function display_intrinsic(GeometryCalib,handles) |
---|
| 1430 | %------------------------------------------------------------------------ |
---|
| 1431 | fx=[]; |
---|
| 1432 | fy=[]; |
---|
| 1433 | if isfield(GeometryCalib,'fx_fy') |
---|
| 1434 | fx=GeometryCalib.fx_fy(1); |
---|
| 1435 | fy=GeometryCalib.fx_fy(2); |
---|
| 1436 | end |
---|
| 1437 | Cx_Cy=[0 0];%default |
---|
| 1438 | if isfield(GeometryCalib,'Cx_Cy') |
---|
| 1439 | Cx_Cy=GeometryCalib.Cx_Cy; |
---|
| 1440 | end |
---|
| 1441 | kc=0; |
---|
| 1442 | if isfield(GeometryCalib,'kc') |
---|
[121] | 1443 | kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal; |
---|
[114] | 1444 | end |
---|
| 1445 | set(handles.fx,'String',num2str(fx,5)) |
---|
| 1446 | set(handles.fy,'String',num2str(fy,5)) |
---|
| 1447 | set(handles.Cx,'String',num2str(Cx_Cy(1),'%1.1f')) |
---|
| 1448 | set(handles.Cy,'String',num2str(Cx_Cy(2),'%1.1f')) |
---|
| 1449 | set(handles.kc,'String',num2str(kc,'%1.4f')) |
---|
[109] | 1450 | |
---|
| 1451 | |
---|
[507] | 1452 | % --- Executes when user attempts to close geometry_calib. |
---|
| 1453 | function geometry_calib_CloseRequestFcn(hObject, eventdata, handles) |
---|
| 1454 | % hObject handle to geometry_calib (see GCBO) |
---|
| 1455 | % eventdata reserved - to be defined in a future version of MATLAB |
---|
| 1456 | % handles structure with handles and user data (see GUIDATA) |
---|
| 1457 | |
---|
| 1458 | % Hint: delete(hObject) closes the figure |
---|
| 1459 | delete(hObject); |
---|