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 | |
---|
17 | donefile = '.done'; |
---|
18 | |
---|
19 | addpath /home/svoboda/Work/BlueCCal/BlueCFindingPoints |
---|
20 | |
---|
21 | % config = localconfig('BlueCHoengg') |
---|
22 | config = localconfig('BlueCRZ') |
---|
23 | |
---|
24 | STEP4STAT = 5; % step for computing average and std images, if 1 then all images taken |
---|
25 | |
---|
26 | im.dir = config.paths.data; |
---|
27 | im.ext = config.files.imgext; |
---|
28 | |
---|
29 | % get the information about machine |
---|
30 | machinename = getenv('HOST'); |
---|
31 | CamsIds = str2num(machinename(find(machinename>47 & machinename<58))); |
---|
32 | |
---|
33 | NoCams = size(CamsIds,2); |
---|
34 | CamsIds |
---|
35 | |
---|
36 | % load image names |
---|
37 | for 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 |
---|
50 | end |
---|
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 |
---|
57 | NoPoints = min([seq.size]); |
---|
58 | |
---|
59 | % compute the average images that will be used for finding LEDs |
---|
60 | % if not already computed |
---|
61 | |
---|
62 | pointsIdx = [1:STEP4STAT:NoPoints]; |
---|
63 | |
---|
64 | t = cputime; |
---|
65 | for 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 |
---|
77 | end |
---|
78 | disp(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 |
---|
81 | t = cputime; |
---|
82 | for 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 |
---|
96 | end |
---|
97 | disp(sprintf('Elapsed time for computation of images [sec]: %d',cputime-t)) |
---|
98 | |
---|
99 | % find points in the images |
---|
100 | Ws = []; |
---|
101 | IdWs = []; |
---|
102 | Res = []; |
---|
103 | |
---|
104 | IdMat = 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 | |
---|
110 | for 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)]; |
---|
125 | end |
---|
126 | |
---|
127 | idx = '.'; |
---|
128 | for i=CamsIds, |
---|
129 | idx = sprintf('%s%02d',idx,i); |
---|
130 | end |
---|
131 | |
---|
132 | save([config.files.points,idx], 'Ws','-ASCII') |
---|
133 | % save(config.files.IdPoints,'IdWs','-ASCII') |
---|
134 | save([config.files.Res,idx], 'Res', '-ASCII') |
---|
135 | save([config.files.IdMat,idx], 'IdMat', '-ASCII') |
---|
136 | |
---|
137 | % write auxiliary file that is done |
---|
138 | done=1; |
---|
139 | save(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 |
---|
144 | exit; |
---|