[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 []=genVrmlLaserData()
|
---|
| 40 |
|
---|
| 41 | % this function generate the VRML from the laser depthMap
|
---|
| 42 | % Use this to see if the depthMap makes sense
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | % declaim global variable
|
---|
| 46 | global GeneralDataFolder ScratchDataFolder LocalFolder ClusterExecutionDirectory...
|
---|
| 47 | ImgFolder VertYNuPatch VertYNuDepth HoriXNuPatch HoriXNuDepth a_default b_default Ox_default Oy_default...
|
---|
| 48 | Horizon_default filename;
|
---|
| 49 |
|
---|
| 50 | % load data
|
---|
| 51 | %load([ScratchDataFolder '/data/LowResImgIndexSuperpixelSep.mat']); % superpixel_index
|
---|
| 52 |
|
---|
| 53 | NuPics = size(filename,2);
|
---|
| 54 | for i = 10%1 : NuPics
|
---|
| 55 |
|
---|
| 56 | % 1) load picsinfo
|
---|
| 57 | PicsinfoName = strrep(filename{i},'img','picsinfo');
|
---|
| 58 | temp = dir([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
|
---|
| 59 | if size(temp,1) == 0
|
---|
| 60 | a = a_default;
|
---|
| 61 | b = b_default;
|
---|
| 62 | Ox = Ox_default;
|
---|
| 63 | Oy = Oy_default;
|
---|
| 64 | Horizon = Horizon_default;
|
---|
| 65 | VertYImg = 2272;
|
---|
| 66 | HoriXImg = 1704;
|
---|
| 67 | else
|
---|
| 68 | load([GeneralDataFolder '/PicsInfo/' PicsinfoName '.mat']);
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 | % 2) Loadin the 3d position and corresponding image position generated
|
---|
| 72 | depthfile = strrep(filename{i},'img','depth_sph_corr'); % the depth filename(without .file extension) associate with the *jpg file
|
---|
| 73 | % from Rajiv's code
|
---|
| 74 | temp = dir([ScratchDataFolder '/Gridlaserdata/' depthfile '.mat']);
|
---|
| 75 | if size(temp,1) ~=0
|
---|
| 76 | i
|
---|
| 77 | load([ScratchDataFolder '/Gridlaserdata/' depthfile '.mat']);
|
---|
| 78 | % load([ScratchDataFolder '/laserdata/' depthfile '.mat']);
|
---|
| 79 | %[Position3DGrid] = gen_position3dgrid(depthfile,pixelReservoir,VertYNuDepth,HoriXNuDepth,VertYImg,HoriXImg);
|
---|
| 80 | % ============ changable ================
|
---|
| 81 | %pixelReservoir(:,5) = 1704 - pixelReservoir(:,5);
|
---|
| 82 | %[Position3DGrid] = gen_position3dgrid(depthfile,pixelReservoir,VertYNuDepth,HoriXNuDepth,VertYImg,HoriXImg);
|
---|
| 83 | % =======================================================
|
---|
| 84 |
|
---|
| 85 | % add superpixel index to the laserdata
|
---|
| 86 | % sup = LowResImgIndexSuperpixelSep{i,1};
|
---|
| 87 | % Indices = sub2ind(size(sup),max(min(ceil((pixelReservoir(:,4)/VertYImg)*VertYNuDepth),VertYNuDepth),1),...
|
---|
| 88 | % max(min(ceil((1-pixelReservoir(:,5)/HoriXImg)*HoriXNuDepth),HoriXNuDepth),1));
|
---|
| 89 | % pixelReservoir(:,7) = sup(Indices);
|
---|
| 90 | %save([ScratchDataFolder '/laserdataMin/' depthfile '.mat'],'pixelReservoir');
|
---|
| 91 |
|
---|
| 92 | % generate specific ray for whole pics
|
---|
| 93 | % RayCorner = GenerateRay(HoriXNuDepth,VertYNuDepth,'corner',a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
|
---|
| 94 | RayCenter = GenerateRay(HoriXNuDepth,VertYNuDepth,'center',a,b,Ox,Oy); %[ horiXSizeLowREs VertYSizeLowREs 3]
|
---|
| 95 | Position3D = im_cr2w_cr(Position3DGrid(:,:,4),RayCenter);
|
---|
| 96 | % size(RayCorner)
|
---|
| 97 | % size(RayCenter)
|
---|
| 98 |
|
---|
| 99 | % generate 3d position in camera coordinate
|
---|
| 100 | % ray = cat(3,a*(1-pixelReservoir(:,5)/HoriXImg-Ox),b*(1-pixelReservoir(:,4)/VertYImg-Oy),ones(size(pixelReservoir,1),1));
|
---|
| 101 | % ray = ray./repmat(sqrt(sum(ray(:,:,1).^2+ray(:,:,2).^2+ray(:,:,3).^2,3)),[1 1 3]);
|
---|
| 102 | % Position3DTure=im_cr2w_cr(pixelReservoir(:,6),ray);
|
---|
| 103 |
|
---|
| 104 | % 3) calculate each plane parameter for each superpixel
|
---|
| 105 | % [PlaneParameterTure]=fit_all_planes([ pixelReservoir(:,[2 1 3])...
|
---|
| 106 | % max(min(ceil((pixelReservoir(:,4)/VertYImg)*VertYNuDepth),VertYNuDepth),1) ...
|
---|
| 107 | % max(min(ceil((1-pixelReservoir(:,5)/HoriXImg)*HoriXNuDepth),HoriXNuDepth),1) ...
|
---|
| 108 | % pixelReservoir(:,[7])],Position3DGrid(:,:,[2 1 3 4]),...
|
---|
| 109 | % permute(RayCorner,[3 1 2]),sup); % hard work around 2min
|
---|
| 110 |
|
---|
| 111 | % DepthTureProjPics = 1./sum(RayCenter.*permute(reshape(PlaneParameterTure(1:3,sup),3,VertYNuDepth,HoriXNuDepth),[2 3 1]),3);
|
---|
| 112 | % Position3DTureProjPics=im_cr2w_cr(DepthTureProjPics,RayCenter);
|
---|
| 113 | % Position3DTureProjPics=im_cr2w_cr(DepthTureProjPics,RayCenter);
|
---|
| 114 | % vrml_test_faceset_triangle(filename{i},Position3DTureProjPics,RayCenter,'fit');
|
---|
| 115 | [VrmlName] = vrml_test_faceset_goodSkyBoundary(filename{i},Position3D,Position3DGrid(:,:,4),RayCenter, 'grid',...
|
---|
| 116 | [],[],0,zeros(VertYNuDepth,HoriXNuDepth), zeros(VertYNuDepth,HoriXNuDepth),...
|
---|
| 117 | 1,0,a_default,b_default,Ox_default,Oy_default);
|
---|
| 118 | system(['gzip -9 -c ' ScratchDataFolder '/vrml/' VrmlName ' > ' ScratchDataFolder '/vrml/' VrmlName '.gz']);
|
---|
| 119 | delete([ScratchDataFolder '/vrml/' VrmlName]);
|
---|
| 120 |
|
---|
| 121 | %vrml_test_faceset_triangle(filename{i},permute(Position3DGrid(:,:,1:3),[3 1 2]),RayCenter,'real');
|
---|
| 122 |
|
---|
| 123 | % save
|
---|
| 124 | % PlaneParameter{i} = PlaneParameterTure;
|
---|
| 125 | % DepthTureProj{i} = DepthTureProjPics;
|
---|
| 126 | % Position3DTureProj{i} = Position3DTureProjPics;
|
---|
| 127 | end
|
---|
| 128 | end
|
---|
| 129 |
|
---|
| 130 | %save([ScratchDataFolder '/data/PlaneParameter.mat'], 'PlaneParameter');
|
---|
| 131 | %save([ScratchDataFolder '/data/DepthTureProj.mat'], 'DepthTureProj');
|
---|
| 132 | %save([ScratchDataFolder '/data/Position3DTureProj.mat'], 'Position3DTureProj');
|
---|
| 133 | return;
|
---|