/** * For the specified regions, computes the values of each fern inside of it and then retrives their P and N values. * The sum of which is stored inside of info. * @param info (Input) Location/Rectangle (output) P and N values * @return true if a known value for any of the ferns was observed in this region */ public boolean lookupFernPN( TldRegionFernInfo info ) { ImageRectangle r = info.r; float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2.0f; float c_y = r.y0+(rectHeight-1)/2.0f; int sumP = 0; int sumN = 0; for( int i = 0; i < ferns.length; i++ ) { TldFernDescription fern = ferns[i]; int value = computeFernValue(c_x, c_y, rectWidth, rectHeight, fern); TldFernFeature f = managers[i].table[value]; if( f != null ) { sumP += f.numP; sumN += f.numN; } } info.sumP = sumP; info.sumN = sumN; return sumN != 0 || sumP != 0; }
/** * Learns a fern from the specified region. No noise is added. */ public void learnFern(boolean positive, ImageRectangle r) { float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2f; float c_y = r.y0+(rectHeight-1)/2f; for( int i = 0; i < ferns.length; i++ ) { // first learn it with no noise int value = computeFernValue(c_x, c_y, rectWidth, rectHeight,ferns[i]); TldFernFeature f = managers[i].lookupFern(value); increment(f,positive); } }
/** * Computes the value for each fern inside the region and update's their P and N value. Noise is added * to the image measurements to take in account the variability. */ public void learnFernNoise(boolean positive, ImageRectangle r) { float rectWidth = r.getWidth(); float rectHeight = r.getHeight(); float c_x = r.x0+(rectWidth-1)/2.0f; float c_y = r.y0+(rectHeight-1)/2.0f; for( int i = 0; i < ferns.length; i++ ) { // first learn it with no noise int value = computeFernValue(c_x, c_y, rectWidth, rectHeight,ferns[i]); TldFernFeature f = managers[i].lookupFern(value); increment(f,positive); for( int j = 0; j < numLearnRandom; j++ ) { value = computeFernValueRand(c_x, c_y, rectWidth, rectHeight,ferns[i]); f = managers[i].lookupFern(value); increment(f,positive); } } }