The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

createMPIWeightsCode.m

Go to the documentation of this file.
00001 %
00002 %  createCiCode.m
00003 %    Generates c++ code for compiling mpisearch features into
00004 %    binary library
00005 % 
00006 %   Copyright (c) 2002 Machine Perception Laboratory 
00007 %   University of California San Diego.
00008 % 
00009 % Please read the disclaimer and notes about redistribution 
00010 % at the end of this file. 
00011 % 
00012 function createMPIWeightsCode(data,name, varargin)
00013 if ischar(data)
00014   load(data)
00015 else
00016   ci = data;
00017 end
00018 real_fun = 0;
00019 preserve_aH = 0;
00020 if isfield(ci,'trainAttr')
00021   if isAttr(ci, 'densityEst')
00022     real_fun = 1;
00023   end
00024   if isAttr(ci, 'preserve_aH')
00025     preserve_aH = 1;
00026   end
00027 end
00028 numCascade = ci.numCascade;
00029 numClassifiers = ci.numClassifiers;
00030 numStdAdjusts = length(ci.std_adjust);
00031 if ~isfield(ci,'plus_minus_one')
00032   ci.plus_minus_one = 0;
00033 end
00034 if ~isfield(ci,'patchSize')
00035   ci.patchSize = ci.nI;
00036 end
00037 if ~isfield(ci,'nI')
00038   ci.nI = ci.patchSize;
00039 end
00040 if ~isfield(ci,'nJ')
00041   ci.nJ = ci.patchSize;
00042 end
00043 
00044 mirrorx = 0;
00045 if (nargin == 3)
00046   if (varargin{1} == 1)
00047     mirrorx = 1;
00048   end
00049 end  
00050 fid = fopen([name,'.h'], 'w');
00051 
00052 fprintf(fid, ['/*********** File: ',name,'.h ***********\n']);
00053 fprintf(fid, 'FILE GENERATED FROM MATLAB\n');
00054 fprintf(fid, 'In Matlab:\n');
00055 fprintf(fid, '\t>> createMPIWeightsCodeCode(datafile,name)\n');
00056 fprintf(fid, '************************************/\n\n');
00057 
00058 fprintf(fid, ['#ifndef __',name,'_H__\n#define __',name,'_H__\n\n'])
00059 fprintf(fid, '#include "config.h"\n#include "featuredata.h"\n')
00060 if(isfield(ci,'centering'))
00061   fprintf(fid, '#include "eyefinder.h"\n\n')
00062 end
00063 fprintf(fid, ['namespace ',name,'{\n']);
00064 if(isfield(ci,'centering'))
00065   fprintf(fid, ['\tvoid assignData(MPEyeFinder *ef, FeatureData &d);\n']);
00066 else 
00067   fprintf(fid, ['\tvoid assignData(FeatureData &d);\n']);
00068 end
00069 
00070 
00071 
00072 fprintf(fid, '};\n\n');
00073 fprintf(fid, '#endif\n\n');
00074 fclose(fid);
00075 
00076 fid = fopen([name,'.cc'], 'w');
00077 
00078 fprintf(fid,['/*\n',...
00079              ' * ',name,'.cc\n',...
00080              ' *\n',...
00081              ' *  Copyright (c) 2002 Machine Perception Laboratory \n',...
00082              ' *  University of California San Diego.\n',...
00083              ' * \n',...
00084              ' * Please read the disclaimer and notes about redistribution \n',...
00085              ' * at the end of this file.\n',...
00086              ' *\n',...
00087              ' */\n\n']);
00088 
00089 fprintf(fid, ['#include "',name,'.h"\n\n'])
00090 
00091 fprintf(fid, ['namespace ',name,'{\n']);
00092 fprintf(fid, '\tstatic float stdAdj[%d] = {\n', numStdAdjusts);
00093 fprintf(fid, '\t\t1.0f,\n');
00094 for(i=2:numStdAdjusts)
00095   fprintf(fid, '\t\t%gf', ci.std_adjust(i));
00096   if (i < numStdAdjusts)
00097     fprintf(fid, ',\n');
00098   end
00099 end
00100 fprintf(fid, '};\n\n');
00101 
00102 fprintf(fid, '\tstatic Cascade casc[%d] = {\n', numCascade);
00103 
00104 for(i=1:numCascade)
00105         tempthresh = ci.cascade(i).thresh;
00106 
00107 %       if i == 38 
00108 %               tempthresh = 16.0;
00109 %       elseif i == 39
00110 %               tempthresh = 28.0;
00111 %       end
00112 
00113     fprintf(fid, '\t\t{%d, %d, %ff}', ci.cascade(i).start-1, ci.cascade(i).end-1, tempthresh);
00114     if (i < numCascade)
00115       fprintf(fid, ',\n');
00116     end
00117 end
00118 fprintf(fid, '};\n\n');
00119 
00120 for(i=1:numClassifiers)
00121   fprintf(fid, '\tstatic Corner Corners%d[%d] = {\n', i-1, length(ci.shape_feature(i).j));
00122   for(j=1:length(ci.shape_feature(i).j))
00123     fprintf(fid, '\t\t{%d, %d, %d}', ci.shape_feature(i).j(j)-1, ...
00124             ci.shape_feature(i).i(j)-1, ci.shape_feature(i).c(j));
00125     if (j < length(ci.shape_feature(i).j))
00126       fprintf(fid, ',\n');
00127     end
00128   end
00129   fprintf(fid, '};\n\n');
00130 end
00131 
00132 if(real_fun)
00133   for(i=1:numClassifiers)
00134     fprintf(fid, '\tstatic double RealFun%d[%d] = {\n', i-1, ci.nl+1);
00135     fprintf(fid, '%d, ',ci.Weights{i}(1));
00136     fprintf(fid, '%d, ',ci.Weights{i}(1:end-1));
00137     fprintf(fid, '%d};\n\n',ci.Weights{i}(end));
00138   end
00139 end
00140 
00141 
00142 fprintf(fid, '\tstatic Feature f[%d] = {\n', numClassifiers);
00143 if(~real_fun)
00144   for(i=1:numClassifiers)
00145     z = cell2struct(ci.Weights(i),'wt',2);
00146     fprintf(fid, '\t\t{%d, %d, %ff, %ff, %d, %d, 0, 0, Corners%d}', i-1, length(ci.shape_feature(i).j), ci.Alphas(i), ci.Bias(i), z.wt, ci.abs(i), i-1);
00147     if (i < numClassifiers)
00148       fprintf(fid, ',\n');
00149     end
00150   end
00151 else
00152   % ci.nl
00153   for(i=1:numClassifiers)
00154     z = cell2struct(ci.Weights(i),'wt',2);
00155     fprintf(fid, '\t\t{%d, %d, 0.0f, %df, 0, 0, %d, RealFun%d, Corners%d}', i-1, ...
00156             length(ci.shape_feature(i).j), ci.Bias(i,1), ci.nl/(ci.Bias(i,2)-ci.Bias(i,1)), i-1, i-1);
00157     if (i < numClassifiers)
00158       fprintf(fid, ',\n');
00159     end
00160   end  
00161 end
00162 fprintf(fid, '\t};\n\n');
00163 
00164 if(isfield(ci,'centering'))
00165   fprintf(fid, ['    void ',name,'::assignData(MPEyeFinder *ef, FeatureData &d){\n']);
00166 else 
00167   fprintf(fid, ['    void ',name,'::assignData(FeatureData &d){\n']);
00168 end
00169 fprintf(fid, '\td.patchsize=%d;\n',ci.patchSize);
00170 fprintf(fid, '\td.patch_width=%d;\n',ci.nJ);
00171 fprintf(fid, '\td.patch_height=%d;\n',ci.nI);
00172 fprintf(fid, '\td.plus_minus_one=%d;\n',ci.plus_minus_one);
00173 fprintf(fid, '\td.preserve_aH=%d;\n',preserve_aH);
00174 fprintf(fid, '\td.numfeatures=%d;\n',numClassifiers);
00175 fprintf(fid, '\td.numcascades=%d;\n',numCascade);
00176 fprintf(fid, '\td.cascades = casc;\n');
00177 fprintf(fid, '\td.features = f;\n');
00178 fprintf(fid, '\td.normOffset.top = %d;\n', ci.hwi(1)-1);
00179 fprintf(fid, '\td.normOffset.left = %d;\n', ci.hwj(1)-1);
00180 fprintf(fid, '\td.normOffset.right = %d;\n', ci.nJ-1-ci.hwj(4));
00181 fprintf(fid, '\td.normOffset.bottom = %d;\n', ci.nI-1-ci.hwi(4));
00182 fprintf(fid, '\td.numStdAdjusts=%d;\n',numStdAdjusts);
00183 fprintf(fid, '\td.stdAdjusts = stdAdj;\n');
00184 if(real_fun)
00185   fprintf(fid, '\td.real_fun = true;\n');
00186   fprintf(fid, '\td.nl=%d; 
00187 else
00188   fprintf(fid, '\td.real_fun = false;\n');  
00189 end
00190 if(isfield(ci,'centering'))
00191   fprintf(fid, ['\tef->SetCentering(',ci.centering,');\n']);
00192 end
00193 if(isfield(ci,'patch_condition'))
00194   fprintf(fid, ['\tef->SetRez(',ci.patch_condition,');\n']);
00195 end  
00196 
00197 fprintf(fid, '    }\n');
00198 fprintf(fid, '};\n');
00199 
00200 fclose(fid);
00201 
00202 
00203 
00204 %%%%%%%%%%%%%%%%%%%%%
00205 % Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
00206 % 
00207 %    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00208 %    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
00209 %    3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
00210 % 
00211 % THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

Generated on Mon Nov 8 17:07:32 2004 for MPT by  doxygen 1.3.9.1