source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/image3dstiching/BundleAdjustment/SparseBAWraper.m @ 37

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

Added original make3d

File size: 4.2 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function [NewR NewT NewX_obj NewX_im dist1 dist2]=SparseBAWraper(defaultPara, R, T, x_im, X_obj, ImgInfo, FlagDisp)
40
41% This function is the wraper function to call eucsbademo
42% which perform the sparse bundle adjustment given
43% Input:
44%       1) defaultPara - camera intrinsic paramter in calib.txt
45%       2) Rotation adn Translation - camera viewpoint in cams.txt
46%       3) X_obj - object 3D position in pts.txt
47% note: for the format of calib.txt cams.txt pts.txt
48%       please see README.txt in sba-1.3/demo/
49%
50% Return:
51%       1)
52
53Img1 = strrep(ImgInfo(1).ExifInfo.name,'.jpg','');
54Img2 = strrep(ImgInfo(2).ExifInfo.name,'.jpg','');
55NumObj = length(X_obj);
56
57% calculate qauternion
58[axis_angle qauternion] = Rotation2Q(R(1:3,:));
59
60% Write 3 .txt files in Fdir/info/
61% 1) cams.txt
62fp = fopen([defaultPara.Fdir '/info/cams'],'w');
63fprintf(fp, '1.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000\n'); % the reference camera
64fprintf(fp, '%.6g ', qauternion); % print the quaternion of the second camera
65fprintf(fp, '%.6g ', T(1:3)); % print the translation of the second camera
66fclose(fp);
67
68% 2) pts.txt
69fp = fopen([defaultPara.Fdir '/info/pts'],'w');
70fprintf(fp, '# X Y Z  nframes  frame0 x0 y0  frame1 x1 y1 ... \n'); % the reference camera
71for i = 1:NumObj
72        fprintf(fp, '%.6g ', X_obj(:,i));
73        fprintf(fp, '2 0 ');
74        fprintf(fp, '%.6g ', x_im(1:2,i));
75        fprintf(fp, '1 ');
76        fprintf(fp, '%.6g ', x_im(3:4,i));
77        fprintf(fp, '\n');
78end
79fclose(fp);
80
81% 3) calib.txt
82fp = fopen([defaultPara.Fdir '/info/calib'],'w');
83fprintf(fp, '%.6g ', defaultPara.InrinsicK1(1,:));
84fprintf(fp, '\n');
85fprintf(fp, '%.6g ', defaultPara.InrinsicK1(2,:));
86fprintf(fp, '\n');
87fprintf(fp, '%.6g ', defaultPara.InrinsicK1(3,:));
88fprintf(fp, '\n');
89fclose(fp);
90
91%--------------------------------------------------
92
93% call sba to solve sfm
94sbaInfoPath = [defaultPara.Fdir '/info/'];
95outputName = [ Img1 '-' Img2 '.out'];
96system(['../third_party/sba-1.3/demo/eucsbademo ' sbaInfoPath 'cams ' sbaInfoPath 'pts ' sbaInfoPath 'calib > ' sbaInfoPath outputName]);
97
98% Read in the result R T and X_obj x_im
99[NewR NewT NewX_im NewX_obj] = readBA([sbaInfoPath outputName]);
100% system(['rm ' sbaInfoPath outputName]);
101
102temp = defaultPara.InrinsicK1*NewX_obj;
103NewX_im(1:2,:) = temp(1:2,:)./repmat( temp(3,:),2,1);
104temp = defaultPara.InrinsicK2*(NewR*NewX_obj + repmat(NewT,1,length(NewX_obj)));
105NewX_im(3:4,:) = temp(1:2,:)./repmat( temp(3,:),2,1);
106
107re = NewX_im - x_im;
108dist1 = sqrt(sum(re(1:2,:).^2, 1));
109dist2 = sqrt(sum(re(3:4,:).^2, 1));
110
111return;
Note: See TracBrowser for help on using the repository browser.