source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LaserDataCollection/makeDepthImagesSph_ImgbyImg.m @ 37

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

Added original make3d

File size: 11.7 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function makeDepthImagesSph_ImgbyImg(dataNumber, displayFlag)
40% global depthBins;
41% global countBuf;
42if nargin < 2
43    displayFlag = false;
44end
45if nargin < 1
46    dataNumber = 1;
47end
48%% we first read the log file and then read the depth values in a
49%% two-dimensional array after binning and averaging values for each bin
50%% value
51homeData='/afs/cs/group/reconstruction3d/Data/Dataset_Oct21/scenario';
52depthDirectory = strcat(homeData,num2str(dataNumber),'/');
53imgDirectory = strcat(homeData,num2str(dataNumber),'/');
54%Win05:
55% system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']);
56% Above command is passed in Linux to clear the text, leaving only numbers, which can be directly
57% imported into Matlab by using File > Import Data
58    dirList = dir([depthDirectory '*.txt']);
59    depthFileInitialname = dirList(1).name;
60   
61    system([ 'cat ' depthDirectory depthFileInitialname ' | sed /PTLASER/\d | cat > ' depthDirectory depthFileInitialname 'image1']);
62    system([ 'cat ' depthDirectory depthFileInitialname 'image1' ' | sed s/IMAGE/\/g | cat > ' depthDirectory depthFileInitialname 'image2']);
63    system([ 'cat ' depthDirectory depthFileInitialname 'image2' ' | sed s/data/\\n\data/g | cat > ' depthDirectory depthFileInitialname 'image3']);
64    system([ 'cat ' depthDirectory depthFileInitialname 'image3' ' | sed /data/\d | cat > ' depthDirectory depthFileInitialname 'image']);
65    system([ 'cat ' depthDirectory depthFileInitialname ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFileInitialname 'cleaned1']);
66    system([ 'cat ' depthDirectory depthFileInitialname 'cleaned1' ' | sed /IMAGE/\d | cat > ' depthDirectory depthFileInitialname 'cleaned']);
67    system([ 'rm ' depthDirectory depthFileInitialname 'cleaned1']);
68    system([ 'rm ' depthDirectory depthFileInitialname 'image1']);
69    system([ 'rm ' depthDirectory depthFileInitialname 'image2']);
70    system([ 'rm ' depthDirectory depthFileInitialname 'image3']);
71   
72    depthFilename = strcat(depthFileInitialname,'cleaned');
73    imageFileForAnglesName = strcat(depthFileInitialname,'image');
74rawDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']);
75imageAngList = load([depthDirectory imageFileForAnglesName]);
76%% now we make the bins and store the rawDepth values in the appropriate
77%% bins
78panStartAngD  =   floor(rawDepth(1,2)-1);
79panEndAngD    =   ceil(rawDepth(end,2)+1);
80sweepStartAngD=   -90;
81sweepEndAngD  =   90;
82panRange = panEndAngD-panStartAngD;
83sweepRange = sweepEndAngD-sweepStartAngD;
84 
85panBinResD  =   .125; %panRange/size(rawDepth,1);
86sweepBinResD=   1; %sweepRange/rawDepth(1,4);
87panBins     = ceil(panRange/panBinResD); 
88sweepBins   = ceil(sweepRange/sweepBinResD);
89depthBins = zeros(panBins,sweepBins);
90countBuf = zeros(panBins,sweepBins);
91[depthBins,countBuf,minDepth]=readLogFileForDepth(rawDepth,depthBins,countBuf, ...
92    panEndAngD,panBinResD,sweepEndAngD,sweepBinResD);
93%% trim depth buffer to remove zero columns
94[depthBins,countBuf,panStartTrim,panEndTrim,sweepStartTrim,sweepEndTrim]=trimDepthBuf(depthBins,countBuf,panBins,sweepBins);
95panBins=size(depthBins,1);
96sweepBins=size(depthBins,2);
97panStartAngD  =   floor(rawDepth(1,2))+(panStartTrim*panBinResD);%rawDepth(1,2);
98panEndAngD    =   ceil(rawDepth(end,2))-(panEndTrim*panBinResD);%rawDepth(end,2);
99sweepStartAngD=   -90+(sweepStartTrim*sweepBinResD);
100sweepEndAngD  =   90-(sweepEndTrim*sweepBinResD);
101panRange = panEndAngD-panStartAngD;
102sweepRange = sweepEndAngD-sweepStartAngD;
103%% we now check for validity of the buffer
104[depthBins,countBuf]=checkIfValid(depthBins,countBuf,size(depthBins,1), ...
105    size(depthBins,2),minDepth);
106clear countBuf;
107%% we now do the triangle making
108%% for the time being we are skipping this part
109%% now for every i,j in the depth map, we need to find the x_im and y_im,
110%% based on the format that Min wants it in i.e. lets say that the image
111%% lines between (0,0), (1,0), (1,1) and (0,1) going counter clockwise with
112%% the bottom left point of the image being (0,0), and so the top left
113%% point being (0,1)
114% image2LaserPanAngleOffsetD = 0; %% check if this is 0 by trial and error
115% panImageStartAngD = -180;
116% panImageEndAngD = 180;
117% sweepImageStartAngD = 67-90;
118% sweepImageEndAngD = (180-68)-90;
119% panBinIdxStart=floor((panEndAngD-panImageStartAngD)/panBinResD);
120% panBinIdxEnd=floor((panEndAngD-panImageEndAngD)/panBinResD);
121% sweepBinIdxStart=floor((sweepEndAngD-sweepImageStartAngD)/sweepBinResD);
122% sweepBinIdxEnd=floor((sweepEndAngD-sweepImageEndAngD)/sweepBinResD);
123       
124laserPanAxisOffset = 0.2;
125laserTiltAxisOffset = 0.155;
126rigHeight = 1.5;
127distCoeffs = [-0.068382333138247237 -0.54357925933026252 -0.0029516085790312376 ...
128        -0.00024597914695977276];
129D2R = (pi/180);
130fx = 2400.2091651084;
131fy = 2407.3312729885838;
132Ox = 1110.7122391785729;%2272/2; %
133Oy = 833.72104535435108;%1704/2; %
134camIntMat = [ -fx, 0.0, Ox;
135    0.0, -fy, Oy;
136    0.0, 0.0, 1.0 ];
137UNDISTORT = 1;
138rollInit = pi;
139pitchInit = -pi/2;
140yawInit = 0.0;
141camPanAxisOffset = 0.20;
142camTiltAxisOffset = 0.155;
143imagePanAngD = imageAngList(:,2);
144imagePanAngD = (imagePanAngD<-180).*(imagePanAngD+360)+...
145    (imagePanAngD>-180).*(imagePanAngD);
146imagePanAngRndD = round(imageAngList(:,2));
147imageRangeAngD = 21;
148R = eulerAngles(rollInit,pitchInit,yawInit);
149%% roll is along the x-axis, pitch is along the y-axis and yaw is along
150%% the z axis
151t = [camPanAxisOffset 0.0 camTiltAxisOffset];
152camPos = [R t'; 0 0 0 1];
153camExtMat1 = inv(camPos);
154for imNum=1:length(imagePanAngD)
155    image2LaserPanAngleOffsetD = 0; %% check if this is 0 by trial and error
156    dirList = dir([imgDirectory strcat('*', ...
157        num2str(abs(imagePanAngRndD(imNum))),'*.jpg')]);
158    if (length(dirList)==0)
159        problem_list=1
160    end
161        imageFilename = dirList(1).name;
162    depthPixelFilename=regexprep(imageFilename,'img','depth_sph_corr');
163    depthPixelFilename=regexprep(depthPixelFilename,'.jpg','.mat');
164    depthPixelFilename=strcat('/afs/cs/group/reconstruction3d/scratch/LaserDepth/Dataset_Oct21/',depthPixelFilename);
165   
166    imagePanAngCurrentD=(round(imagePanAngD(imNum)/panBinResD))*panBinResD;
167        panImageStartAngD = imagePanAngCurrentD-imageRangeAngD;
168        panImageEndAngD = imagePanAngCurrentD+imageRangeAngD;
169        sweepImageStartAngD = 63-90;
170        sweepImageEndAngD = (180-63)-90;
171    pixelCount = 1;
172%       panCount=1;
173%       imageFilenamePrev=' ';
174        for panBinAngleLoopD=panImageEndAngD:-panBinResD:panImageStartAngD
175        panBinAngleLoopDt=panBinAngleLoopD;
176        if panBinAngleLoopD<-180 %% wrap around
177            panBinAngleLoopDt=panBinAngleLoopD+360;
178        end
179        if panBinAngleLoopD>180 %% wrap around
180            panBinAngleLoopDt=panBinAngleLoopD-360;
181        end
182        if (((panStartAngD<-180) && (panEndAngD>180))|| ...
183                ((panBinAngleLoopD>=panStartAngD) && (panBinAngleLoopD<panEndAngD)))
184            %% this condition is to handle log files which do not have the
185            %% full pan angle from -180 to 180
186       
187            panBinIdx=floor((panEndAngD-panBinAngleLoopDt)/panBinResD);
188    %         sweepCount=1;
189            for sweepBinAngleLoopD=sweepImageStartAngD:sweepBinResD:sweepImageEndAngD
190                sweepBinIdx=floor((sweepEndAngD-sweepBinAngleLoopD)/sweepBinResD);
191                %% we now calculate the world coordinate point from depth buffer
192                if ((panBinIdx>size(depthBins,1))||(panBinIdx<1)||...
193                        (sweepBinIdx>size(depthBins,2))||(sweepBinIdx<1))
194                    waithere = 1
195                end           
196                depthVal = depthBins(panBinIdx,sweepBinIdx);
197                Wcoord=calcPointFromDepthBuf(depthVal,panBinIdx,sweepBinIdx, ...
198                    panEndAngD,panBins,panRange,sweepEndAngD,sweepBins, ...
199                    sweepRange,laserPanAxisOffset,laserTiltAxisOffset,rigHeight);
200    %                   %% once we have the world coordinates, we get the color
201    %                   %% corresponding to these world coordinates
202    %                   %% which is the same as finding the x_im and y_im in the correct
203    %                   %% image               
204    %                   %% so the first step will be to find the right image
205    %             currPanAngD = panEndAngD-(panBinIdx/panBins)*panRange;
206    %             currPanAngD = (currPanAngD+image2LaserPanAngleOffsetD);
207    %             if (currPanAngD>180)
208    %                 currPanAngD = currPanAngD-360;
209    %             elseif (currPanAngD<-180)
210    %                 currPanAngD = currPanAngD+360;
211    %             end
212    %             [temp1,temp2]=min(abs(imagePanAngD-currPanAngD));
213    %             rightImageNum = imagePanAngRndD(temp2);
214        %         if (imageFilenamePrev~=imageFilename)
215        %             A = imread([imgDirectory imageFilename]);
216        %             imageFilenamePrev=imageFilename;           
217        %         end
218                %% the definition of roll, pitch and yaw needs to be checked with
219                %% Kyle
220                panAngR = imagePanAngD(imNum)*D2R;
221                tiltAngR = imageAngList(imNum,3)*D2R;
222                [pixel, camCoord, isCorrect] = getPixelCoords(Wcoord,panAngR,tiltAngR, ...
223                    rigHeight,distCoeffs,camIntMat,UNDISTORT,camExtMat1);
224                %% the storage format in the pixelreservoir is to store for each
225                %% value of panBinIdx and sweepBinIdx, the imageNumber and the
226                %% pixel values in that image
227                if (isCorrect == true)               
228                    pixelReservoir(pixelCount,:)=[camCoord' pixel depthVal];
229                    pixelCount=pixelCount+1;               
230                end
231            end
232        end
233%             waithere=1;
234%         panCount=panCount+1;
235        end
236    depthMapXRes=55;
237        depthMapYRes=305;
238%     [pseudoDepthMap] = sortPixel(pixelReservoir,depthMapXRes,depthMapYRes);
239    save(depthPixelFilename, 'pixelReservoir');
240%         save(depthPixelFilename, 'pseudoDepthMap', 'pixelReservoir');
241%     pixelCount
242%       plotKyleData(pseudoDepthMap,depthMapXRes,depthMapYRes, ...
243%         imgDirectory,imageFilename)
244   
245    clear pixelReservoir;
246end
247% displayScenario(depthDirectory,imgDirectory);
Note: See TracBrowser for help on using the repository browser.