1 | % Read all images and extract point coordinates. |
---|
2 | % |
---|
3 | % All information needed are stored and retrieved |
---|
4 | % from the function CONFIGDATA |
---|
5 | |
---|
6 | % $Author: svoboda $ |
---|
7 | % $Revision: 2.0 $ |
---|
8 | % $Id: im2points.m,v 2.0 2003/06/19 12:07:11 svoboda Exp $ |
---|
9 | % $State: Exp $ |
---|
10 | |
---|
11 | clear all; |
---|
12 | |
---|
13 | % add path to config data |
---|
14 | addpath ../Cfg |
---|
15 | % add path for graphical output if needed |
---|
16 | addpath ../OutputFunctions |
---|
17 | |
---|
18 | SHOWFIG = 0; % show images during point extraction |
---|
19 | STEP4STAT = 5; % step for computing average and std images, if 1 then all images taken |
---|
20 | |
---|
21 | config = configdata(expname); |
---|
22 | |
---|
23 | im.dir = config.paths.img; |
---|
24 | im.ext = config.files.imgext; |
---|
25 | |
---|
26 | NoCams = size(config.files.idxcams,2); % number of cameras |
---|
27 | |
---|
28 | % load image names |
---|
29 | for i=1:NoCams, |
---|
30 | seq(i).camId = config.files.idxcams(i); |
---|
31 | if seq(i).camId > -1 |
---|
32 | if findstr(expname,'oscar') |
---|
33 | seq(i).data = dir([sprintf(im.dir,seq(i).camId),config.files.imnames,'*.',im.ext]); |
---|
34 | else |
---|
35 | seq(i).data = dir([sprintf(im.dir,seq(i).camId),sprintf(config.files.imnames,seq(i).camId),im.ext]); |
---|
36 | end |
---|
37 | else |
---|
38 | seq(i).data = dir([im.dir,sprintf(config.files.imnames),im.ext]); |
---|
39 | end |
---|
40 | seq(i).size = size(seq(i).data,1); |
---|
41 | if seq(i).size<4 |
---|
42 | error('Not enough images found. Wrong image path or name pattern?'); |
---|
43 | end |
---|
44 | end |
---|
45 | |
---|
46 | % Expected number of 3D points is equal to the number of frames. |
---|
47 | % In fact, some frames might be without any calibration point |
---|
48 | |
---|
49 | % Becouse of non-consistent stopping of capturing, the sequences might |
---|
50 | % have different number of images, select the minimal value as the right one |
---|
51 | NoPoints = min([seq.size]); |
---|
52 | pointsIdx = [1:STEP4STAT:NoPoints]; |
---|
53 | |
---|
54 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
55 | %%% beginning of the findings |
---|
56 | |
---|
57 | t = cputime; |
---|
58 | for i=1:NoCams, |
---|
59 | if ~exist(sprintf(config.files.avIM,seq(i).camId)), |
---|
60 | disp(sprintf('The average image of the camera %d is being computed',seq(i).camId)); |
---|
61 | avIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name]))); |
---|
62 | for j=pointsIdx, |
---|
63 | IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]); |
---|
64 | avIM = avIM + double(IM); |
---|
65 | end |
---|
66 | avIM = uint8(round(avIM./size(pointsIdx,2))); |
---|
67 | imwrite(avIM,sprintf(config.files.avIM,seq(i).camId)); |
---|
68 | else disp('Average files already exist'); |
---|
69 | end |
---|
70 | end |
---|
71 | disp(sprintf('Elapsed time for average images: %d [sec]',cputime-t)) |
---|
72 | % compute the standard deviations images that will be used for finding LEDs |
---|
73 | % if not already computed |
---|
74 | t = cputime; |
---|
75 | for i=1:NoCams, |
---|
76 | if ~exist(sprintf(config.files.stdIM,seq(i).camId)), |
---|
77 | avIM = double(imread(sprintf(config.files.avIM,seq(i).camId))); |
---|
78 | disp(sprintf('The image of standard deviations of the camera %d is being computed',seq(i).camId)); |
---|
79 | stdIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name]))); |
---|
80 | for j=pointsIdx, |
---|
81 | IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]); |
---|
82 | stdIM = stdIM + (double(IM)-avIM).^2; |
---|
83 | end |
---|
84 | stdIM = uint8(round(sqrt(stdIM./(size(pointsIdx,2)-1)))); |
---|
85 | imwrite(stdIM,sprintf(config.files.stdIM,seq(i).camId)); |
---|
86 | else |
---|
87 | disp('Image of standard deviations already exist') |
---|
88 | end |
---|
89 | end |
---|
90 | |
---|
91 | disp(sprintf('Elapsed time for computation of images [sec]: %d',cputime-t)) |
---|
92 | |
---|
93 | |
---|
94 | % find points in the images |
---|
95 | Ws = []; % joint image matrix |
---|
96 | Res = []; % resolution of cameras |
---|
97 | IdMat = ones(NoCams,NoPoints); |
---|
98 | % IdMat is very important for Martinec&Pajdla filling [ECCV2002] |
---|
99 | % it is a NoCams x NoPoints matrix, |
---|
100 | % IdMat(i,j) = 0 -> no j-th point in i-th |
---|
101 | % IdMat(i,j) = 1 -> point successfully detected |
---|
102 | |
---|
103 | |
---|
104 | disp('*********************************************') |
---|
105 | disp('Finding points (laser projections) in cameras') |
---|
106 | disp(sprintf('Totally %d cameras, %d images for each cam', NoCams, NoPoints')) |
---|
107 | disp('*********************************************') |
---|
108 | for i=1:NoCams, |
---|
109 | t1 = cputime; |
---|
110 | disp(sprintf('Finding points in camera No: %0.2d',config.files.idxcams(i))) |
---|
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], SHOWFIG, 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 | t2 = cputime; |
---|
126 | disp(sprintf('Elapsed time for finding points in one camera: %d minutes %d seconds',floor((t2-t1)/60), round(mod((t2-t1),60)))) |
---|
127 | end |
---|
128 | |
---|
129 | %%% End of the findings |
---|
130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
131 | |
---|
132 | if findstr(expname,'oscar') |
---|
133 | % needs special care for handling projector data |
---|
134 | ProjPoints = load(config.files.projdata,'-ASCII'); |
---|
135 | Ws = [Ws; ProjPoints(:,2:3)'; ones(size(ProjPoints(:,1)'))]; |
---|
136 | IdMat = [IdMat; ones(size(ProjPoints(:,1)'))]; |
---|
137 | Res = [Res; config.imgs.projres]; |
---|
138 | end |
---|
139 | |
---|
140 | save(config.files.points, 'Ws','-ASCII') |
---|
141 | save(config.files.Res, 'Res', '-ASCII') |
---|
142 | save(config.files.IdMat, 'IdMat', '-ASCII') |
---|
143 | |
---|
144 | % display the overall statistics |
---|
145 | disp('Overall statistics from im2points: ************************ ') |
---|
146 | disp(sprintf('Total number of frames (possible 3D points): %d',NoPoints)) |
---|
147 | disp(sprintf('Total number of cameras %d', NoCams)) |
---|
148 | disp('More important statistics: ********************************* ') |
---|
149 | disp(sprintf('Detected 3D points: %d', sum(sum(IdMat)>0))) |
---|
150 | disp(sprintf('Detected 3D points in at least 3 cams: %d', sum(sum(IdMat)>2))) |
---|
151 | disp(sprintf('Detected 3D points in ALL cameras: %d', sum(sum(IdMat)==NoCams))) |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|