Search in sources :

Example 36 with ImageRectangle

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

the class ImplIntegralImageOps method convolve.

public static void convolve(GrayS64 integral, IntegralKernel kernel, GrayS64 output) {
    for (int y = 0; y < integral.height; y++) {
        for (int x = 0; x < integral.width; x++) {
            long total = 0;
            for (int i = 0; i < kernel.blocks.length; i++) {
                ImageRectangle b = kernel.blocks[i];
                total += block_zero(integral, x + b.x0, y + b.y0, x + b.x1, y + b.y1) * kernel.scales[i];
            }
            output.set(x, y, total);
        }
    }
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 37 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 = detection.getBest();
            reacquiring = false;
            valid = false;
            // set it to the detected region
            ImageRectangle r = region.rect;
            targetRegion.set(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.set(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 38 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 = 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 (ImageRectangle r : ambiguous) {
            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 39 with ImageRectangle

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

the class TldLearning method initialLearning.

/**
 * Select positive and negative examples based on the region the user's initially selected region.  The selected
 * region is used as a positive example while all the other regions far away are used as negative examples.
 *
 * @param targetRegion user selected region
 * @param cascadeRegions Set of regions used by the cascade detector
 */
public void initialLearning(Rectangle2D_F64 targetRegion, FastQueue<ImageRectangle> cascadeRegions) {
    storageMetric.reset();
    fernNegative.clear();
    // learn the initial descriptor
    TldHelperFunctions.convertRegion(targetRegion, targetRegion_I32);
    // select the variance the first time using user selected region
    variance.selectThreshold(targetRegion_I32);
    // add positive examples
    template.addDescriptor(true, targetRegion_I32);
    fern.learnFernNoise(true, targetRegion_I32);
    // Find all the regions which can be used to learn a negative descriptor
    for (int i = 0; i < cascadeRegions.size; i++) {
        ImageRectangle r = cascadeRegions.get(i);
        // see if it passes the variance test
        if (!variance.checkVariance(r))
            continue;
        // learn features far away from the target region
        double overlap = helper.computeOverlap(targetRegion_I32, r);
        if (overlap > config.overlapLower)
            continue;
        fernNegative.add(r);
    }
    // randomize which regions are used
    // Collections.shuffle(fernNegative,rand);
    // Math.min(config.numNegativeFerns,fernNegative.size());
    int N = fernNegative.size();
    for (int i = 0; i < N; i++) {
        fern.learnFern(false, fernNegative.get(i));
    }
    // run detection algorithm and if there is an ambiguous solution mark it as not target
    detection.detectionCascade(cascadeRegions);
    learnAmbiguousNegative(targetRegion);
}
Also used : ImageRectangle(boofcv.struct.ImageRectangle)

Example 40 with ImageRectangle

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

the class VideoSequenceSimulator method convexFill.

private void convexFill(Polygon2D_I32 poly, ImageGray image, double value) {
    int minX = Integer.MAX_VALUE;
    int maxX = Integer.MIN_VALUE;
    int minY = Integer.MAX_VALUE;
    int maxY = Integer.MIN_VALUE;
    for (int i = 0; i < poly.size(); i++) {
        Point2D_I32 p = poly.vertexes.data[i];
        if (p.y < minY) {
            minY = p.y;
        } else if (p.y > maxY) {
            maxY = p.y;
        }
        if (p.x < minX) {
            minX = p.x;
        } else if (p.x > maxX) {
            maxX = p.x;
        }
    }
    ImageRectangle bounds = new ImageRectangle(minX, minY, maxX, maxY);
    BoofMiscOps.boundRectangleInside(image, bounds);
    Point2D_F64 p = new Point2D_F64();
    Polygon2D_F64 poly64 = new Polygon2D_F64(4);
    for (int i = 0; i < 4; i++) poly64.vertexes.data[i].set(poly.vertexes.data[i].x, poly.vertexes.data[i].y);
    for (int y = bounds.y0; y < bounds.y1; y++) {
        p.y = y;
        for (int x = bounds.x0; x < bounds.x1; x++) {
            p.x = x;
            if (Intersection2D_F64.containConvex(poly64, p)) {
                GeneralizedImageOps.set(image, x, y, value);
            }
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) ImageRectangle(boofcv.struct.ImageRectangle) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Aggregations

ImageRectangle (boofcv.struct.ImageRectangle)43 Test (org.junit.Test)15 GrayU8 (boofcv.struct.image.GrayU8)10 IntegralKernel (boofcv.alg.transform.ii.IntegralKernel)3 FactoryGImageGray (boofcv.core.image.FactoryGImageGray)3 GImageGray (boofcv.core.image.GImageGray)3 ImageGray (boofcv.struct.image.ImageGray)3 ImageBorder_S32 (boofcv.core.image.border.ImageBorder_S32)2 Kernel2D_S32 (boofcv.struct.convolve.Kernel2D_S32)2 GrayS32 (boofcv.struct.image.GrayS32)2 Point2D_F32 (georegression.struct.point.Point2D_F32)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Point2D_I32 (georegression.struct.point.Point2D_I32)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)1 FastQueue (org.ddogleg.struct.FastQueue)1 GrowQueue_F64 (org.ddogleg.struct.GrowQueue_F64)1