Ignore:
Timestamp:
Feb 8, 2022, 1:58:47 PM (2 years ago)
Author:
sommeria
Message:

bug corrected in 3D calibration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r1112 r1113  
    5252% Edit the above text to modify the response to help geometry_calib
    5353
    54 % Last Modified by GUIDE v2.5 20-Sep-2018 19:04:30
     54% Last Modified by GUIDE v2.5 05-Feb-2022 22:24:55
    5555
    5656% Begin initialization code - DO NOT edit
     
    232232
    233233%% Apply calibration
    234 [GeometryCalib,index,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
     234[GeometryCalib,index,ind_removed]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration
    235235if isempty(GeometryCalib)
    236236    return
     
    245245GeometryCalib.SourceCalib.PointCoord=Coord;
    246246
    247 %% display calibration results on the GUI geometry_calib
    248 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters
    249 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters
    250 %     (rotation and translation of camera with  respect to the phys coordinates)
    251 
    252247%% set the default plane and display the calibration data errors for validation
    253248answer=msgbox_uvmat('INPUT_Y-N',{'store calibration data';...
    254249    ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];...
    255250    ['Error max (along x,y)=' num2str(GeometryCalib.ErrorMax) ' pixels'];
    256     [num2str(numel(ind_removed)) ' points removed']});
    257 % SliceCoord_ref=[0 0 0]; %default reference plane
     251    [num2str(numel(ind_removed)) ' points removed with ErrorMax > 3 rms']});
    258252checkslice=0;
    259253if strcmp(answer,'Yes') %store the calibration data
     254    display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters on the GUI geometry_calib
     255    display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters on the GUI geometry_calib
    260256    Z=Coord(:,3);
    261257    if strcmp(calib_cell{val}(1:2),'3D') && isequal(max(Z),min(Z))%set the plane position for 3D (projection) calibration
     
    348344        errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file
    349345        if checkslice
    350                     errormsg=update_imadoc(Slice,outputfile,'Slice');% introduce the slice position in the xml file
     346            errormsg=update_imadoc(Slice,outputfile,'Slice');% introduce the slice position in the xml file
    351347        end
    352348        if ~strcmp(errormsg,'')
    353349            msgbox_uvmat('ERROR',errormsg);
    354350        end
    355        
     351
    356352        %% display image with new calibration in the currently opened uvmat GUI
    357353        FieldList=get(hhuvmat.FieldName,'String');
     
    397393%------------------------------------------------------------------------
    398394% --- activate calibration and store parameters in ouputfile .
    399 function [GeometryCalib,ind_max,ind_removed,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)
     395function [GeometryCalib,ind_max,ind_removed]=calibrate(Coord,CalibFcn,Intrinsic)
    400396%------------------------------------------------------------------------
    401397
    402398index=[];
    403399GeometryCalib=[];
    404 ind_max=[];ind_removed=[];Z_plane=[];
     400ind_max=[];ind_removed=[];
    405401% apply the calibration, whose type is selected in  handles.calib_type
    406402CoordFlip=Coord;
    407 CoordFlip(:,3)=-Coord(:,3);
     403CoordFlip(:,3)=Coord(:,3);% the calibration function assume a z ccordinate along the camera view, opposite to ours
    408404if ~isempty(Coord)
    409405    GeometryCalib=feval(CalibFcn,CoordFlip,Intrinsic);
     
    414410    return
    415411end
    416 Z_plane=[];
    417412
    418413% estimate calibration error rms and max
    419 % X=Coord(:,1);
    420 % Y=Coord(:,2);
    421 Z=Coord(:,3);
    422414x_ima=Coord(:,4);
    423415y_ima=Coord(:,5);
    424 [Xpoints,Ypoints]=px_XYZ(GeometryCalib,[],Coord(:,1),Coord(:,2),Coord(:,3));% convention of downward z coordinate (facing the camera)
     416[Xpoints,Ypoints]=px_XYZ(GeometryCalib,[],Coord(:,1),Coord(:,2),Coord(:,3));
    425417GeometryCalib.ErrorRms(1)=sqrt(mean((Xpoints-x_ima).*(Xpoints-x_ima)));
    426418GeometryCalib.ErrorRms(2)=sqrt(mean((Ypoints-y_ima).*(Ypoints-y_ima)));
     
    430422ind_max=index(ind_dim); % mark the index with maximum deviation
    431423
    432 % detect bad calibration points, marked by indices ind_bad, if the
     424% detect bad calibration points, marked by indices ind_removed, if the
    433425% difference of actual image coordinates and those given by calibration is
    434 % greater than 2 pixels and greater than 4 rms.
     426% greater than 2 pixels and greater than 3 rms.
    435427check_x=abs(Xpoints-x_ima)>max(2,3*GeometryCalib.ErrorRms(1));
    436428check_y=abs(Ypoints-y_ima)>max(2,3*GeometryCalib.ErrorRms(2));
    437 ind_removed=find(check_x | check_y)
     429ind_removed=find(check_x | check_y);
    438430% repeat calibration without the excluded points:
    439431if ~isempty(ind_removed)
    440432    Coord(ind_removed,:)=[];
    441     GeometryCalib=feval(CalibFcn,Coord,Intrinsic);
     433    CoordFlip=Coord;
     434    CoordFlip(:,3)=Coord(:,3);% the calibration function assume a z ccordinate along the camera view, opposite to ours
     435    GeometryCalib=feval(CalibFcn,CoordFlip,Intrinsic);
    442436    X=Coord(:,1);
    443437    Y=Coord(:,2);
     
    450444end
    451445GeometryCalib.ErrorMax=ErrorMax;
    452 % %set the Z position of the reference plane used for calibration
    453 % if isequal(max(Z),min(Z))%Z constant
    454 %     Z_plane=Z(1);
    455 %     GeometryCalib.NbSlice=1;
    456 %     GeometryCalib.SliceCoord=[0 0 Z_plane];
    457 % end
    458446
    459447
     
    468456[px]=polyfit(X,x_ima,1);
    469457[py]=polyfit(Y,y_ima,1);
    470 % T_x=px(2);
    471 % T_y=py(2);
    472458GeometryCalib.CalibrationType='rescale';
    473459GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y
     
    620606run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));% apply fct 'toolbox_calib/go_calib_optim'
    621607if exist('Rc_1','var')
    622     GeometryCalib.CalibrationType='3D_linear';
     608    GeometryCalib.CalibrationType='3D_extrinsic';
    623609    GeometryCalib.fx_fy=fc';
    624610    GeometryCalib.Cx_Cy=cc';
     
    698684
    699685if exist('Rc_1','var')
    700     GeometryCalib.CalibrationType='3D_quadr';
     686    GeometryCalib.CalibrationType='3D_extrinsic';
    701687    GeometryCalib.fx_fy=fc';
    702688    GeometryCalib.Cx_Cy=cc';
     
    11631149
    11641150% --------------------------------------------------------------------
    1165 function MenuFlip_x_Callback(hObject, eventdata, handles)
     1151function MenuFlip_xy_Callback(hObject, eventdata, handles)
    11661152Coord=get(handles.ListCoord,'Data');
    11671153Coord(:,1)=-Coord(:,1);
     1154Coord(:,2)=-Coord(:,2);
    11681155set(handles.ListCoord,'Data',Coord)
    11691156
    11701157% --------------------------------------------------------------------
    1171 function MenuFlip_y_Callback(hObject, eventdata, handles)
     1158function MenuFlip_xz_Callback(hObject, eventdata, handles)
    11721159Coord=get(handles.ListCoord,'Data');
    1173 Coord(:,2)=-Coord(:,2);
     1160Coord(:,1)=-Coord(:,1);
     1161Coord(:,3)=-Coord(:,3);
    11741162set(handles.ListCoord,'Data',Coord)
    11751163
Note: See TracChangeset for help on using the changeset viewer.