Changeset 1113 for trunk/src/geometry_calib.m
 Timestamp:
 Feb 8, 2022, 1:58:47 PM (2 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/geometry_calib.m
r1112 r1113 52 52 % Edit the above text to modify the response to help geometry_calib 53 53 54 % Last Modified by GUIDE v2.5 20Sep2018 19:04:3054 % Last Modified by GUIDE v2.5 05Feb2022 22:24:55 55 55 56 56 % Begin initialization code  DO NOT edit … … 232 232 233 233 %% Apply calibration 234 [GeometryCalib,index,ind_removed ,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration234 [GeometryCalib,index,ind_removed]=calibrate(Coord,CalibFcn,Intrinsic);% apply calibration 235 235 if isempty(GeometryCalib) 236 236 return … … 245 245 GeometryCalib.SourceCalib.PointCoord=Coord; 246 246 247 %% display calibration results on the GUI geometry_calib248 display_intrinsic(GeometryCalib,handles)%display calibration intrinsic parameters249 display_extrinsic(GeometryCalib,handles)%display calibration extrinsic parameters250 % (rotation and translation of camera with respect to the phys coordinates)251 252 247 %% set the default plane and display the calibration data errors for validation 253 248 answer=msgbox_uvmat('INPUT_YN',{'store calibration data';... 254 249 ['Error rms (along x,y)=' num2str(GeometryCalib.ErrorRms) ' pixels'];... 255 250 ['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']}); 258 252 checkslice=0; 259 253 if 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 260 256 Z=Coord(:,3); 261 257 if strcmp(calib_cell{val}(1:2),'3D') && isequal(max(Z),min(Z))%set the plane position for 3D (projection) calibration … … 348 344 errormsg=update_imadoc(GeometryCalib,outputfile,'GeometryCalib');% introduce the calibration data in the xml file 349 345 if checkslice 350 346 errormsg=update_imadoc(Slice,outputfile,'Slice');% introduce the slice position in the xml file 351 347 end 352 348 if ~strcmp(errormsg,'') 353 349 msgbox_uvmat('ERROR',errormsg); 354 350 end 355 351 356 352 %% display image with new calibration in the currently opened uvmat GUI 357 353 FieldList=get(hhuvmat.FieldName,'String'); … … 397 393 % 398 394 %  activate calibration and store parameters in ouputfile . 399 function [GeometryCalib,ind_max,ind_removed ,Z_plane]=calibrate(Coord,CalibFcn,Intrinsic)395 function [GeometryCalib,ind_max,ind_removed]=calibrate(Coord,CalibFcn,Intrinsic) 400 396 % 401 397 402 398 index=[]; 403 399 GeometryCalib=[]; 404 ind_max=[];ind_removed=[]; Z_plane=[];400 ind_max=[];ind_removed=[]; 405 401 % apply the calibration, whose type is selected in handles.calib_type 406 402 CoordFlip=Coord; 407 CoordFlip(:,3)= Coord(:,3);403 CoordFlip(:,3)=Coord(:,3);% the calibration function assume a z ccordinate along the camera view, opposite to ours 408 404 if ~isempty(Coord) 409 405 GeometryCalib=feval(CalibFcn,CoordFlip,Intrinsic); … … 414 410 return 415 411 end 416 Z_plane=[];417 412 418 413 % estimate calibration error rms and max 419 % X=Coord(:,1);420 % Y=Coord(:,2);421 Z=Coord(:,3);422 414 x_ima=Coord(:,4); 423 415 y_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)); 425 417 GeometryCalib.ErrorRms(1)=sqrt(mean((Xpointsx_ima).*(Xpointsx_ima))); 426 418 GeometryCalib.ErrorRms(2)=sqrt(mean((Ypointsy_ima).*(Ypointsy_ima))); … … 430 422 ind_max=index(ind_dim); % mark the index with maximum deviation 431 423 432 % detect bad calibration points, marked by indices ind_ bad, if the424 % detect bad calibration points, marked by indices ind_removed, if the 433 425 % difference of actual image coordinates and those given by calibration is 434 % greater than 2 pixels and greater than 4rms.426 % greater than 2 pixels and greater than 3 rms. 435 427 check_x=abs(Xpointsx_ima)>max(2,3*GeometryCalib.ErrorRms(1)); 436 428 check_y=abs(Ypointsy_ima)>max(2,3*GeometryCalib.ErrorRms(2)); 437 ind_removed=find(check_x  check_y) 429 ind_removed=find(check_x  check_y); 438 430 % repeat calibration without the excluded points: 439 431 if ~isempty(ind_removed) 440 432 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); 442 436 X=Coord(:,1); 443 437 Y=Coord(:,2); … … 450 444 end 451 445 GeometryCalib.ErrorMax=ErrorMax; 452 % %set the Z position of the reference plane used for calibration453 % if isequal(max(Z),min(Z))%Z constant454 % Z_plane=Z(1);455 % GeometryCalib.NbSlice=1;456 % GeometryCalib.SliceCoord=[0 0 Z_plane];457 % end458 446 459 447 … … 468 456 [px]=polyfit(X,x_ima,1); 469 457 [py]=polyfit(Y,y_ima,1); 470 % T_x=px(2);471 % T_y=py(2);472 458 GeometryCalib.CalibrationType='rescale'; 473 459 GeometryCalib.fx_fy=[px(1) py(1)];%.fx_fy corresponds to pxcm along x and y … … 620 606 run(fullfile(path_UVMAT,'toolbox_calib','go_calib_optim'));% apply fct 'toolbox_calib/go_calib_optim' 621 607 if exist('Rc_1','var') 622 GeometryCalib.CalibrationType='3D_ linear';608 GeometryCalib.CalibrationType='3D_extrinsic'; 623 609 GeometryCalib.fx_fy=fc'; 624 610 GeometryCalib.Cx_Cy=cc'; … … 698 684 699 685 if exist('Rc_1','var') 700 GeometryCalib.CalibrationType='3D_ quadr';686 GeometryCalib.CalibrationType='3D_extrinsic'; 701 687 GeometryCalib.fx_fy=fc'; 702 688 GeometryCalib.Cx_Cy=cc'; … … 1163 1149 1164 1150 %  1165 function MenuFlip_x _Callback(hObject, eventdata, handles)1151 function MenuFlip_xy_Callback(hObject, eventdata, handles) 1166 1152 Coord=get(handles.ListCoord,'Data'); 1167 1153 Coord(:,1)=Coord(:,1); 1154 Coord(:,2)=Coord(:,2); 1168 1155 set(handles.ListCoord,'Data',Coord) 1169 1156 1170 1157 %  1171 function MenuFlip_ y_Callback(hObject, eventdata, handles)1158 function MenuFlip_xz_Callback(hObject, eventdata, handles) 1172 1159 Coord=get(handles.ListCoord,'Data'); 1173 Coord(:,2)=Coord(:,2); 1160 Coord(:,1)=Coord(:,1); 1161 Coord(:,3)=Coord(:,3); 1174 1162 set(handles.ListCoord,'Data',Coord) 1175 1163
Note: See TracChangeset
for help on using the changeset viewer.