[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 []= main( Fdir, PairList, Wrlname, defaultPara); |
---|
| 40 | |
---|
| 41 | % This function is the main function tha handle: |
---|
| 42 | % 1) Extracting info mation : Exif GPS IMU |
---|
| 43 | % 2) Pair Image Metric Reconstruction |
---|
| 44 | |
---|
| 45 | MainTime = tic; % Start counting time ============================= |
---|
| 46 | pause off; |
---|
| 47 | |
---|
| 48 | if nargin < 2 |
---|
| 49 | PairList = []; |
---|
| 50 | end |
---|
| 51 | % initialize parameters |
---|
| 52 | defaultPara.Wrlname = [defaultPara.Wrlname '_' Wrlname]; |
---|
| 53 | |
---|
| 54 | % initialize variables ============================================ |
---|
| 55 | ImgInfo = []; |
---|
| 56 | [status currdir] = system([ 'ls ' Fdir '/data/ModelStatus/']); |
---|
| 57 | if status |
---|
| 58 | [status currdir] = system([ 'mkdir ' Fdir '/data/ModelStatus/']); % Min add July 1st; |
---|
| 59 | end |
---|
| 60 | [status currdir] = system([ 'ls ' Fdir '/info/']); |
---|
| 61 | if status |
---|
| 62 | [status currdir] = system([ 'mkdir ' Fdir '/info/']); % Min add Aug 17th; |
---|
| 63 | end |
---|
| 64 | |
---|
| 65 | if defaultPara.Flag.NewModelList |
---|
| 66 | ImgAddedList = cell(0); % cell array for names |
---|
| 67 | else |
---|
| 68 | load([ Fdir '/data/ModelStatus/' defaultPara.Wrlname '.mat']); |
---|
| 69 | NumImg = length(ModelStatus); |
---|
| 70 | for i = 1:NumImg |
---|
| 71 | ImgAddedList{i} = ModelStatus(i).ImgName; |
---|
| 72 | end |
---|
| 73 | end |
---|
| 74 | |
---|
| 75 | % initialize preacquired infomation ============================== |
---|
| 76 | fprintf('Pre - Acquired Info .....'); |
---|
| 77 | if defaultPara.Flag.FlagImgInfoLoadPreStorage == 0 |
---|
| 78 | [ImgInfo] = ExifExtractDir(Fdir,ImgInfo); % Exif info |
---|
| 79 | % 1) Extracting info |
---|
| 80 | [ImgInfo] = ExtractGPSInfo(defaultPara, Fdir, ImgInfo); % GPS info |
---|
| 81 | [ImgInfo] = ExtractRotationInfo( defaultPara, Fdir, ImgInfo); % IMU info |
---|
| 82 | % write into .kml file for google earth to display |
---|
| 83 | |
---|
| 84 | save([Fdir '/data/ImgInfo.mat'],'ImgInfo'); |
---|
| 85 | elseif defaultPara.Flag.FlagImgInfoLoadPreStorage == 1 |
---|
| 86 | [ImgInfo] = ExifExtractDir(Fdir,ImgInfo); % Exif info |
---|
| 87 | % read from google earth .kml file |
---|
| 88 | temp = dir([Fdir '/info/*.kml']); |
---|
| 89 | [ ImgInfo ] = ExtractGoogleEarthInfo(ImgInfo, [Fdir '/info/' temp.name]); |
---|
| 90 | [ ImgInfo ] = AllXWorld(defaultPara, ImgInfo); %X_world info |
---|
| 91 | % [ImgInfo] = InfoInitialize(ImgInfo); % initialize everything |
---|
| 92 | save([Fdir '/data/ImgInfo.mat'],'ImgInfo'); |
---|
| 93 | elseif defaultPara.Flag.FlagImgInfoLoadPreStorage == 2 |
---|
| 94 | [ImgInfo] = ExifExtractDir(Fdir,ImgInfo); % Exif info |
---|
| 95 | [ImgInfo] = ExtractRotationInfo( defaultPara, Fdir, ImgInfo); % IMU info |
---|
| 96 | % read from google earth .kml file |
---|
| 97 | temp = dir([Fdir '/info/*.kml']); |
---|
| 98 | [ ImgInfo ] = ExtractGoogleEarthInfo(ImgInfo, [Fdir '/info/' temp.name]); |
---|
| 99 | [ ImgInfo ] = AllXWorld(defaultPara, ImgInfo); %X_world info |
---|
| 100 | % [ImgInfo] = InfoInitialize(ImgInfo); % initialize everything |
---|
| 101 | save([Fdir '/data/ImgInfo.mat'],'ImgInfo'); |
---|
| 102 | elseif defaultPara.Flag.FlagImgInfoLoadPreStorage == 3 |
---|
| 103 | [ImgInfo] = ExifExtractDir(Fdir,ImgInfo); % Exif info |
---|
| 104 | save([Fdir '/data/ImgInfo.mat'],'ImgInfo'); |
---|
| 105 | else |
---|
| 106 | load([ Fdir '/data/ImgInfo.mat']); % // used for hand tune GPS and IMU info //Bad |
---|
| 107 | end |
---|
| 108 | disp([' ' num2str( toc( MainTime)) ' seconds.']); |
---|
| 109 | |
---|
| 110 | % SurfFeatures generation ========================================= |
---|
| 111 | fprintf('Calculating Surf Features ......'); |
---|
| 112 | MakeSureSurfDone(defaultPara, ImgInfo); |
---|
| 113 | disp([' ' num2str( toc( MainTime)) ' seconds.']); |
---|
| 114 | |
---|
| 115 | % start loop by getting input ===================================== |
---|
| 116 | NuPair = size(PairList,1); |
---|
| 117 | ReadImgCount = 1; |
---|
| 118 | while length(ImgAddedList) <= length(ImgInfo) |
---|
| 119 | |
---|
| 120 | % request user input |
---|
| 121 | if ReadImgCount > NuPair && defaultPara.Flag.NewInput |
---|
| 122 | disp('enter pair of image''s names'); |
---|
| 123 | if isempty(ImgA) || isempty(ImgB) |
---|
| 124 | ImgA = input('add image A', 's'); |
---|
| 125 | ImgB = input('add image B', 's'); |
---|
| 126 | end |
---|
| 127 | elseif ReadImgCount <= NuPair |
---|
| 128 | ImgA = PairList{ReadImgCount,1}; |
---|
| 129 | ImgB = PairList{ReadImgCount,2}; |
---|
| 130 | else |
---|
| 131 | % if ReadImgCount > NuPair && ~defaultPara.Flag.NewInput |
---|
| 132 | % ( Do not allow to add images manually) |
---|
| 133 | break; |
---|
| 134 | end |
---|
| 135 | |
---|
| 136 | if ReadImgCount == NuPair |
---|
| 137 | defaultPara.LastImgFlag = 1; |
---|
| 138 | end |
---|
| 139 | ReadImgCount = ReadImgCount +1; |
---|
| 140 | |
---|
| 141 | % find ImgInfo index for ImgA ImgB |
---|
| 142 | [ImgAIndex] = ImgInfoIndexFromName(ImgInfo, ImgA); |
---|
| 143 | [ImgBIndex] = ImgInfoIndexFromName(ImgInfo, ImgB); |
---|
| 144 | |
---|
| 145 | % Metric reconstruction |
---|
| 146 | fprintf('Start Metric Reconstruction ....') |
---|
| 147 | [defaultPara NewImgInfo fail] = MetricRecon(defaultPara, ImgInfo([ImgAIndex ImgBIndex])); |
---|
| 148 | disp([' ' num2str( toc( MainTime)) ' seconds.']); |
---|
| 149 | if fail > 0 |
---|
| 150 | disp('Failed ............... End of main.m'); |
---|
| 151 | return; |
---|
| 152 | end |
---|
| 153 | ImgInfo(ImgAIndex ).Model = []; |
---|
| 154 | ImgInfo(ImgBIndex ).Model = []; |
---|
| 155 | ImgInfo(ImgAIndex ) = NewImgInfo(1); |
---|
| 156 | ImgInfo(ImgBIndex ) = NewImgInfo(2); |
---|
| 157 | |
---|
| 158 | % add ImgAddedList with ImgA and ImgB |
---|
| 159 | ImgAddedList{end+1} = ImgA; |
---|
| 160 | ImgAddedList{end+1} = ImgB; |
---|
| 161 | |
---|
| 162 | % reset |
---|
| 163 | ImgA = []; |
---|
| 164 | ImgB = []; |
---|
| 165 | defaultPara.Flag.FlagFirstPair = 0; |
---|
| 166 | end |
---|
| 167 | |
---|
| 168 | pause on; |
---|
| 169 | disp('End of main.m'); |
---|
| 170 | return; |
---|