use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TestImplIntegralImageOps method convolveBorder.
public void convolveBorder(Method m) throws InvocationTargetException, IllegalAccessException {
Kernel2D_S32 kernel = new Kernel2D_S32(3, new int[] { 1, 1, 1, 2, 2, 2, 1, 1, 1 });
GrayU8 input = new GrayU8(width, height);
GrayS32 expected = new GrayS32(width, height);
GImageMiscOps.fillUniform(input, rand, 0, 10);
ImageBorder_S32 border = FactoryImageBorderAlgs.value(input, 0);
ConvolveImage.convolve(kernel, input, expected, border);
Class[] paramType = m.getParameterTypes();
Class inputType = paramType[0];
Class outputType = paramType[2];
ImageGray inputII = GeneralizedImageOps.createSingleBand(inputType, width, height);
ImageGray integral = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray expectedII = GeneralizedImageOps.createSingleBand(outputType, width, height);
ImageGray found = GeneralizedImageOps.createSingleBand(outputType, width, height);
GConvertImage.convert(input, inputII);
GConvertImage.convert(expected, expectedII);
GIntegralImageOps.transform(inputII, integral);
IntegralKernel kernelII = new IntegralKernel(2);
kernelII.blocks[0] = new ImageRectangle(-2, -2, 1, 1);
kernelII.blocks[1] = new ImageRectangle(-2, -1, 1, 0);
kernelII.scales = new int[] { 1, 1 };
m.invoke(null, integral, kernelII, found, 4, 5);
BoofTesting.assertEqualsBorder(expected, found, 1e-4f, 4, 5);
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TldDetection method computeTemplateConfidence.
/**
* Computes the confidence for all the regions which pass the fern test
*/
protected void computeTemplateConfidence() {
double max = 0;
for (int i = 0; i < fernRegions.size(); i++) {
ImageRectangle region = fernRegions.get(i);
double confidence = template.computeConfidence(region);
max = Math.max(max, confidence);
if (confidence < config.confidenceThresholdUpper)
continue;
TldRegion r = candidateDetections.grow();
r.connections = 0;
r.rect.set(region);
r.confidence = confidence;
}
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TldDetection method detectionCascade.
/**
* Detects the object inside the image. Eliminates candidate regions using a cascade of tests
*/
protected void detectionCascade(FastQueue<ImageRectangle> cascadeRegions) {
// initialize data structures
success = false;
ambiguous = false;
best = null;
candidateDetections.reset();
localMaximums.reset();
ambiguousRegions.clear();
storageMetric.reset();
storageIndexes.reset();
storageRect.clear();
fernRegions.clear();
fernInfo.reset();
int totalP = 0;
int totalN = 0;
// Run through all candidate regions, ignore ones without enough variance, compute
// the fern for each one
TldRegionFernInfo info = fernInfo.grow();
for (int i = 0; i < cascadeRegions.size; i++) {
ImageRectangle region = cascadeRegions.get(i);
if (!variance.checkVariance(region)) {
continue;
}
info.r = region;
if (fern.lookupFernPN(info)) {
totalP += info.sumP;
totalN += info.sumN;
info = fernInfo.grow();
}
}
fernInfo.removeTail();
// avoid overflow errors in the future by re-normalizing the Fern detector
if (totalP > 0x0fffffff)
fern.renormalizeP();
if (totalN > 0x0fffffff)
fern.renormalizeN();
// Select the ferns with the highest likelihood
selectBestRegionsFern(totalP, totalN);
// From the remaining regions, score using the template algorithm
computeTemplateConfidence();
if (candidateDetections.size == 0) {
return;
}
// use non-maximum suppression to reduce the number of candidates
nonmax.process(candidateDetections, localMaximums);
best = selectBest();
if (best != null) {
ambiguous = checkAmbiguous(best);
success = true;
}
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TldFernClassifier method lookupFernPN.
/**
* 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;
}
use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.
the class TldTracker method createCascadeRegion.
/**
* Creates a list containing all the regions which need to be tested
*/
private void createCascadeRegion(int imageWidth, int imageHeight) {
cascadeRegions.reset();
int rectWidth = (int) (targetRegion.getWidth() + 0.5);
int rectHeight = (int) (targetRegion.getHeight() + 0.5);
for (int scaleInt = -config.scaleSpread; scaleInt <= config.scaleSpread; scaleInt++) {
// try several scales as specified in the paper
double scale = Math.pow(1.2, scaleInt);
// the actual rectangular region being tested at this scale
int actualWidth = (int) (rectWidth * scale);
int actualHeight = (int) (rectHeight * scale);
// see if the region is too small or too large
if (actualWidth < config.detectMinimumSide || actualHeight < config.detectMinimumSide)
continue;
if (actualWidth >= imageWidth || actualHeight >= imageHeight)
continue;
// step size at this scale
int stepWidth = (int) (rectWidth * scale * 0.1);
int stepHeight = (int) (rectHeight * scale * 0.1);
if (stepWidth < 1)
stepWidth = 1;
if (stepHeight < 1)
stepHeight = 1;
// maximum allowed values
int maxX = imageWidth - actualWidth;
int maxY = imageHeight - actualHeight;
// start at (1,1). Otherwise a more complex algorithm needs to be used for integral images
for (int y0 = 1; y0 < maxY; y0 += stepHeight) {
for (int x0 = 1; x0 < maxX; x0 += stepWidth) {
ImageRectangle r = cascadeRegions.grow();
r.x0 = x0;
r.y0 = y0;
r.x1 = x0 + actualWidth;
r.y1 = y0 + actualHeight;
}
}
}
}
Aggregations