Changeset 121 for trunk/src


Ignore:
Timestamp:
Nov 12, 2010, 5:39:24 PM (14 years ago)
Author:
sommeria
Message:

geometry_calib: adapt all the calibration options to the new format for calibration parameters. Suppress the definition of Z for 2D calibrations
msbox_uvmat: suppress a warning by a test on the input string
uvmat: improve the dispaly of dt for pairs

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r116 r121  
     1%%
    12%'geometry_calib': performs geometric calibration from a set of reference points
    23%
     
    5354                   'gui_LayoutFcn',  [] , ...
    5455                   'gui_Callback',   []);
    55 if nargin & isstr(varargin{1})
     56if nargin && ischar(varargin{1})
    5657    gui_State.gui_Callback = str2func(varargin{1});
    5758end
     
    9091%set menu of calibration options
    9192%set(handles.calib_type,'String',{'rescale';'linear';'perspective';'normal';'tsai';'bouguet';'extrinsic'})
    92 set(handles.calib_type,'String',{'rescale';'linear';'quadr';'3D_linear';'3D_quadr';'3D_extrinsic'})
     93set(handles.calib_type,'String',{'rescale';'linear';'3D_linear';'3D_quadr';'3D_extrinsic'})
    9394inputxml='';
    9495if exist('inputfile','var')&& ~isempty(inputfile)
     
    9798    [Pathsub,RootFile,field_count,str2,str_a,str_b,ext,nom_type,subdir]=name2display(inputfile);
    9899    if ~strcmp(ext,'.xml')
    99         inputfile=[fullfile(Pathsub,RootFile) '.xml']%xml file corresponding to the input file
     100        inputfile=[fullfile(Pathsub,RootFile) '.xml'];%xml file corresponding to the input file
    100101    end
    101102end
     
    141142function APPLY_Callback(hObject, eventdata, handles)
    142143%------------------------------------------------------------------------
    143 
    144144%read the current calibration points
    145145Coord_cell=get(handles.ListCoord,'String');
    146146Object=read_geometry_calib(Coord_cell);
    147147Coord=Object.Coord;
    148 
    149148% apply the calibration, whose type is selected in  handles.calib_type
    150149if ~isempty(Coord)
     
    198197RootPath='';
    199198RootFile='';
    200 if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile)
     199if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
    201200    testhandle=1;
    202201    RootPath=get(hhuvmat.RootPath,'String');
     
    206205else
    207206    question={'save the calibration data and point coordinates in'};
    208     def={fullfile(RootPath,['ObjectCalib.xml'])};
     207    def={fullfile(RootPath,'ObjectCalib.xml')};
    209208    options.Resize='on';
    210209    answer=inputdlg(question,'save average in a new file',1,def,options);
     
    214213    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    215214    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels']});
    216 if isequal(answer,'Yes')
    217     answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane));
    218     Z_plane=str2num(answer_1);
    219     GeometryCalib.NbSlice=1;
    220     GeometryCalib.SliceCoord=[0 0 Z_plane];
     215if strcmp(answer,'Yes')
     216    if strcmp(calib_cell{val}(1:2),'3D')%set the plane position for 3D (projection) calibration
     217        answer_1=msgbox_uvmat('INPUT_TXT',' Z= ',num2str(Z_plane));
     218        if strcmp(answer_1,'Cancel')
     219            Z_plane=0; %default
     220        else
     221            Z_plane=str2num(answer_1);
     222        end
     223        GeometryCalib.NbSlice=1;
     224        GeometryCalib.SliceCoord=[0 0 Z_plane];
     225    end
    221226    errormsg=update_imadoc(GeometryCalib,outputfile);% introduce the calibration data in the xml file
    222227    if ~strcmp(errormsg,'')
     
    396401T_y=py(2);
    397402GeometryCalib.CalibrationType='rescale';
    398 GeometryCalib.fx_fy=[px(1) py(1)];
     403GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y
    399404GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
    400405GeometryCalib.Tx_Ty_Tz=[px(2)/px(1) py(2)/py(1) 1];
     
    417422% y1=XY_mat*a_Y1;
    418423% err_Y1=max(abs(y1-y_ima));%error
    419 R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,0];
     424% R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,1];
     425R=[a_X1(2),a_X1(3);a_Y1(2),a_Y1(3)];
    420426norm=abs(det(R));
    421427GeometryCalib.CalibrationType='linear';
    422 GeometryCalib.fx_fy=[norm norm];
     428GeometryCalib.fx_fy(1)=sqrt((a_X1(2)/a_Y1(3))*norm);
     429GeometryCalib.fx_fy(2)=(a_Y1(3)/a_X1(2))*GeometryCalib.fx_fy(1);
    423430GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
    424 R=[a_X1(2),a_X1(3),0;a_Y1(2),a_Y1(3),0;0,0,0];
    425431GeometryCalib.Tx_Ty_Tz=[a_X1(1) a_Y1(1) 1];
    426 GeometryCalib.R=R/norm;
    427 GeometryCalib.omc=(180/pi)*[acos(R(1,1)) 0 0];
     432R(1,:)=R(1,:)/GeometryCalib.fx_fy(1);
     433R(2,:)=R(2,:)/GeometryCalib.fx_fy(2);
     434R=[R;[0 0]];
     435GeometryCalib.R=[R [0;0;1]];
     436GeometryCalib.omc=(180/pi)*[acos(GeometryCalib.R(1,1)) 0 0]
    428437%------------------------------------------------------------------------
    429438% determine the tsai parameters for a view normal to the grid plane
     
    474483calib_param(3)=a_Y1(1);
    475484calib_param(4)=Calib.f/(norm*Calib.dpx)-R(3,3)*Zmean;
    476 calib_param(5)=angle(a_X1(2)+i*a_X1(3));
     485calib_param(5)=angle(a_X1(2)+1i*a_X1(3));
    477486display(['initial guess=' num2str(calib_param)])
    478487
    479488%optimise the parameters: minimisation of error
    480 calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param)
     489calib_param = fminsearch(@(calib_param) error_calib(calib_param,Calib,Coord),calib_param);
    481490
    482491GeometryCalib.CalibrationType='tsai_normal';
     
    493502%------------------------------------------------------------------------
    494503function GeometryCalib=calib_3D_linear(Coord,handles)
    495 %TO UPDATE
    496504%------------------------------------------------------------------
    497505path_uvmat=which('uvmat');% check the path detected for source file uvmat
     
    499507huvmat=findobj(allchild(0),'Tag','uvmat');
    500508hhuvmat=guidata(huvmat);
    501 x_1=Coord(:,4:5)'
    502 X_1=Coord(:,1:3)'
    503 n_ima=1;
    504 % check_cond=0;
    505 
    506 nx=str2num(get(hhuvmat.npx,'String'));
    507 ny=str2num(get(hhuvmat.npy,'String'));
    508 
    509 est_dist=[0;0;0;0;0];
    510 est_aspect_ratio=0;
    511 est_fc=[1;1];
    512 %fc=[25;25]/0.012;
    513 center_optim=0;
    514 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));
    515 
    516 GeometryCalib.CalibrationType='3D_linear';
    517 GeometryCalib.focal=fc(2);
    518 GeometryCalib.dpx_dpy=[1 1];
    519 GeometryCalib.Cx_Cy=cc';
    520 GeometryCalib.sx=fc(1)/fc(2);
    521 GeometryCalib.kappa1=-kc(1)/fc(2)^2;
    522 GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
    523 GeometryCalib.Tx_Ty_Tz=Tc_1';
    524 GeometryCalib.R=Rc_1;
    525 
    526 %------------------------------------------------------------------------
    527 function GeometryCalib=calib_3D_quadr(Coord,handles)
    528 %------------------------------------------------------------------
    529 
    530 path_uvmat=which('uvmat');% check the path detected for source file uvmat
    531 path_UVMAT=fileparts(path_uvmat); %path to UVMAT
    532 huvmat=findobj(allchild(0),'Tag','uvmat');
    533 hhuvmat=guidata(huvmat);
    534 % check_cond=0;
    535509coord_files=get(handles.coord_files,'String');
    536510if ischar(coord_files)
     
    540514    coord_files={};
    541515end
    542 
    543516%retrieve the calibration points stored in the files listed in the popup list coord_files
    544517x_1=Coord(:,4:5)';%px coordinates of the ref points
     
    557530                if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
    558531                PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
    559                 Coord_file=[];
     532                Coord_file=zeros(length(PointCoord),5);%default
    560533                for i=1:length(PointCoord)
    561534                    line=str2num(PointCoord{i});
     
    571544    end
    572545end
    573 
    574546n_ima=numel(coord_files)+1;
    575 whos
    576 
     547est_dist=[0;0;0;0;0];
     548est_aspect_ratio=0;
     549est_fc=[1;1];
     550%fc=[25;25]/0.012;
     551center_optim=0;
     552run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));
     553GeometryCalib.CalibrationType='3D_linear';
     554GeometryCalib.fx_fy=fc';
     555%GeometryCalib.focal=fc(2);
     556%GeometryCalib.dpx_dpy=[1 1];
     557GeometryCalib.Cx_Cy=cc';
     558%GeometryCalib.sx=fc(1)/fc(2);
     559GeometryCalib.kc=kc(1);
     560%GeometryCalib.kappa1=-kc(1)/fc(2)^2;
     561GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
     562GeometryCalib.Tx_Ty_Tz=Tc_1';
     563GeometryCalib.R=Rc_1;
     564GeometryCalib.R(2,1:3)=-GeometryCalib.R(2,1:3);%inversion of the y image coordinate
     565GeometryCalib.Tx_Ty_Tz(2)=-GeometryCalib.Tx_Ty_Tz(2);%inversion of the y image coordinate
     566GeometryCalib.Cx_Cy(2)=ny-GeometryCalib.Cx_Cy(2);%inversion of the y image coordinate
     567GeometryCalib.omc=(180/pi)*omc_1;%angles in degrees
     568GeometryCalib.ErrorRMS=[];
     569GeometryCalib.ErrorMax=[];
     570
     571%------------------------------------------------------------------------
     572function GeometryCalib=calib_3D_quadr(Coord,handles)
     573%------------------------------------------------------------------
     574
     575path_uvmat=which('uvmat');% check the path detected for source file uvmat
     576path_UVMAT=fileparts(path_uvmat); %path to UVMAT
     577huvmat=findobj(allchild(0),'Tag','uvmat');
     578hhuvmat=guidata(huvmat);
     579% check_cond=0;
     580coord_files=get(handles.coord_files,'String');
     581if ischar(coord_files)
     582    coord_files={coord_files};
     583end
     584if isempty(coord_files{1}) || isequal(coord_files,{''})
     585    coord_files={};
     586end
     587
     588%retrieve the calibration points stored in the files listed in the popup list coord_files
     589x_1=Coord(:,4:5)';%px coordinates of the ref points
     590nx=str2num(get(hhuvmat.npx,'String'));
     591ny=str2num(get(hhuvmat.npy,'String'));
     592x_1(2,:)=ny-x_1(2,:);%reverse the y image coordinates
     593X_1=Coord(:,1:3)';%phys coordinates of the ref points
     594n_ima=numel(coord_files)+1;
     595if ~isempty(coord_files)
     596    msgbox_uvmat('CONFIRMATION',['The xy coordinates of the calibration points in ' num2str(n_ima) ' planes will be used'])
     597    for ifile=1:numel(coord_files)
     598    t=xmltree(coord_files{ifile});
     599    s=convert(t);%convert to matlab structure
     600        if isfield(s,'GeometryCalib')
     601            if isfield(s.GeometryCalib,'SourceCalib')
     602                if isfield(s.GeometryCalib.SourceCalib,'PointCoord')
     603                PointCoord=s.GeometryCalib.SourceCalib.PointCoord;
     604                Coord_file=zeros(length(PointCoord),5);%default
     605                for i=1:length(PointCoord)
     606                    line=str2num(PointCoord{i});
     607                    Coord_file(i,4:5)=line(4:5);%px x
     608                    Coord_file(i,1:3)=line(1:3);%phys x
     609                end
     610                eval(['x_' num2str(ifile+1) '=Coord_file(:,4:5)'';']);
     611                eval(['x_' num2str(ifile+1) '(2,:)=ny-x_' num2str(ifile+1) '(2,:);' ]);
     612                eval(['X_' num2str(ifile+1) '=Coord_file(:,1:3)'';']);
     613                end
     614            end
     615        end
     616    end
     617end
     618n_ima=numel(coord_files)+1;
    577619est_dist=[1;0;0;0;0];
    578620est_aspect_ratio=1;
     
    700742GeometryCalib.CoordUnit=[];% default value, to be updated by the calling function
    701743GeometryCalib.Tx_Ty_Tz=[calibdat(12) calibdat(13) calibdat(14)];
    702 Rx_Ry_Rz=calibdat([15:17]);
     744Rx_Ry_Rz=calibdat(15:17);
    703745sa = sin(Rx_Ry_Rz(1)) ;
    704746ca=cos(Rx_Ry_Rz(1));
     
    771813RootPath='';
    772814RootFile='';
    773 if ~isempty(hhuvmat.RootPath)& ~isempty(hhuvmat.RootFile)
     815if ~isempty(hhuvmat.RootPath)&& ~isempty(hhuvmat.RootFile)
    774816    testhandle=1;
    775817    RootPath=get(hhuvmat.RootPath,'String');
     
    834876str2=get(handles.YObject,'String');
    835877str3=get(handles.ZObject,'String');
    836 if ~isempty(str1) & ~isequal(double(str1),32) & (isempty(str3)|isequal(double(str3),32))
     878if ~isempty(str1) && ~isequal(double(str1),32) && (isempty(str3)||isequal(double(str3),32))
    837879    str3='0';%put z to 0 by default
    838880end
     
    10661108
    10671109%reorder the last two points (the two first in the list) if needed
    1068 angles=angle((corners_X-corners_X(1))+i*(corners_Y-corners_Y(1)));
     1110angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
    10691111if abs(angles(4)-angles(2))>abs(angles(3)-angles(2))
    10701112      X_end=corners_X(4);
     
    10921134D = [ corners_X , corners_Y ];
    10931135D = reshape (D', 8 , 1 );
    1094 l = inv(B' * B) * B' * D;
     1136%l = inv(B' * B) * B' * D;
     1137l = (B' * B)\B' * D;
    10951138Amat = reshape([l(1:6)' 0 0 1 ],3,3)';
    10961139C = [l(7:8)' 1];
     
    11281171Data.CoordType='px';
    11291172Calib.GeometryCalib=GeometryCalib;
    1130 DataOut=phys(Data,Calib)
     1173DataOut=phys(Data,Calib);
    11311174rmpath(fullfile(path_UVMAT,'transform_field'))
    11321175Amod=DataOut.A;
     
    11541197Dx=(Rangx(2)-Rangx(1))/(npxy(2)-1); %x mesh in real space
    11551198Dy=(Rangy(2)-Rangy(1))/(npxy(1)-1); %y mesh in real space
    1156 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
    1157 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
     1199ind_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
     1200ind_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
    11581201nbpoints=size(T,1);
    11591202for ipoint=1:nbpoints
     
    14051448% --------------------------------------------------------------------
    14061449function MenuImportPoints_Callback(hObject, eventdata, handles)
    1407 fileinput=browse_xml(hObject, eventdata, handles)
     1450fileinput=browse_xml(hObject, eventdata, handles);
    14081451if isempty(fileinput)
    14091452    return
     
    14371480function MenuImportAll_Callback(hObject, eventdata, handles)
    14381481%------------------------------------------------------------------------
    1439 fileinput=browse_xml(hObject, eventdata, handles)
     1482fileinput=browse_xml(hObject, eventdata, handles);
    14401483if ~isempty(fileinput)
    14411484    loadfile(handles,fileinput)
     
    14461489function MenuGridFile_Callback(hObject, eventdata, handles)
    14471490% -----------------------------------------------------------------------
    1448 inputfile=browse_xml(hObject, eventdata, handles)
     1491inputfile=browse_xml(hObject, eventdata, handles);
    14491492listfile=get(handles.coord_files,'string');
    14501493if isequal(listfile,{''})
    14511494    listfile={inputfile};
    14521495else
    1453     listfile=[listfile;{inputfile}]%update the list of coord files
     1496    listfile=[listfile;{inputfile}];%update the list of coord files
    14541497end
    14551498set(handles.coord_files,'string',listfile);
     
    15001543function loadfile(handles,fileinput)
    15011544%------------------------------------------------------------------------
    1502 fileinput
    1503 [s,errormsg]=imadoc2struct(fileinput,'GeometryCalib')
     1545[s,errormsg]=imadoc2struct(fileinput,'GeometryCalib');
    15041546GeometryCalib=s.GeometryCalib;
    15051547fx=1;fy=1;Cx=0;Cy=0;kc=0; %default
     
    15751617kc=0;
    15761618if isfield(GeometryCalib,'kc')
    1577     kc=GeometryCalib.kc %* GeometryCalib.focal*GeometryCalib.focal;
     1619    kc=GeometryCalib.kc; %* GeometryCalib.focal*GeometryCalib.focal;
    15781620end
    15791621set(handles.fx,'String',num2str(fx,5))
  • trunk/src/msgbox_uvmat.m

    r12 r121  
    2626                   'gui_LayoutFcn',  [] , ...
    2727                   'gui_Callback',   []);
    28 if nargin && ischar(varargin{1})
    29     gui_State.gui_Callback = str2func(varargin{1});
     28if nargin && ischar(varargin{1}) && ~isempty(regexp(varargin{1},'_Callback','once'))
     29    gui_State.gui_Callback = str2func(varargin{1});%for running msgbox_uvmat from a Callback
    3030end
    3131
  • trunk/src/uvmat.m

    r120 r121  
    28042804    dt=UvData.dt;
    28052805end
    2806 if isequal(dt,0)
     2806if isempty(dt)||isequal(dt,0)
    28072807    set(handles.Dt_txt,'String','')
    28082808else
Note: See TracChangeset for help on using the changeset viewer.