[37] | 1 | % loaddata ... load the input data |
---|
| 2 | % |
---|
| 3 | % loaded = loaddata(config) |
---|
| 4 | % |
---|
| 5 | % config ... configuration structure, see the CONFIGDATA |
---|
| 6 | % |
---|
| 7 | % M cameras and N frames |
---|
| 8 | % loaded.Ws ... 3M x N joint image matrix |
---|
| 9 | % .IdMat ... M x N point identification matrix |
---|
| 10 | % .Res ... M x 2 image resolutions |
---|
| 11 | % .Pmat ... {1xM} cell array of the projection matrices |
---|
| 12 | % |
---|
| 13 | % see the FindingPoint and MulticamSelfCalib for more details |
---|
| 14 | % |
---|
| 15 | % $Id: loaddata.m,v 2.2 2005/05/23 16:23:35 svoboda Exp $ |
---|
| 16 | |
---|
| 17 | function loaded = loaddata(config) |
---|
| 18 | |
---|
| 19 | USED_MULTIPROC = 0; % was the multipropcessing used? |
---|
| 20 | % if yes then multiple IdMat.dat and points.dat have to be loaded |
---|
| 21 | % setting to 1 it forces to read the multiprocessor data against the |
---|
| 22 | % monoprocessor see the IM2POINTS, IM2PMULTIPROC.PL |
---|
| 23 | |
---|
| 24 | %%% |
---|
| 25 | % read the data structures |
---|
| 26 | if ~USED_MULTIPROC |
---|
| 27 | try, |
---|
| 28 | Ws = load(config.files.points); % distorted points as found by Im2Points |
---|
| 29 | IdMat = load(config.files.IdMat); % see function im2points for detailed comments |
---|
| 30 | %%% |
---|
| 31 | % try,load the file with Images resolutions which is on of the output files |
---|
| 32 | % from finding LEDs procedure or take the pre-defined resolutions specified in the configdata |
---|
| 33 | try, Res = load(config.files.Res); catch, Res = repmat(config.imgs.res,size(IdMat,1),1); end |
---|
| 34 | catch |
---|
| 35 | warning('Data from mono-processor version not found, trying the multi-proc ones ...') |
---|
| 36 | USED_MULTIPROC=1; |
---|
| 37 | end |
---|
| 38 | end |
---|
| 39 | |
---|
| 40 | if USED_MULTIPROC |
---|
| 41 | pointsfiles = dir([config.files.points,'.*']); |
---|
| 42 | IdMatfiles = dir([config.files.IdMat,'.*']); |
---|
| 43 | Resfiles = dir([config.files.Res,'.*']); |
---|
| 44 | pp = []; |
---|
| 45 | for i=1:size(pointsfiles,1), |
---|
| 46 | W{i} = load([config.paths.data,pointsfiles(i).name],'-ASCII'); |
---|
| 47 | pp = [pp,size(W{i},2)]; |
---|
| 48 | IdM{i} = load([config.paths.data,IdMatfiles(i).name],'-ASCII'); |
---|
| 49 | try, Rs{i} = load([config.paths.data,Resfiles(i).name],'-ASCII'); catch, Rs{i} = repmat(config.imgs.res,size(IdM{i},1),1); end |
---|
| 50 | end |
---|
| 51 | % throw away some point to preserve consistency |
---|
| 52 | [minpp,minidx] = min(pp); |
---|
| 53 | if minpp == 0 |
---|
| 54 | error('loaddata: Problem in loading input data. Check CONFIGDATA, EXPNAME settings'); |
---|
| 55 | end |
---|
| 56 | % merge the matrices |
---|
| 57 | Ws = []; |
---|
| 58 | IdMat = []; |
---|
| 59 | Res = []; |
---|
| 60 | for i=1:size(pointsfiles,1), |
---|
| 61 | Ws = [Ws; W{i}(:,1:minpp)]; |
---|
| 62 | IdMat = [IdMat; IdM{i}(:,1:minpp)]; |
---|
| 63 | Res = [Res; Rs{i}]; |
---|
| 64 | end |
---|
| 65 | if isempty(Ws) | isempty(IdMat) |
---|
| 66 | error('Error in loading parallel data. Did you really use multi-processor version of finding points'); |
---|
| 67 | end |
---|
| 68 | end |
---|
| 69 | |
---|
| 70 | % oscar data hack. The projectors are handled as the cameras |
---|
| 71 | try,config.files.idxcams = [config.files.idxcams,config.files.idxproj]; catch, config.files.idxcams; end |
---|
| 72 | |
---|
| 73 | if size(Ws,1)/3 ~= size(config.files.idxcams,2) |
---|
| 74 | error('Problem in loading points data. Less or more data than expected found') |
---|
| 75 | end |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | %%% read the P matrices |
---|
| 79 | count = 1; |
---|
| 80 | for i=config.cal.cams2use, |
---|
| 81 | try,P = load(sprintf(config.files.CalPmat,i),'-ASCII'); catch, warning(sprintf('The calibration file config.files.CalPmat does not exist',i)); end; |
---|
| 82 | try,Pmat{count} = P; catch, warning('No P mat available'); end; |
---|
| 83 | count = count+1; |
---|
| 84 | end |
---|
| 85 | |
---|
| 86 | idx2use = zeros(size(config.cal.cams2use)); |
---|
| 87 | for i=1:size(config.cal.cams2use,2), |
---|
| 88 | idx2use(i) = find(config.cal.cams2use(i) == config.files.idxcams); |
---|
| 89 | end |
---|
| 90 | |
---|
| 91 | idx2use3 = []; |
---|
| 92 | for i=1:size(idx2use,2), |
---|
| 93 | idx2use3 = [idx2use3, [idx2use(i)*3-2:idx2use(i)*3]]; |
---|
| 94 | end |
---|
| 95 | |
---|
| 96 | %%% |
---|
| 97 | % fill the loaded structure |
---|
| 98 | loaded.Ws = Ws(idx2use3,:); |
---|
| 99 | loaded.IdMat = IdMat(idx2use,:); |
---|
| 100 | loaded.Res = Res(idx2use,:); |
---|
| 101 | |
---|
| 102 | try,loaded.Pmat = Pmat; catch, warning('No Pmat available'); end; |
---|
| 103 | |
---|
| 104 | return; |
---|