source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/LearningCode/ObjectDetection/ReInfGivenPersonDetection.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

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