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

mpisearchMexData Namespace Reference


Functions

bool loadStruct (const mxArray **ci, FeatureData &thedata)
void releaseStruct (FeatureData &thedata)


Function Documentation

bool loadStruct const mxArray **  ci,
FeatureData thedata
 

Definition at line 25 of file loadstruct.cc.

References Feature::abs, Feature::alpha, Feature::bias, OffsetWindow::bottom, cascade, FeatureData::cascades, corner, Feature::corners, Cascade::end, feature, FeatureData::features, i, Feature::id, OffsetWindow::left, FeatureData::nl, Feature::nl_over_range, FeatureData::normOffset, FeatureData::numcascades, numClassifiers, Feature::numcorners, FeatureData::numfeatures, FeatureData::numStdAdjusts, FeatureData::patch_height, FeatureData::patch_width, FeatureData::patchsize, FeatureData::plus_minus_one, FeatureData::preserve_aH, FeatureData::real_fun, OffsetWindow::right, Cascade::start, FeatureData::stdAdjusts, Cascade::thresh, OffsetWindow::top, Feature::tuning_curve, Corner::value, Feature::weight, Corner::x, and Corner::y.

Referenced by MPEyeFinderMex::MPEyeFinderMex(), and MPISearchMex::MPISearchMex().

00026 {
00027   // cout << "entered load struct" << endl;
00028   int trainAttr = -1;
00029   int nfields = mxGetNumberOfFields(*ci);
00030   thedata.plus_minus_one = 0;
00031   //cout << "nfields: " << nfields << endl;
00032   int patchSizeField = -1;
00033   // check for possibly missing fields
00034   for(int i = 0; i < nfields; ++i){
00035     const char * field = mxGetFieldNameByNumber(*ci, i);
00036     if(!strcmp(field, "trainAttr"))
00037       trainAttr = i;
00038     // plus_minus_one is bogus here..? Should be below!
00039     if(!strcmp(field, "plus_minus_one"))
00040       thedata.plus_minus_one = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "plus_minus_one")));
00041     if(!strcmp(field, "patchSize"))
00042       patchSizeField = i;
00043   }
00044   // cout << "trainAttr: " << trainAttr << endl;
00045   thedata.real_fun = false;
00046   thedata.preserve_aH = 0;
00047   char *attrBuff;
00048   attrBuff = (char *)malloc(sizeof(char) * 256);
00049   if(trainAttr >= 0 ){
00050     int nAttr = mxGetNumberOfElements(mxGetFieldByNumber(*ci, 0, trainAttr));
00051     for(int i = 0; i < nAttr; ++i){
00052       mxGetString(mxGetCell(mxGetFieldByNumber(*ci, 0, trainAttr), i), attrBuff, 256);
00053       if(!strcmp(attrBuff, "densityEst"))
00054          thedata.real_fun = true;
00055       if(!strcmp(attrBuff, "preserve_aH"))
00056          thedata.preserve_aH = 1;
00057       if(!strcmp(attrBuff, "plus_minus_one"))
00058          thedata.plus_minus_one = 1;
00059     }
00060   }
00061   free(attrBuff);
00062   // cout << "thedata.real_fun: " << thedata.real_fun << endl;
00063   if(patchSizeField != -1){
00064     thedata.patchsize = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "patchSize")));
00065     thedata.patch_height =  thedata.patchsize;
00066     thedata.patch_width =  thedata.patchsize;
00067   } else {
00068     thedata.patch_height = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "nI")));
00069     thedata.patch_width = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "nJ")));
00070     thedata.patchsize = thedata.patch_width;
00071   }
00072   // cout << "patchSize: " << thedata.patchsize << endl;
00073 
00074   // get normalization window
00075   double *hwi, *hwj;
00076   hwi = mxGetPr(mxGetField(*ci, 0, "hwi"));
00077   hwj = mxGetPr(mxGetField(*ci, 0, "hwj"));
00078   //cout << "hwi[0,3]: " << hwi[0] << " " << hwi[3] << endl;
00079   //cout << "hwj[0,3]: " << hwj[0] << " " << hwj[3] << endl;
00080   thedata.normOffset.left = static_cast<int>(hwj[0])-1;
00081   thedata.normOffset.top = static_cast<int>(hwi[0])-1;
00082   thedata.normOffset.right = thedata.patch_width-static_cast<int>(hwj[3])-1;
00083   thedata.normOffset.bottom = thedata.patch_height-static_cast<int>(hwi[3])-1;
00084   //cout << "normOffset[l,t,r,b]: " << thedata.normOffset.left << " " << thedata.normOffset.top << " ";
00085   //cout << thedata.normOffset.right << " " << thedata.normOffset.bottom << endl;
00086   if(thedata.real_fun){
00087     thedata.nl = static_cast<int>(*(mxGetPr(mxGetField(*ci, 0, "nl"))));
00088   }
00089   
00090   // Get stdAdjusts
00091   thedata.numStdAdjusts = static_cast<int>(mxGetNumberOfElements(mxGetField(*ci, 0, "std_adjust")));
00092   thedata.stdAdjusts = new float[thedata.numStdAdjusts];
00093   for(int i = 0; i < thedata.numStdAdjusts; ++i){
00094     thedata.stdAdjusts[i] = static_cast<float>(*(mxGetPr(mxGetField(*ci, 0, "std_adjust"))+i));
00095   }
00096 
00097   // Get cascades
00098   thedata.numcascades = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "numCascade")));
00099   thedata.cascades = new Cascade[thedata.numcascades];
00100   for(int i=0; i < thedata.numcascades; i++) {
00101     Cascade *cascade = thedata.cascades + i;
00102     cascade->start = static_cast<int>((*mxGetPr(mxGetField(mxGetField(*ci, 0, "cascade"), i, "start")))-1);
00103     cascade->end = static_cast<int>((*mxGetPr(mxGetField(mxGetField(*ci, 0, "cascade"), i, "end")))-1);
00104     cascade->thresh = static_cast<float>(*mxGetPr(mxGetField(mxGetField(*ci, 0, "cascade"), i, "thresh")));
00105   }  
00106   
00107   // iterate through the Features
00108   int numClassifiers = static_cast<int>(*mxGetPr(mxGetField(*ci, 0, "numClassifiers")));
00109   thedata.numfeatures = numClassifiers;
00110   thedata.features = new Feature[thedata.numfeatures];
00111   for(int i = 0; i < numClassifiers; ++i) {     
00112     Feature * feature = thedata.features + i;
00113     if(!thedata.real_fun){
00114       feature->id = i; //(*mxGetPr(mxGetCell(mxGetField(*ci, 0, "Weights"), i)));
00115       feature->alpha = static_cast<float>(*(mxGetPr(mxGetField(*ci, 0, "Alphas"))+i));
00116       feature->bias = static_cast<float>(*(mxGetPr(mxGetField(*ci, 0, "Bias"))+i));
00117       feature->weight = static_cast<int>(*mxGetPr(mxGetCell(mxGetField(*ci, 0, "Weights"), i)));
00118       feature->abs = static_cast<int>(*(mxGetPr(mxGetField(*ci, 0, "abs"))+i));
00119     } else {
00120       feature->id = i;
00121       feature->alpha = 1;
00122       feature->bias = static_cast<float>(*(mxGetPr(mxGetField(*ci, 0, "Bias"))+i));
00123       feature->tuning_curve = new double[thedata.nl+1];
00124       double * weights_array = mxGetPr(mxGetCell(mxGetField(*ci, 0, "Weights"), i));
00125       feature->tuning_curve[0] = *weights_array;
00126       for(int j=0; j < thedata.nl; ++j)
00127          feature->tuning_curve[j+1] = *(weights_array+j);
00128       //cout << "Weights: ";
00129       //for(int j = 0; j <= thedata.nl; ++j)
00130       //cout << " " << feature->tuning_curve[j];
00131       //cout << endl;
00132       double top, bot;
00133       top = *(mxGetPr(mxGetField(*ci, 0, "Bias"))+(numClassifiers+i));
00134       bot = *(mxGetPr(mxGetField(*ci, 0, "Bias"))+i);
00135       feature->nl_over_range = thedata.nl/(top-bot);
00136       // cout << "feature->nl_over_range = " << feature->nl_over_range << endl;
00137     }
00138 
00139     feature->numcorners = static_cast<int>(mxGetNumberOfElements(mxGetField(mxGetField(*ci, 0, "shape_feature"), i, "i")));
00140     feature->corners = new Corner[feature->numcorners];
00141     for(int j=0;j < feature->numcorners; j++) {
00142       Corner * corner = feature->corners + j;
00143       corner->x = static_cast<int>(*(mxGetPr(mxGetField(mxGetField(*ci, 0, "shape_feature"), i, "j"))+j)-1);
00144       corner->y = static_cast<int>(*(mxGetPr(mxGetField(mxGetField(*ci, 0, "shape_feature"), i, "i"))+j)-1);
00145       corner->value = static_cast<int>(*(mxGetPr(mxGetField(mxGetField(*ci, 0, "shape_feature"), i, "c"))+j));
00146     }
00147   }
00148   //cout << "Exiting from loadStruct" << endl;
00149   return true;
00150 }

void releaseStruct FeatureData thedata  ) 
 

Definition at line 152 of file loadstruct.cc.

References FeatureData::cascades, Feature::corners, FeatureData::features, i, FeatureData::numcascades, FeatureData::numfeatures, FeatureData::real_fun, FeatureData::stdAdjusts, and Feature::tuning_curve.

Referenced by MPEyeFinderMex::~MPEyeFinderMex(), and MPISearchMex::~MPISearchMex().

00152                                                         {
00153   //cout << "Entered mpisearchMexData::releaseStruct" << endl;
00154   delete[] thedata.stdAdjusts;
00155   for(int i = 0; i < thedata.numfeatures; i++) {
00156     delete [] thedata.features[i].corners;
00157     if(thedata.real_fun)
00158       delete [] thedata.features[i].tuning_curve;
00159   }
00160   delete[] thedata.features;
00161   delete[] thedata.cascades;  
00162   thedata.cascades = NULL;
00163   thedata.features = NULL;
00164   thedata.numfeatures = 0;
00165   thedata.numcascades = 0;
00166   //cout << "exited mpisearchMexData::releaseStruct" << endl;
00167 }


Generated on Mon Nov 8 17:08:50 2004 for MPT by  doxygen 1.3.9.1