[37] | 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(dataNumber, displayFlag) |
---|
| 40 | |
---|
| 41 | % global depthBins; |
---|
| 42 | % global countBuf; |
---|
| 43 | |
---|
| 44 | if nargin < 2 |
---|
| 45 | displayFlag = false; |
---|
| 46 | end |
---|
| 47 | if nargin < 1 |
---|
| 48 | dataNumber = 1; |
---|
| 49 | end |
---|
| 50 | |
---|
| 51 | %% we first read the log file and then read the depth values in a |
---|
| 52 | %% two-dimensional array after binning and averaging values for each bin |
---|
| 53 | %% value |
---|
| 54 | |
---|
| 55 | depthDirectory = './dataset5/'; |
---|
| 56 | imgDirectory = './dataset5/'; |
---|
| 57 | %Win05: |
---|
| 58 | % system([ 'cat ' depthDirectory depthFilename ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFilename 'cleaned']); |
---|
| 59 | % Above command is passed in Linux to clear the text, leaving only numbers, which can be directly |
---|
| 60 | % imported into Matlab by using File > Import Data |
---|
| 61 | |
---|
| 62 | dirList = dir([depthDirectory '*.txt']); |
---|
| 63 | depthFileInitialname = dirList(dataNumber).name; |
---|
| 64 | |
---|
| 65 | % system([ 'cat ' depthDirectory depthFileInitialname ' | sed /PTLASER/\d | cat > ' depthDirectory depthFileInitialname 'image1']); |
---|
| 66 | % system([ 'cat ' depthDirectory depthFileInitialname 'image1' ' | sed s/IMAGE/\/g | cat > ' depthDirectory depthFileInitialname 'image2']); |
---|
| 67 | % system([ 'cat ' depthDirectory depthFileInitialname 'image2' ' | sed s/data/\\n\data/g | cat > ' depthDirectory depthFileInitialname 'image3']); |
---|
| 68 | % system([ 'cat ' depthDirectory depthFileInitialname 'image3' ' | sed /data/\d | cat > ' depthDirectory depthFileInitialname 'image']); |
---|
| 69 | % |
---|
| 70 | % system([ 'cat ' depthDirectory depthFileInitialname ' | sed s/PTLASER/\/g | cat > ' depthDirectory depthFileInitialname 'cleaned1']); |
---|
| 71 | % system([ 'cat ' depthDirectory depthFileInitialname 'cleaned1' ' | sed /IMAGE/\d | cat > ' depthDirectory depthFileInitialname 'cleaned']); |
---|
| 72 | % |
---|
| 73 | % system([ 'rm ' depthDirectory depthFileInitialname 'cleaned1']); |
---|
| 74 | % system([ 'rm ' depthDirectory depthFileInitialname 'image1']); |
---|
| 75 | % system([ 'rm ' depthDirectory depthFileInitialname 'image2']); |
---|
| 76 | % system([ 'rm ' depthDirectory depthFileInitialname 'image3']); |
---|
| 77 | |
---|
| 78 | depthFilename = strcat(depthFileInitialname,'cleaned'); |
---|
| 79 | imageFileForAnglesName = strcat(depthFileInitialname,'image'); |
---|
| 80 | depthPixelFilename = strcat(depthDirectory,'finalResultsDepthUd.mat'); |
---|
| 81 | |
---|
| 82 | rawDepth = load([depthDirectory depthFilename]); %load([directory 'log' num2str(dataNumber) '.mat']); |
---|
| 83 | imageAngList = load([depthDirectory imageFileForAnglesName]); |
---|
| 84 | |
---|
| 85 | %% now we make the bins and store the rawDepth values in the appropriate |
---|
| 86 | %% bins |
---|
| 87 | |
---|
| 88 | panStartAngD = -185;%rawDepth(1,2); |
---|
| 89 | panEndAngD = 185;%rawDepth(end,2); |
---|
| 90 | sweepStartAngD= -90; |
---|
| 91 | sweepEndAngD = 90; |
---|
| 92 | |
---|
| 93 | panRange = panEndAngD-panStartAngD; |
---|
| 94 | sweepRange = sweepEndAngD-sweepStartAngD; |
---|
| 95 | |
---|
| 96 | panBinResD = .125; %panRange/size(rawDepth,1); |
---|
| 97 | sweepBinResD= 1; %sweepRange/rawDepth(1,4); |
---|
| 98 | |
---|
| 99 | panBins = ceil(panRange/panBinResD); |
---|
| 100 | sweepBins = ceil(sweepRange/sweepBinResD); |
---|
| 101 | |
---|
| 102 | depthBins = zeros(panBins,sweepBins); |
---|
| 103 | countBuf = zeros(panBins,sweepBins); |
---|
| 104 | |
---|
| 105 | [depthBins,countBuf,minDepth]=readLogFileForDepth(rawDepth,depthBins,countBuf, ... |
---|
| 106 | panEndAngD,panBinResD,sweepEndAngD,sweepBinResD); |
---|
| 107 | |
---|
| 108 | %% trim depth buffer to remove zero columns |
---|
| 109 | [depthBins,countBuf,panStartTrim,panEndTrim,sweepStartTrim,sweepEndTrim]=trimDepthBuf(depthBins,countBuf,panBins,sweepBins); |
---|
| 110 | panBins=size(depthBins,1); |
---|
| 111 | sweepBins=size(depthBins,2); |
---|
| 112 | panStartAngD = -185+(panStartTrim*panBinResD);%rawDepth(1,2); |
---|
| 113 | panEndAngD = 185-(panEndTrim*panBinResD);%rawDepth(end,2); |
---|
| 114 | sweepStartAngD= -90+(sweepStartTrim*sweepBinResD); |
---|
| 115 | sweepEndAngD = 90-(sweepEndTrim*sweepBinResD); |
---|
| 116 | |
---|
| 117 | panRange = panEndAngD-panStartAngD; |
---|
| 118 | sweepRange = sweepEndAngD-sweepStartAngD; |
---|
| 119 | |
---|
| 120 | %% we now check for validity of the buffer |
---|
| 121 | [depthBins,countBuf]=checkIfValid(depthBins,countBuf,size(depthBins,1), ... |
---|
| 122 | size(depthBins,2),minDepth); |
---|
| 123 | clear countBuf; |
---|
| 124 | %% we now do the triangle making |
---|
| 125 | %% for the time being we are skipping this part |
---|
| 126 | |
---|
| 127 | %% now for every i,j in the depth map, we need to find the x_im and y_im, |
---|
| 128 | %% based on the format that Min wants it in i.e. lets say that the image |
---|
| 129 | %% lines between (0,0), (1,0), (1,1) and (0,1) going counter clockwise with |
---|
| 130 | %% the bottom left point of the image being (0,0), and so the top left |
---|
| 131 | %% point being (0,1) |
---|
| 132 | image2LaserPanAngleOffsetD = 0; %% check if this is 0 by trial and error |
---|
| 133 | panImageStartAngD = -180; |
---|
| 134 | panImageEndAngD = 180; |
---|
| 135 | sweepImageStartAngD = 67-90; |
---|
| 136 | sweepImageEndAngD = (180-68)-90; |
---|
| 137 | panBinIdxStart=floor((panEndAngD-panImageStartAngD)/panBinResD); |
---|
| 138 | panBinIdxEnd=floor((panEndAngD-panImageEndAngD)/panBinResD); |
---|
| 139 | sweepBinIdxStart=floor((sweepEndAngD-sweepImageStartAngD)/sweepBinResD); |
---|
| 140 | sweepBinIdxEnd=floor((sweepEndAngD-sweepImageEndAngD)/sweepBinResD); |
---|
| 141 | |
---|
| 142 | laserPanAxisOffset = 0.2; |
---|
| 143 | laserTiltAxisOffset = 0.155; |
---|
| 144 | rigHeight = 1.5; |
---|
| 145 | distCoeffs = [-0.068382333138247237 -0.54357925933026252 -0.0029516085790312376 -0.00024597914695977276]; |
---|
| 146 | D2R = (pi/180); |
---|
| 147 | fx = 2400.2091651084; |
---|
| 148 | fy = 2407.3312729885838; |
---|
| 149 | Ox = 1110.7122391785729;%2272/2; % |
---|
| 150 | Oy = 833.72104535435108;%1704/2; % |
---|
| 151 | |
---|
| 152 | camIntMat = [ -fx, 0.0, Ox; |
---|
| 153 | 0.0, -fy, Oy; |
---|
| 154 | 0.0, 0.0, 1.0 ]; |
---|
| 155 | |
---|
| 156 | UNDISTORT = 1; |
---|
| 157 | |
---|
| 158 | rollInit = pi; |
---|
| 159 | pitchInit = -pi/2; |
---|
| 160 | yawInit = 0.0; |
---|
| 161 | camPanAxisOffset = 0.20; |
---|
| 162 | camTiltAxisOffset = 0.155; |
---|
| 163 | |
---|
| 164 | imagePanAngD = imageAngList(:,2); |
---|
| 165 | imagePanAngD = (imagePanAngD<-180).*(imagePanAngD+360)+... |
---|
| 166 | (imagePanAngD>-180).*(imagePanAngD); |
---|
| 167 | imagePanAngRndD = round(imageAngList(:,2)); |
---|
| 168 | |
---|
| 169 | R = eulerAngles(rollInit,pitchInit,yawInit); |
---|
| 170 | %% roll is along the x-axis, pitch is along the y-axis and yaw is along |
---|
| 171 | %% the z axis |
---|
| 172 | t = [camPanAxisOffset 0.0 camTiltAxisOffset]; |
---|
| 173 | camPos = [R t'; 0 0 0 1]; |
---|
| 174 | camExtMat1 = inv(camPos); |
---|
| 175 | |
---|
| 176 | panCount=1; |
---|
| 177 | imageFilenamePrev=' '; |
---|
| 178 | for panBinIdx=panBinIdxStart:-1:panBinIdxEnd |
---|
| 179 | sweepCount=1; |
---|
| 180 | for sweepBinIdx=sweepBinIdxStart:-1:sweepBinIdxEnd |
---|
| 181 | %% we now calculate the world coordinate point from depth buffer |
---|
| 182 | depthVal = depthBins(panBinIdx,sweepBinIdx); |
---|
| 183 | Wcoord=calcPointFromDepthBuf(depthVal,panBinIdx,sweepBinIdx, ... |
---|
| 184 | panEndAngD,panBins,panRange,sweepEndAngD,sweepBins, ... |
---|
| 185 | sweepRange,laserPanAxisOffset,laserTiltAxisOffset,rigHeight); |
---|
| 186 | |
---|
| 187 | %% once we have the world coordinates, we get the color |
---|
| 188 | %% corresponding to these world coordinates |
---|
| 189 | %% which is the same as finding the x_im and y_im in the correct |
---|
| 190 | %% image |
---|
| 191 | %% so the first step will be to find the right image |
---|
| 192 | currPanAngD = panEndAngD-(panBinIdx/panBins)*panRange; |
---|
| 193 | currPanAngD = (currPanAngD+image2LaserPanAngleOffsetD); |
---|
| 194 | if (currPanAngD>180) |
---|
| 195 | currPanAngD = currPanAngD-360; |
---|
| 196 | elseif (currPanAngD<-180) |
---|
| 197 | currPanAngD = currPanAngD+360; |
---|
| 198 | end |
---|
| 199 | [temp1,temp2]=min(abs(imagePanAngD-currPanAngD)); |
---|
| 200 | rightImageNum = imagePanAngRndD(temp2); |
---|
| 201 | dirList = dir([imgDirectory strcat('*',num2str(abs(rightImageNum)),'*.jpg')]); |
---|
| 202 | if (length(dirList)==0) |
---|
| 203 | problem_list=1 |
---|
| 204 | end |
---|
| 205 | imageFilename = dirList(1).name; |
---|
| 206 | % if (imageFilenamePrev~=imageFilename) |
---|
| 207 | % A = imread([imgDirectory imageFilename]); |
---|
| 208 | % imageFilenamePrev=imageFilename; |
---|
| 209 | % end |
---|
| 210 | |
---|
| 211 | %% the definition of roll, pitch and yaw needs to be checked with |
---|
| 212 | %% Kyle |
---|
| 213 | panAngR = imagePanAngD(temp2)*D2R; |
---|
| 214 | tiltAngR = imageAngList(temp2,3)*D2R; |
---|
| 215 | pixel = getPixelCoords(Wcoord,panAngR,tiltAngR, ... |
---|
| 216 | rigHeight,distCoeffs,camIntMat,UNDISTORT,camExtMat1); |
---|
| 217 | %% the storage format in the pixelreservoir is to store for each |
---|
| 218 | %% value of panBinIdx and sweepBinIdx, the imageNumber and the |
---|
| 219 | %% pixel values in that image |
---|
| 220 | pixelReservoir(panCount,sweepCount,:)=[depthVal rightImageNum pixel]; |
---|
| 221 | sweepCount=sweepCount+1; |
---|
| 222 | end |
---|
| 223 | panCount=panCount+1 |
---|
| 224 | save(depthPixelFilename, 'pixelReservoir'); |
---|
| 225 | end |
---|
| 226 | displayScenario(pixelReservoir,imgDirectory); |
---|