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 | % */
|
---|
39 | function makeDepthImagesSph_ImgbyImg(dataNumber, displayFlag) |
---|
40 | % global depthBins; |
---|
41 | % global countBuf; |
---|
42 | if nargin < 2 |
---|
43 | displayFlag = false; |
---|
44 | end |
---|
45 | if nargin < 1 |
---|
46 | dataNumber = 1; |
---|
47 | end |
---|
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 |
---|
51 | homeData='/afs/cs/group/reconstruction3d/Data/Dataset_Oct21/scenario'; |
---|
52 | depthDirectory = strcat(homeData,num2str(dataNumber),'/'); |
---|
53 | imgDirectory = 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'); |
---|
74 | rawDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']); |
---|
75 | imageAngList = load([depthDirectory imageFileForAnglesName]); |
---|
76 | %% now we make the bins and store the rawDepth values in the appropriate |
---|
77 | %% bins |
---|
78 | panStartAngD = floor(rawDepth(1,2)-1); |
---|
79 | panEndAngD = ceil(rawDepth(end,2)+1); |
---|
80 | sweepStartAngD= -90; |
---|
81 | sweepEndAngD = 90; |
---|
82 | panRange = panEndAngD-panStartAngD; |
---|
83 | sweepRange = sweepEndAngD-sweepStartAngD; |
---|
84 | |
---|
85 | panBinResD = .125; %panRange/size(rawDepth,1); |
---|
86 | sweepBinResD= 1; %sweepRange/rawDepth(1,4); |
---|
87 | panBins = ceil(panRange/panBinResD); |
---|
88 | sweepBins = ceil(sweepRange/sweepBinResD); |
---|
89 | depthBins = zeros(panBins,sweepBins); |
---|
90 | countBuf = 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); |
---|
95 | panBins=size(depthBins,1); |
---|
96 | sweepBins=size(depthBins,2); |
---|
97 | panStartAngD = floor(rawDepth(1,2))+(panStartTrim*panBinResD);%rawDepth(1,2); |
---|
98 | panEndAngD = ceil(rawDepth(end,2))-(panEndTrim*panBinResD);%rawDepth(end,2); |
---|
99 | sweepStartAngD= -90+(sweepStartTrim*sweepBinResD); |
---|
100 | sweepEndAngD = 90-(sweepEndTrim*sweepBinResD); |
---|
101 | panRange = panEndAngD-panStartAngD; |
---|
102 | sweepRange = 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); |
---|
106 | clear 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 | |
---|
124 | laserPanAxisOffset = 0.2; |
---|
125 | laserTiltAxisOffset = 0.155; |
---|
126 | rigHeight = 1.5; |
---|
127 | distCoeffs = [-0.068382333138247237 -0.54357925933026252 -0.0029516085790312376 ... |
---|
128 | -0.00024597914695977276]; |
---|
129 | D2R = (pi/180); |
---|
130 | fx = 2400.2091651084; |
---|
131 | fy = 2407.3312729885838; |
---|
132 | Ox = 1110.7122391785729;%2272/2; % |
---|
133 | Oy = 833.72104535435108;%1704/2; % |
---|
134 | camIntMat = [ -fx, 0.0, Ox; |
---|
135 | 0.0, -fy, Oy; |
---|
136 | 0.0, 0.0, 1.0 ]; |
---|
137 | UNDISTORT = 1; |
---|
138 | rollInit = pi; |
---|
139 | pitchInit = -pi/2; |
---|
140 | yawInit = 0.0; |
---|
141 | camPanAxisOffset = 0.20; |
---|
142 | camTiltAxisOffset = 0.155; |
---|
143 | imagePanAngD = imageAngList(:,2); |
---|
144 | imagePanAngD = (imagePanAngD<-180).*(imagePanAngD+360)+... |
---|
145 | (imagePanAngD>-180).*(imagePanAngD); |
---|
146 | imagePanAngRndD = round(imageAngList(:,2)); |
---|
147 | imageRangeAngD = 21; |
---|
148 | R = 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 |
---|
151 | t = [camPanAxisOffset 0.0 camTiltAxisOffset]; |
---|
152 | camPos = [R t'; 0 0 0 1]; |
---|
153 | camExtMat1 = inv(camPos); |
---|
154 | for 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; |
---|
246 | end |
---|
247 | % displayScenario(depthDirectory,imgDirectory); |
---|