Search in sources :

Example 51 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TldTracker method track.

/**
 * Updates track region.
 *
 * @param image Next image in the sequence.
 * @return true if the object could be found and false if not
 */
public boolean track(T image) {
    boolean success = true;
    valid = false;
    imagePyramid.process(image);
    template.setImage(image);
    variance.setImage(image);
    fern.setImage(image);
    if (reacquiring) {
        // It can reinitialize if there is a single detection
        detection.detectionCascade(cascadeRegions);
        if (detection.isSuccess() && !detection.isAmbiguous()) {
            TldRegion region = Objects.requireNonNull(detection.getBest());
            reacquiring = false;
            valid = false;
            // set it to the detected region
            ImageRectangle r = region.rect;
            targetRegion.setTo(r.x0, r.y0, r.x1, r.y1);
            // get tracking running again
            tracking.initialize(imagePyramid);
            checkNewTrackStrong(region.confidence);
        } else {
            success = false;
        }
    } else {
        detection.detectionCascade(cascadeRegions);
        // update the previous track region using the tracker
        trackerRegion.setTo(targetRegion);
        boolean trackingWorked = tracking.process(imagePyramid, trackerRegion);
        trackingWorked &= adjustRegion.process(tracking.getPairs(), trackerRegion);
        TldHelperFunctions.convertRegion(trackerRegion, trackerRegion_I32);
        if (hypothesisFusion(trackingWorked, detection.isSuccess())) {
            // if it found a hypothesis and it is valid for learning, then learn
            if (valid && performLearning) {
                learning.updateLearning(targetRegion);
            }
        } else {
            reacquiring = true;
            success = false;
        }
    }
    if (strongMatch) {
        previousTrackArea = targetRegion.area();
    }
    return success;
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 52 with ImageRectangle

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(DogArray<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;
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 53 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TldLearning method learnAmbiguousNegative.

/**
 * Mark regions which were local maximums and had high confidence as negative. These regions were
 * candidates for the tracker but were not selected
 */
protected void learnAmbiguousNegative(Rectangle2D_F64 targetRegion) {
    TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
    if (detection.isSuccess()) {
        TldRegion best = Objects.requireNonNull(detection.getBest());
        // see if it found the correct solution
        double overlap = helper.computeOverlap(best.rect, targetRegion_I32);
        if (overlap <= config.overlapLower) {
            template.addDescriptor(false, best.rect);
        // fern.learnFernNoise(false, best.rect );
        }
        // mark all ambiguous regions as bad
        List<ImageRectangle> ambiguous = detection.getAmbiguousRegions();
        for (int ambiguousIdx = 0; ambiguousIdx < ambiguous.size(); ambiguousIdx++) {
            ImageRectangle r = ambiguous.get(ambiguousIdx);
            overlap = helper.computeOverlap(r, targetRegion_I32);
            if (overlap <= config.overlapLower) {
                fern.learnFernNoise(false, r);
                template.addDescriptor(false, r);
            }
        }
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 54 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class ImplIntegralImageOps method convolveSparse.

public static double convolveSparse(GrayF64 integral, IntegralKernel kernel, int x, int y) {
    double ret = 0;
    int N = kernel.getNumBlocks();
    for (int i = 0; i < N; i++) {
        ImageRectangle r = kernel.blocks[i];
        ret += block_zero(integral, x + r.x0, y + r.y0, x + r.x1, y + r.y1) * kernel.scales[i];
    }
    return ret;
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 55 with ImageRectangle

use of boofcv.struct.ImageRectangle in project BoofCV by lessthanoptimal.

the class TestImplIntegralImageConvolve method convolve.

public void convolve(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);
    BoofTesting.assertEqualsRelative(expected, found, 1e-4f);
}
Also used : Kernel2D_S32(boofcv.struct.convolve.Kernel2D_S32) IntegralKernel(boofcv.alg.transform.ii.IntegralKernel) ImageRectangle(boofcv.struct.ImageRectangle) GrayU8(boofcv.struct.image.GrayU8) ImageGray(boofcv.struct.image.ImageGray) ImageBorder_S32(boofcv.struct.border.ImageBorder_S32) GrayS32(boofcv.struct.image.GrayS32)

Aggregations

ImageRectangle (boofcv.struct.ImageRectangle)57 Test (org.junit.jupiter.api.Test)15 GrayU8 (boofcv.struct.image.GrayU8)12 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)5 ImageGray (boofcv.struct.image.ImageGray)5 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)4 GrayS32 (boofcv.struct.image.GrayS32)4 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)3 GImageGray (boofcv.core.image.GImageGray)3 Point2D_F64 (georegression.struct.point.Point2D_F64)3 Point2D_I32 (georegression.struct.point.Point2D_I32)3 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)3 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 ImageBorder_S32 (boofcv.struct.border.ImageBorder_S32)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)1 DogArray (org.ddogleg.struct.DogArray)1 GrowQueue_F64 (org.ddogleg.struct.GrowQueue_F64)1