![]() |
The Machine Perception Toolbox |
|
#include <probColorSearch.h>
Inheritance diagram for ProbColorSearch:
Public Types | |
enum | SearchType { Max, Mean } |
Public Member Functions | |
int | CreateData (int width, int height, int searchWidth, int searchHeight) |
ProbColorSearch () | |
double | probSearch (SearchType type, RImage< T > &pixels, int size, TSquare< double > &win, TSquare< double > &var, double thresh, int LaplacianPrior) |
~ProbColorSearch () | |
Private Member Functions | |
double | logPrior (int x, int y, double d, TSquare< double > &win, TSquare< double > &var, int LaplacianPrior) |
Private Attributes | |
int | set_height |
int | set_width |
|
Definition at line 37 of file probColorSearch.h. 00037 { 00038 Max, 00039 Mean 00040 };
|
|
Definition at line 55 of file probColorSearch.h. 00055 {};
|
|
Definition at line 58 of file probColorSearch.h. 00058 {};
|
|
|
Definition at line 85 of file probColorSearch.h. References c, d, PI, TSquare::size, sqr, TSquare::x, y, and TSquare::y. Referenced by probSearch(). 00086 { 00087 if (LaplacianPrior == 1){ 00088 // Laplacian prior is the default 00089 const double c = 3*log(2.0) + log(var.x * var.y*var.size); 00090 double zscore = fabs(x-win.x)*var.x + fabs(y-win.y)*var.y + fabs(d-win.size)*var.size; 00091 return ( -c - zscore); 00092 } 00093 else{ // Gaussian prior 00094 const double c = 1.5 * log(2*PI); // log(sqrt(cube(2*PI))) 00095 return (- sqr(x - win.x)*var.x 00096 - sqr(y - win.y)*var.y 00097 - sqr(d - win.size)*var.size 00098 - c - 0.5 * (var.x + var.y + var.size)); 00099 } 00100 }
|
|
Definition at line 103 of file probColorSearch.h. References c, corner, d, FeatureData::features, RImage::height, logPrior(), Max, Mean, Feature::numcorners, p, set_height, set_width, TSquare::size, CornerCache::value, RImage::width, TSquare::x, y, and TSquare::y. Referenced by MPColorTracker::DoSearch(). 00103 { 00104 // Cache the corners 00105 00106 if(pixels.width != set_width || pixels.height != set_height || !stream.allocated) { 00107 stream.reset(pixels.width, pixels.height, data, 1); 00108 set_width = pixels.width; set_height = pixels.height; 00109 } 00110 00111 00112 // Integrate the image 00113 static_cast<RIntegral< T >* >(stream.images[0])->integrate(pixels); 00114 //stream.images[0]->print(); 00115 00116 bool bPrior = var.x > 0 && var.y > 0 && var.size > 0; 00117 bool firstTime = true; 00118 00119 double lpostbest = 0; 00120 double max_llike = 0, llike = 0; 00121 double lprior = 0; // log prior 00122 double ptot = 0; 00123 double d1; 00124 00125 double mx = 0; 00126 double my = 0; 00127 double md = 0; 00128 00129 double sx = 0; 00130 double sy = 0; 00131 double sd = 0; 00132 00133 // Do the search 00134 int scale_index; 00135 float scale_factor; 00136 int x, y; 00137 int numWindows = 0; 00138 00139 MPIImagePyramid<T>::const_iterator scale = stream.mpi->begin(); 00140 MPIImagePyramid<T>::const_iterator last_scale = stream.mpi->end(); 00141 00142 scale_factor = 0; 00143 while ( scale_factor*size < .092*pixels.width) { 00144 scale_index = scale.getScale(scale_factor); 00145 scale++; 00146 } 00147 for( ; scale != last_scale; ++scale){ 00148 // get pointers to cached values for this scale 00149 scale_index = scale.getScale(scale_factor); 00150 //T sf2 = scale_factor * scale_factor; 00151 CornerCache< T > **corners = stream.corners[scale_index]; 00152 CornerCache< T > *feature_corners = corners[0]; 00153 //T *fns = stream.fns[scale_index]; 00154 d1 = scale_factor * size ; 00155 T a,b,c,d; 00156 MPIScaledImage<T>::const_iterator window = (*scale).begin(), last_window = (*scale).end(); 00157 for( ; window != last_window; ++window, ++numWindows){ 00158 // Do the per window computation 00159 llike = 0; 00160 for(int corner = 0; corner < data.features[0].numcorners; corner+=4) { 00161 a = window.getPixel0( feature_corners[corner].scaledIndex ) * feature_corners[corner].value; 00162 b = window.getPixel0( feature_corners[corner+1].scaledIndex ) * feature_corners[corner+1].value; 00163 c = window.getPixel0( feature_corners[corner+2].scaledIndex ) * feature_corners[corner+2].value; 00164 d = window.getPixel0( feature_corners[corner+3].scaledIndex ) * feature_corners[corner+3].value; 00165 llike += a + b + c + d; // this is the result of getFeat 00166 } 00167 00168 if (llike < thresh) { 00169 continue; 00170 } 00171 00172 window.getCoords(x,y); 00173 if (bPrior){ 00174 lprior = logPrior(x,y,d1,win,var,LaplacianPrior); 00175 } 00176 00177 double lpost; 00178 lpost = llike + lprior; 00179 00180 00181 double p = exp(lpost); 00182 ptot += p; 00183 00184 switch(type) { 00185 case Max: 00186 if (firstTime || (lpost > lpostbest)){ 00187 firstTime = false; 00188 mx = x; 00189 my = y; 00190 md = d1; 00191 lpostbest = lpost; 00192 max_llike = llike; 00193 00194 } // end if max 00195 break; 00196 case Mean: 00197 { 00198 // do mean here 00199 mx += p*x; 00200 my += p*y; 00201 md += p * d1; 00202 00203 sx += p*(x*x); 00204 sy += p*(y*y); 00205 sd += p*(d1*d1); 00206 } 00207 break; 00208 default: 00209 break; 00210 } 00211 00212 } // End window loop 00213 } // End scale loop 00214 switch(type) { 00215 case Max: 00216 break; 00217 case Mean: 00218 { 00219 mx /= ptot; 00220 my /= ptot; 00221 md /= ptot; 00222 00223 sx = sx/ptot - mx*mx; 00224 sy = sy/ptot - mx*mx; 00225 sd = sd/ptot - mx*mx; 00226 } 00227 break; 00228 default: 00229 break; 00230 } 00231 win = TSquare<double>(md,mx,my,0); 00232 var = TSquare<double>(sd,sx,sy,0); 00233 00234 if(type == Max) { 00235 return max_llike; 00236 } 00237 00238 //get value of mean feature need to update fimage to random access x,y before implement 00239 /*int scale = (int) (md/size); 00240 int a = static_cast<int>((mx - 1)); 00241 int b = static_cast<int>((my - 1)); 00242 double f = 0; 00243 00244 for(int corner = 0; corner < data.feature[0].numcorners; corner++) { 00245 00246 f+= ii.getPixel(a + scale * data.feature[0].corners[corner].x, 00247 b + scale * data.feature[0].corners[corner].y) 00248 * data.feature[0].corners[corner].value; 00249 00250 } // end feature loop 00251 return f;*/ 00252 return -1; 00253 00254 }
|
Here is the call graph for this function:
|
Definition at line 49 of file probColorSearch.h. Referenced by CreateData(), and probSearch(). |
|
Definition at line 49 of file probColorSearch.h. Referenced by CreateData(), and probSearch(). |