source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamSelfCal/OutputFunctions/savecalpar.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 3.1 KB
Line 
1% SaveCalPar   save calibration parameters in different formats
2%
3% [Cst,Rot] = savecalpar(P,config)
4% P ... 3*CAM x 4 matrix containing result of selfcalibration, see EUCLIDIZE
5% config ... configuration structure, see CONFIGDATA
6%
7%
8% Cst ... CAMSx3   matrix containing the camera centers (in world coord.)
9% Rot ... 3*CAMSx3 matrix containing camera rotation matrices
10
11% $Author: svoboda $
12% $Revision: 2.0 $
13% $Id: savecalpar.m,v 2.0 2003/06/19 12:07:03 svoboda Exp $
14% $State: Exp $
15
16
17function [Cst,Rot] = savecalpar(P,config)
18
19idxused = config.cal.cams2use;
20
21CAMS = size(P,1)/3;
22
23Cst = zeros(CAMS,3);
24Pst = zeros(3*CAMS,3);
25Rot = [];
26for i=1:CAMS,
27  % do not save P matrices in separate files
28  if 1
29        Pmat = P(i*3-2:i*3,:);
30        save(sprintf(config.files.CalPmat,idxused(i)),'Pmat','-ASCII');
31  end
32  sc = norm(P(i*3,1:3));
33  % first normalize the Projection matrices to get normalized pixel points
34  P(i*3-2:i*3,:) = P(i*3-2:i*3,:)./sc;
35  % decompose the matrix by using rq decomposition 
36  [K,R] = rq(P(i*3-2:i*3,1:3));
37  tvec= inv(K)*P(i*3-2:i*3,4);                  % translation vector
38  C       = -R'*tvec;                                           % camera center
39  % Stephi calib params
40  Pstephi                  = R'*inv(K);         
41  Pst(i*3-2:i*3,:) = Pstephi;
42  Cst(i,:)                 = C';               
43  % Stephi requires to save the pars in more "wordy" form
44  fid = fopen(sprintf(config.files.StCalPar,idxused(i)),'wt');
45  if ~fid
46        error('SaveCalPar: The camera cal file cannot be opened');
47  else
48        fprintf(fid,'C1 = %f \n', C(1));
49        fprintf(fid,'C2 = %f \n', C(2));
50        fprintf(fid,'C3 = %f \n', C(3));
51        fprintf(fid,'\n');
52        fprintf(fid,'P11 = %f \n', Pstephi(1,1));
53        fprintf(fid,'P12 = %f \n', Pstephi(1,2));
54        fprintf(fid,'P13 = %f \n', Pstephi(1,3));
55        fprintf(fid,'P21 = %f \n', Pstephi(2,1));
56        fprintf(fid,'P22 = %f \n', Pstephi(2,2));
57        fprintf(fid,'P23 = %f \n', Pstephi(2,3));
58        fprintf(fid,'P31 = %f \n', Pstephi(3,1));
59        fprintf(fid,'P32 = %f \n', Pstephi(3,2));
60        fprintf(fid,'P33 = %f \n', Pstephi(3,3));
61        fclose(fid);
62  end
63  Rot    = [Rot;R];
64  % Prithwijit requires to save the pars in more "wordy" form
65  if 0 % do not save in the Prithwijit format
66        fid = fopen(sprintf(config.files.CalPar,idxused(i)),'wt');
67        if ~fid
68          error('SaveCalPar: The camera cal file cannot be opened');
69        else
70          fprintf(fid,'R11 = %f \n',R(1,1));
71          fprintf(fid,'R12 = %f \n',R(1,2));
72          fprintf(fid,'R13 = %f \n',R(1,3));
73          fprintf(fid,'R21 = %f \n',R(2,1));
74          fprintf(fid,'R22 = %f \n',R(2,2));
75          fprintf(fid,'R23 = %f \n',R(2,3));
76          fprintf(fid,'R31 = %f \n',R(3,1));
77          fprintf(fid,'R32 = %f \n',R(3,2));
78          fprintf(fid,'R33 = %f \n',R(3,3));
79          fprintf(fid,'\n');
80          fprintf(fid,'t11 = %f \n',tvec(1));
81          fprintf(fid,'t21 = %f \n',tvec(2));
82          fprintf(fid,'t31 = %f \n',tvec(3));
83          fprintf(fid,'\n');
84          fprintf(fid,'K11 = %f \n',K(1,1));
85          fprintf(fid,'K12 = %f \n',K(1,2));
86          fprintf(fid,'K13 = %f \n',K(1,3));
87          fprintf(fid,'K21 = %f \n',K(2,1));
88          fprintf(fid,'K22 = %f \n',K(2,2));
89          fprintf(fid,'K23 = %f \n',K(2,3));
90          fprintf(fid,'K31 = %f \n',K(3,1));
91          fprintf(fid,'K32 = %f \n',K(3,2));
92          fprintf(fid,'K33 = %f \n',K(3,3));
93          fprintf(fid,'\n');
94          fclose(fid);
95        end
96  end
97end
98
99% save Stehpi params
100save(config.files.Pst,'Pst','-ASCII');
101save(config.files.Cst,'Cst','-ASCII');
Note: See TracBrowser for help on using the repository browser.