source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamSelfCal/MartinecPajdla/utils/load_scene.m @ 37

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

Added original make3d

File size: 8.1 KB
Line 
1%load_scene Load data of a real scene.
2%
3%   function [M,I] = load_scene([show[, load_all_images]])
4%
5%   global scene.ID ... contains the number of the scene to load
6
7function [M,I] = load_scene(show, load_all_images)
8
9if nargin < 1, show = 0; end
10 if nargin < 2, load_all_images = 0; end
11
12global scene Matlab_data;
13
14if scene.ID == 1 % artificial cubes
15  if ~isfield(scene,'to_print')
16    scene.to_print = 0; end % 0..little markers + thin lines,
17                            % 1..big markers + thick lines
18  if ~isfield(scene,'load') | ~isfield(scene.load,'m')
19    scene.load.m = 5; end
20  if ~isfield(scene.load,'predef')
21    scene.load.predef = 0; end % 2 .. cubes like in the master thesis
22  if ~isfield(scene.load,'emptyness')
23    scene.load.emptyness = 0.05; end
24  [M,I,P0,X0,scene.lp,polys] = ...
25      create_cubes(2,scene.load.m,scene.load.predef,scene.load.emptyness,[],0);
26  M(k2idx(find(~I))) = NaN; return
27end
28
29if 1, dir = [ Matlab_data 'cmp/' ];   % data in my directory
30else  dir = '/data/3DR/Projrec/'; end
31
32scene.data_type = 'cmp';                                % data from Cmp
33scene.detection = 'manual';
34switch scene.ID
35 case 2,    scene.name =                              'House';
36  file='Domek/domek.cor'; %'OK.cor';
37                                    picDir='Domek'; %'tif';
38 case 3,    scene.name =                              'Corridor';
39  file='Coridor-Cake/coridorC.cor'; picDir='Coridor-Cake';
40 case 4,    scene.name =                              'Church';
41  file='Plec/Plec.cor';             picDir='Plec';
42 case 5,    scene.name =                              'Kampa';
43  file='Kampa/Kampa.cor';           picDir='Kampa';
44 case 6,    scene.name =                              'Cubes';
45  file='Kostky/Kostky.cor';         picDir='Kostky';
46 case 7,    scene.name =                              'puzzle';
47  file='adam/hlavolam.cor';         picDir='adam';
48 
49 otherwise                                              % data from Oxford:
50  scene.data_type = 'oxford';
51  scene.detection = 'Harris'' operator';
52  dir = [ Matlab_data 'oxford/' ];
53  decimals=3;
54  switch scene.ID
55   case 101,      scene.name =                        'House (Oxford)';
56    file='house'; last_index=9;  picDir='house/';
57   case 102,  scene.name =                            'Corridor (Oxford)';
58    file='bt';    last_index=10; picDir='corridor/';
59   
60   otherwise                                              % data from Oxford:
61    scene.data_type = 'oxford_';
62    switch scene.ID
63     case 170,  scene.name =                            'Dinosaur (Oxford)';
64      file='viff';  last_index=36; picDir='dinosaur/';
65   
66     otherwise
67      scene.data_type = 'leuven';
68      scene.detection = 'Harris'' operator';
69      dir = [ Matlab_data 'leuven/' ];
70      decimals=3; first_index = 0; ext='';
71      switch scene.ID
72       case 201,      scene.name =                        'Castle (Leuven)';
73        file='viff'; last_index=21;  picDir='Castle/';
74       case 202,      scene.name =                        'Temple (Leuven)';
75        file='temple'; first_index=2; last_index=6;
76        decimals=2; ext='.pgm'; picDir='Temple/';
77       otherwise
78        scene.data_type = 'boujou';
79        scene.detection = 'boujou';
80        dir = [ Matlab_data 'boujou/' ];
81        switch scene.ID
82         case 301,      scene.name =                        'Road in Forest';
83          file='road'; last_index=1; picDir='Road_in_Forest/';
84         case 302,      scene.name =                        'Corridor (CMP)';
85          file='corridorvideo'; last_index=1; picDir='Corridor_CMP/';
86         case 303,      scene.name =                        'Fish eye round';
87          file='fish_ray4in_im'; last_index=1; picDir='Fish_eye_round/fish_ray_4_in/';
88          decimals=4;
89         otherwise
90          disp(sprintf('Error: undefined scene with ID %d.', scene.ID));
91          M = []; I = []; return;
92        end
93      end
94    end
95  end
96end
97
98switch scene.data_type
99 case 'cmp'
100  if ~exist('CORR'), load ([dir file],'-mat');
101    CORR = CORR_EXCHANGE;
102    CORR.d.picturesDir=[dir picDir];
103  end
104  x              = CORR.d.corr(:,:,1)';
105  y              = CORR.d.corr(:,:,2)';
106  [m n]          = size(x);
107  I              = x~=0;
108  M(1:3:3*m,1:n) = x;
109  M(2:3:3*m,1:n) = y;
110  M(3:3:3*m,1:n) = ones(size(I));
111
112  % kill unknown data
113  M(k2i(find(~I))) = NaN;
114 case 'oxford'
115  [M,I]      = oxford2mm([dir picDir file], last_index);
116  M          = e2p(M);  % add ones as homogenous coordinates
117  [m n]      = size(I);
118 case 'oxford_'
119  [M,I]      = oxford_2mm([dir picDir file]);
120  M          = e2p(M);  % add ones as homogenous coordinates
121  [m n]      = size(I);
122 case 'leuven'
123  scene.mm_file = [ dir picDir kill_spaces(scene.name) '.mat' ];
124  convert = 1; to_file = 0;
125  if 1 %scene.ID == 201  % `Leuven's castle' is too big to compute always again
126    to_file = 1;
127    convert = ~file_exists(scene.mm_file); % whether file doesn't exist
128  end
129  if convert
130    [M,I]      = leuven2mm([dir picDir], file, last_index, first_index, ...
131                           decimals, ext);
132    if to_file
133      disp([ 'Saving to precompiled file ' scene.mm_file '...' ]);
134      a=[ 'save ' scene.mm_file ' M I']; eval(a); end
135  else
136    disp([ 'Loading from precompiled file ' scene.mm_file '...' ]);
137    a=[ 'load ' scene.mm_file ' M I']; eval(a);
138  end
139  M          = e2p(M);  % add ones as homogenous coordinates
140  [m n]      = size(I);
141 
142 case 'boujou'
143  [M,I]      = boujou2mm([dir picDir file '.txt']);
144  fprintf(1,'Converting from Eucledian to projective coordinates...'); tic;
145  M          = e2p(M);  % add ones as homogenous coordinates
146  disp(['(' num2str(toc) ' sec)']);
147  [m n]      = size(I);
148end
149
150
151% take out some points and pictures
152  % take out some pictures
153  if scene.ID==3, % take out the first picture
154    I=I([2:8],:); M=M([2*3-2:3*8],:); m=m-1;
155  end
156   
157  % take out points which are just in two images or less
158  if 1 %scene.ID==3,
159    out  = find(sum(I)<=1); %<=2
160    stay = setdiff(1:n,out);  M     = M(:,stay);
161    I    = I(:,stay);         [m n] = size(I);
162  end
163 
164  % take out points which are not in the first image
165  %if scene.ID==2, stay=find(I(1,:) == 1); M=M(:,stay); I=I(:,stay); end
166
167
168if strcmp(scene.data_type, 'cmp'),
169  decimals = ceil(log10(m + .1));
170end
171format = sprintf('%%0%dd',decimals);
172
173% load images
174changed = 0;
175if show  |  load_all_images, to_load = m; else to_load = 1; end
176if ~isfield(scene,'img') | size(scene.img,2)~=to_load,scene.img{to_load}=[];end
177for k=1:to_load
178  switch scene.data_type
179   case 'cmp'
180    nos       = sprintf(format,k);
181    InputFile = strcat(CORR.d.picturesDir,filesep,CORR.d.filePrefix,...
182                       nos,'.', CORR.d.fileExt);
183   case 'oxford'
184    InputFile = [[dir picDir file] '.' num2str(k-1,format) '.png' ]; % '.pgm'
185                                                 % doesn't work in Matlab
186   case 'oxford_'
187    InputFile = [[dir picDir file] '.' num2str(k-1,format) '.png' ]; % '.ppm'
188                                                 % doesn't work in Matlab
189   case 'leuven'
190    InputFile = [[dir picDir file] '.' num2str(k-1+first_index,format) ...
191                                      '.png' ]; % '.pgm' doesn't work in Matlab
192   case 'boujou'
193    InputFile = [[dir picDir file] '.' num2str(k-1+first_index,format) ...
194                                      '.jpg' ];
195   otherwise
196    disp('Unknown data type');
197  end
198
199  if isempty(scene.img{k})  |  ~isfield(scene.img{k}, 'file') ...
200        |  ~strcmp(scene.img{k}.file, InputFile)
201    disp(sprintf('Loading %s...', InputFile));
202    scene.img{k}.file = InputFile;
203    scene.img{k}.data = imread(InputFile);
204   
205    scene.image_size = size(scene.img{1}.data);
206    if scene.ID == 2 % Domek
207      % pictures are too big therefore some smaller ones are taken
208      scene.image_size_show = scene.image_size;
209      scene.image_size(1:2) = [ 2003 2952 ];
210    end
211   
212    changed=1;
213  end
214end
215
216tiles_y=4; if m/tiles_y > 2, tiles_x = 6; else tiles_x = 4; end
217global tiles; tiles_set(tiles_x, tiles_y);
218
219if show  &  changed    % show
220  for k=1:m
221    fig = figure(10+k);
222    [x y] = tiles2xy(k); subfig(tiles.y, tiles.x, y*tiles.x+x+1, fig);
223    cla; image(scene.img{k}.data); hold on;
224    drawpointsI(M([k*3-2,k*3-1],:),[1;1]*I(k,:));
225  end
226end
Note: See TracBrowser for help on using the repository browser.