source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/BlueCFindingPoints/im2pointsLocally.m @ 37

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

Added original make3d

File size: 4.5 KB
Line 
1% im2pointsLocally    computes image statistics from several images
2%                     and finds the projections of laser points
3%
4% The version for local computation on each machine
5%
6% The computation core is taken from  im2points.m
7% computes average image and image of standard deviations
8% requires configdata.m
9% The name of the experiment has to be specified
10% it determines the location of files etc ...
11%
12% the scripts serves as a template for a multiprocessing
13% it assumes a vector of camera IDs CamIds to be known
14% indexes in the CamIds are supposed to be correct
15%
16
17donefile = '.done';
18
19addpath /home/svoboda/Work/BlueCCal/BlueCFindingPoints
20
21% config = localconfig('BlueCHoengg')
22config = localconfig('BlueCRZ')
23
24STEP4STAT = 5; % step for computing average and std images, if 1 then all images taken
25
26im.dir = config.paths.data;
27im.ext = config.files.imgext;
28
29% get the information about machine
30machinename = getenv('HOST');
31CamsIds = str2num(machinename(find(machinename>47 & machinename<58)));
32
33NoCams = size(CamsIds,2);
34CamsIds
35
36% load image names
37for i=1:NoCams,
38  seq(i).camId = CamsIds(i);
39  if seq(i).camId > -1
40        seq(i).data = dir([sprintf(im.dir,seq(i).camId),sprintf(config.files.imnames,seq(i).camId),im.ext]);
41        [sprintf(im.dir,seq(i).camId),sprintf(config.files.imnames,seq(i).camId),im.ext]
42  else
43        seq(i).data = dir([im.dir,sprintf(config.files.imnames),im.ext]);
44  end
45  seq(i).size = size(seq(i).data,1);
46  if seq(i).size<4
47        i, seq
48        error('Not enough images found. Wrong image path or name pattern?');
49  end
50end
51
52% Expected number of 3D points is equal to the number of frames.
53% In fact, some frames might be without any calibration point
54
55% Because of non-consistent stopping of capturing, the sequences might
56% have different number of images, select the minimal value as the right one
57NoPoints = min([seq.size]);
58
59% compute the average images that will be used for finding LEDs
60% if not already computed
61
62pointsIdx = [1:STEP4STAT:NoPoints];
63
64t = cputime;
65for i=1:NoCams,
66  if ~exist(sprintf(config.files.avIM,seq(i).camId)),
67        disp(sprintf('The average image of the camera %d is being computed',seq(i).camId));
68        avIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
69        for j=pointsIdx,
70          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
71          avIM = avIM + double(IM);
72        end
73        avIM = uint8(round(avIM./size(pointsIdx,2)));
74        imwrite(avIM,sprintf(config.files.avIM,seq(i).camId));
75  else  disp('Average files already exist');
76  end
77end
78disp(sprintf('Elapsed time for average images: %d [sec]',cputime-t))
79% compute the standard deviations images that will be used for finding LEDs
80% if not already computed
81t = cputime;
82for i=1:NoCams,
83  if ~exist(sprintf(config.files.stdIM,seq(i).camId)),
84        avIM = double(imread(sprintf(config.files.avIM,seq(i).camId)));
85        disp(sprintf('The image of standard deviations of the camera %d is being computed',seq(i).camId));
86        stdIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
87        for j=pointsIdx,
88          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
89          stdIM = stdIM + (double(IM)-avIM).^2;
90        end
91        stdIM = uint8(round(sqrt(stdIM./(size(pointsIdx,2)-1))));
92        imwrite(stdIM,sprintf(config.files.stdIM,seq(i).camId));
93  else
94        disp('Image of standard deviations already exist')
95  end
96end
97disp(sprintf('Elapsed time for computation of images [sec]: %d',cputime-t))
98
99% find points in the images
100Ws    = [];
101IdWs  = [];
102Res       = [];
103
104IdMat = ones(NoCams,NoPoints);
105% IdMat is very important for Martinec&Pajdla filling [ECCV2002]
106% it is a NoCams x NoPoints matrix,
107% IdMat(i,j) = 0 -> no j-th point in i-th
108% IdMat(i,j) = 1 -> point successfully detected
109
110for i=1:NoCams,
111  Points = [];
112  avIM  = imread(sprintf(config.files.avIM,seq(i).camId));
113  stdIM = imread(sprintf(config.files.stdIM,seq(i).camId));
114  for j=1:NoPoints,
115        [pos,err] = getpoint([sprintf(im.dir,seq(i).camId),seq(i).data(j).name], 0, config.imgs, avIM, stdIM);
116        if err   
117          IdMat(i,j) = 0;
118          Points = [Points, [NaN; NaN; NaN]];
119        else
120          Points = [Points, [pos; 1]];
121        end
122  end
123  Ws = [Ws; Points];
124  Res= [Res; size(avIM,2), size(avIM,1)];
125end
126
127idx = '.';
128for i=CamsIds,
129  idx = sprintf('%s%02d',idx,i);
130end
131       
132save([config.files.points,idx], 'Ws','-ASCII')
133% save(config.files.IdPoints,'IdWs','-ASCII')
134save([config.files.Res,idx], 'Res', '-ASCII')
135save([config.files.IdMat,idx], 'IdMat', '-ASCII')
136
137% write auxiliary file that is done
138done=1;
139save(donefile,'done','-ascii');
140
141% exit the Matlab
142% this script is to be used in the batch mode
143% hence exit at the end is necessary
144exit;
Note: See TracBrowser for help on using the repository browser.