source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamSelfCal/FindingPoints/im2points.m @ 37

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

Added original make3d

File size: 6.0 KB
Line 
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.6 $
8% $Id: im2points.m,v 2.6 2005/05/23 16:26:03 svoboda Exp $
9% $State: Exp $
10
11clear all;
12
13% add path to config data
14addpath ../../CommonCfgAndIO
15% add path for graphical output if needed
16addpath ../OutputFunctions
17
18SHOWFIG   = 0; % show images during point extraction
19STEP4STAT = 1; % step for computing average and std images, if 1 then all images taken
20
21config = configdata(expname);
22
23im.dir = config.paths.img;
24im.ext = config.files.imgext;
25
26NoCams = size(config.files.idxcams,2);  % number of cameras
27
28% load image names
29for 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
44end
45
46
47% create an occupancy matrix for image frames
48occmat=1; try config.files.maxid; catch occmat=0; end
49if occmat,
50        NoPoints = config.files.maxid;
51        FrameMat = zeros(config.files.maxid,NoCams);
52        for i=1:NoCams,
53                seq(i).imgidx = zeros(size(1:NoPoints));
54                for j=1:size(seq(i).data,1)
55                        FrameMat(str2num(seq(i).data(j).name(config.files.posid)),i)=j;
56                end
57        end
58else
59        NoPoints = min([seq.size]);
60        FrameMat = zeros(NoPoints,NoCams);
61        for i=1:NoCams,
62                FrameMat(:,i) = [1:NoPoints]';
63        end
64end
65
66% In fact, some frames might be without any calibration point
67
68% Becouse of non-consistent stopping of capturing, the sequences might
69% have different number of images, select the minimal value as the right one
70
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72%%% beginning of the findings
73
74t = cputime;
75for i=1:NoCams,
76  if ~exist(sprintf(config.files.avIM,seq(i).camId)),
77        disp(sprintf('The average image of the camera %d is being computed',seq(i).camId));
78        avIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
79        pointIdx = 1:STEP4STAT:seq(i).size;
80        for j=pointIdx,
81          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
82          avIM = avIM + double(IM);
83        end
84        avIM = uint8(round(avIM./size(pointIdx,2)));
85        imwrite(avIM,sprintf(config.files.avIM,seq(i).camId));
86  else  disp('Average file already exists');
87  end
88end
89disp(sprintf('Elapsed time for computation of average images: %4.2f [sec]',cputime-t))
90% compute the standard deviations images that will be used for finding LEDs
91% if not already computed
92t = cputime;
93for i=1:NoCams,
94  if ~exist(sprintf(config.files.stdIM,seq(i).camId)),
95        avIM = double(imread(sprintf(config.files.avIM,seq(i).camId)));
96        disp(sprintf('The image of standard deviations of the camera %d is being computed',seq(i).camId));
97        stdIM = zeros(size(imread([sprintf(im.dir,seq(i).camId),seq(i).data(1).name])));
98        pointIdx = 1:STEP4STAT:seq(i).size;
99        for j=pointIdx,
100          IM = imread([sprintf(im.dir,seq(i).camId),seq(i).data(j).name]);
101          stdIM = stdIM + (double(IM)-avIM).^2;
102        end
103        stdIM = uint8(round(sqrt(stdIM./(size(pointIdx,2)-1))));
104        imwrite(stdIM,sprintf(config.files.stdIM,seq(i).camId));
105  else
106        disp('Image of standard deviations already exists')
107  end
108end
109
110disp(sprintf('Elapsed time for computation of variance images: %4.2f [sec]',cputime-t))
111
112% find points in the images
113Ws    = [];       % joint image matrix
114Res       = [];   % resolution of cameras
115% UsableFramesIdx = find(sum(FrameMat')>2);
116IdMat = ones(NoCams,NoPoints);
117% IdMat is very important for Martinec&Pajdla filling [ECCV2002]
118% it is a NoCams x NoPoints matrix,
119% IdMat(i,j) = 0 -> no j-th point in i-th
120% IdMat(i,j) = 1 -> point successfully detected
121
122
123disp('*********************************************')
124disp('Finding points (laser projections) in cameras')
125disp(sprintf('Totally %d cameras, %d images for each cam', NoCams, NoPoints'))
126disp('*********************************************')
127for i=1:NoCams,
128  t1 = cputime;
129  disp(sprintf('Finding points in camera No: %0.2d',config.files.idxcams(i)))
130  Points = [];
131  avIM  = imread(sprintf(config.files.avIM,seq(i).camId));
132  stdIM = imread(sprintf(config.files.stdIM,seq(i).camId));
133  for j=1:NoPoints,
134          fprintf(1,'\b\b\b\b\b\b %5d',j);
135          idx2data = FrameMat(j,i);
136          if idx2data
137                  [pos,err] = getpoint([sprintf(im.dir,seq(i).camId),seq(i).data(idx2data).name], SHOWFIG, config.imgs, avIM, stdIM);
138          else
139                  err = 1;
140          end
141        if err   
142          IdMat(i,j) = 0;
143          Points = [Points, [NaN; NaN; NaN]];
144        else
145          Points = [Points, [pos; 1]];
146        end
147  end
148  Ws = [Ws; Points];
149  Res= [Res; size(avIM,2), size(avIM,1)];
150  t2 = cputime;
151  disp(sprintf('\nElapsed time for finding points in one camera: %d minutes %d seconds',floor((t2-t1)/60), round(mod((t2-t1),60))))
152  disp(sprintf('%4d points found in camera No: %0.2d',sum(Points(3,:)>0),config.files.idxcams(i)));
153end
154
155%%% End of the findings
156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157
158if findstr(expname,'oscar')
159  % needs special care for handling projector data
160  ProjPoints = load(config.files.projdata,'-ASCII');
161  Ws = [Ws; ProjPoints(:,end-1:end)'; ones(size(ProjPoints(:,1)'))];
162  IdMat = [IdMat; ones(size(ProjPoints(:,1)'))];
163  Res   = [Res; config.imgs.projres];
164end
165
166save(config.files.points, 'Ws','-ASCII')
167save(config.files.Res, 'Res', '-ASCII')
168save(config.files.IdMat, 'IdMat', '-ASCII')
169
170% display the overall statistics
171disp('Overall statistics from im2points:  ************************  ')
172disp(sprintf('Total number of frames (possible 3D points): %d',NoPoints))
173disp(sprintf('Total number of cameras %d', NoCams))
174disp('More important statistics: *********************************  ')
175disp(sprintf('Detected 3D points:                    %d', sum(sum(IdMat)>0)))
176disp(sprintf('Detected 3D points in at least 3 cams: %d', sum(sum(IdMat)>2)))
177disp(sprintf('Detected 3D points in ALL cameras:     %d', sum(sum(IdMat)==NoCams)))
178
179
180
181
182
183
184
185
Note: See TracBrowser for help on using the repository browser.