[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 [] = ReInfGivenPersonDetection( defaultPara, ImgName) |
---|
| 40 | |
---|
| 41 | % This function Re-Inference after given Person Detection info |
---|
| 42 | TimeStart = tic; |
---|
| 43 | |
---|
| 44 | % initialized parameters |
---|
| 45 | OutPutFolder = [[defaultPara.Fdir '/Wrl/' ImgName '/']]; |
---|
| 46 | system(['mkdir ' OutPutFolder]); |
---|
| 47 | taskName = 'ObjectDetectionRemoveDepth';%(Not Used) taskname will append to the imagename and form the outputname |
---|
| 48 | Flag.DisplayFlag = 0; |
---|
| 49 | Flag.IntermediateStorage = 0; |
---|
| 50 | Flag.FeaturesOnly = 0; |
---|
| 51 | Flag.FeatureStorage = 0; %Min add May 2nd |
---|
| 52 | Flag.NormalizeFlag = 1; |
---|
| 53 | Flag.BeforeInferenceStorage = 1; |
---|
| 54 | Flag.NonInference = 0; |
---|
| 55 | Flag.AfterInferenceStorage = 1; |
---|
| 56 | ScratchFolder = [defaultPara.Fdir '/data/' ImgName]%IMG_0614'; % ScratchFolder |
---|
| 57 | system(['mkdir ' ScratchFolder]); |
---|
| 58 | ParaFolder = '/afs/cs/group/reconstruction3d/scratch/Para/' |
---|
| 59 | Default = SetupDefault_New(... |
---|
| 60 | [ ImgName '_' taskName],... |
---|
| 61 | ParaFolder,... |
---|
| 62 | OutPutFolder,... |
---|
| 63 | ScratchFolder,... |
---|
| 64 | Flag); |
---|
| 65 | |
---|
| 66 | % extract the Person Detection Box ======================================================== |
---|
| 67 | disp(' Extract the Person Detection Box'); |
---|
| 68 | ImgPersonBox = imread([ defaultPara.Fdir '/Person/' ImgName '.jpg']); |
---|
| 69 | ImgPersonBoxSize = size( ImgPersonBox); |
---|
| 70 | ImgPersonBoxSize = ImgPersonBoxSize(1:2); |
---|
| 71 | Img = imread([ defaultPara.Fdir '/jpg/' ImgName '.jpg']); |
---|
| 72 | ImgResize = imresize(Img, ImgPersonBoxSize, 'nearest'); |
---|
| 73 | fid = fopen([defaultPara.Fdir '/Person/' ImgName '.txt']); |
---|
| 74 | %fgetl(fid);% skip first line which is all zeros |
---|
| 75 | PersonBox = fscanf(fid, '%f', [defaultPara.NumCol, inf]); |
---|
| 76 | PersonBox = PersonBox(1:4,:); |
---|
| 77 | PersonBox = PersonBox'; |
---|
| 78 | % debug purpose only------------------------------ |
---|
| 79 | % PersonBox(:,4) = PersonBox(:,4) - 150; |
---|
| 80 | % ------------------------------------------------ |
---|
| 81 | PersonBox = [ PersonBox(:, [ 2 1]) PersonBox(:, [2 1])+PersonBox(:,[4 3])]; % Data Format [Y_Top X_Right Y_Bottom X_Left] |
---|
| 82 | OutLier = PersonBox(:,3) < ImgPersonBoxSize(1)/4; % remove Squares too high |
---|
| 83 | PersonBox( OutLier, :) = []; |
---|
| 84 | [C I] = sort(PersonBox(:,3));% sort the Box from far to close |
---|
| 85 | PersonBox = PersonBox(I,:); |
---|
| 86 | % PersonBox(1,:) = []; |
---|
| 87 | PersonBox |
---|
| 88 | %return; |
---|
| 89 | NumBox = size(PersonBox,1); |
---|
| 90 | if defaultPara.Flag.Disp |
---|
| 91 | PlotBox( ImgResize, PersonBox); |
---|
| 92 | end |
---|
| 93 | disp([ ' ' num2str(toc( TimeStart))]); |
---|
| 94 | % pause |
---|
| 95 | % ========================================================================================= |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | % load Mono-Model info ==================================================================== |
---|
| 99 | load([defaultPara.Fdir '/data/' ImgName '/' ImgName '__AInfnew.mat']); |
---|
| 100 | SupSize = size(Sup); |
---|
| 101 | |
---|
| 102 | SupO = Sup; |
---|
| 103 | % return; |
---|
| 104 | % ========================================================================================= |
---|
| 105 | |
---|
| 106 | MAGIC_NUMBER_SUP_REJECT_RATIO = 0.5; |
---|
| 107 | % Refine Person Contour and Modify Superpixel ========================================== |
---|
| 108 | disp('Refine Person Contour and Modify Superpixel'); |
---|
| 109 | PersonBoxINSupSize = max( round( PersonBox./repmat( ImgPersonBoxSize./SupSize , NumBox, 2) ), 1); |
---|
| 110 | PersonBoxINSupSize(:,[ 1 3]) = min( PersonBoxINSupSize(:,[ 1 3]), SupSize(1)); |
---|
| 111 | PersonBoxINSupSize(:,[ 2 4]) = min( PersonBoxINSupSize(:,[ 2 4]), SupSize(2)); |
---|
| 112 | PersonBoxINSupSize = RefineBox(Sup, PersonBoxINSupSize, MAGIC_NUMBER_SUP_REJECT_RATIO); |
---|
| 113 | |
---|
| 114 | % prevent the Box in the last row ======= |
---|
| 115 | DetectMark = PersonBoxINSupSize(:,3) >= (size(Sup,1) -1); |
---|
| 116 | PersonBoxINSupSize(DetectMark,3) = (size(Sup,1) -1); |
---|
| 117 | % =================================== |
---|
| 118 | % ======================================= |
---|
| 119 | |
---|
| 120 | PersonBox = round(PersonBoxINSupSize./repmat( size(Sup)./ImgPersonBoxSize,NumBox,2)); |
---|
| 121 | if defaultPara.Flag.Disp |
---|
| 122 | PlotBox( ImgResize, PersonBox,12); |
---|
| 123 | end |
---|
| 124 | %SE = strel('octagon',3); |
---|
| 125 | NHOOD = [[0 1 0];[1 1 1];[0 0 0]]; |
---|
| 126 | %HEIGHT = NHOOD; |
---|
| 127 | %SE = strel('arbitrary',NHOOD,HEIGHT); |
---|
| 128 | for i = 1:NumBox |
---|
| 129 | PersonMask = logical( zeros(size(Sup)) ); |
---|
| 130 | PersonMask( PersonBoxINSupSize(i,1): PersonBoxINSupSize(i,3), ... |
---|
| 131 | PersonBoxINSupSize(i,2): PersonBoxINSupSize(i,4)) = true; |
---|
| 132 | Sup( PersonMask) = -i; |
---|
| 133 | SupO( PersonMask) = -i; |
---|
| 134 | % boundary set to zero |
---|
| 135 | PersonMask_boundry = imdilate( PersonMask, NHOOD); |
---|
| 136 | PersonMask_boundry(PersonMask) = 0; |
---|
| 137 | PersonMask_boundry = logical(PersonMask_boundry); |
---|
| 138 | figure(11); imagesc(PersonMask_boundry); |
---|
| 139 | %pause |
---|
| 140 | Sup(PersonMask_boundry) = 0; |
---|
| 141 | SupO(PersonMask_boundry) = -i; |
---|
| 142 | end |
---|
| 143 | % SupOri = Sup; |
---|
| 144 | % return; |
---|
| 145 | disp([' ' num2str(toc( TimeStart))]); |
---|
| 146 | % ========================================================================================= |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | % Using Person contour info =============================================================== |
---|
| 150 | % 1) Modified MultiScaleSupTable SupNeighborTable |
---|
| 151 | MinSupInd = min(Sup(:));% might be negative |
---|
| 152 | MultiScaleSupTable = [ zeros(MinSupInd, 14);MultiScaleSupTable]; |
---|
| 153 | disp('Modified SupNeighborTable'); |
---|
| 154 | SupNeighborTable = FastSupNeighborTable(Sup); |
---|
| 155 | disp([' ' num2str(toc( TimeStart))]); |
---|
| 156 | % ========================================================================================= |
---|
| 157 | |
---|
| 158 | % Re-Inference ============================================================================ |
---|
| 159 | % need Default Predicted.VarMap |
---|
| 160 | ReportPlaneParaMRF_Conditioned_ObjectDetection( Default, 3, [],... |
---|
| 161 | Sup, SupO, MedSup, full(depthMap), zeros( size( depthMap)), RayOri, Ray, ... % big change |
---|
| 162 | SupNeighborTable, [], maskSky, maskG,... |
---|
| 163 | [], [], MultiScaleSupTable, [], [], [], false, 0); |
---|
| 164 | % ========================================================================================= |
---|
| 165 | |
---|
| 166 | % Constructing Model ====================================================================== |
---|
| 167 | |
---|
| 168 | % ========================================================================================= |
---|
| 169 | %return; |
---|