source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/BlueCCal/MultiCamValidation/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: 5.3 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.0 $
8% $Id: im2points.m,v 2.0 2003/06/19 12:07:11 svoboda Exp $
9% $State: Exp $
10
11clear all;
12
13% add path to config data
14addpath ../Cfg
15% add path for graphical output if needed
16addpath ../OutputFunctions
17
18SHOWFIG   = 0; % show images during point extraction
19STEP4STAT = 5; % 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% 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
51NoPoints = min([seq.size]);
52pointsIdx = [1:STEP4STAT:NoPoints];
53
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55%%% beginning of the findings
56
57t = cputime;
58for 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
70end
71disp(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
74t = cputime;
75for 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
89end
90
91disp(sprintf('Elapsed time for computation of images [sec]: %d',cputime-t))
92
93
94% find points in the images
95Ws    = [];       % joint image matrix
96Res       = [];   % resolution of cameras
97IdMat = 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
104disp('*********************************************')
105disp('Finding points (laser projections) in cameras')
106disp(sprintf('Totally %d cameras, %d images for each cam', NoCams, NoPoints'))
107disp('*********************************************')
108for 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))))
127end
128
129%%% End of the findings
130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131
132if 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];
138end
139
140save(config.files.points, 'Ws','-ASCII')
141save(config.files.Res, 'Res', '-ASCII')
142save(config.files.IdMat, 'IdMat', '-ASCII')
143
144% display the overall statistics
145disp('Overall statistics from im2points:  ************************  ')
146disp(sprintf('Total number of frames (possible 3D points): %d',NoPoints))
147disp(sprintf('Total number of cameras %d', NoCams))
148disp('More important statistics: *********************************  ')
149disp(sprintf('Detected 3D points:                    %d', sum(sum(IdMat)>0)))
150disp(sprintf('Detected 3D points in at least 3 cams: %d', sum(sum(IdMat)>2)))
151disp(sprintf('Detected 3D points in ALL cameras:     %d', sum(sum(IdMat)==NoCams)))
152
153
154
155
156
157
158
159
Note: See TracBrowser for help on using the repository browser.