Search in sources :

Example 6 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class SplitMergeLineFitLoop method splitSegments.

/**
 * Splits a line in two if there is a point that is too far away
 * @return true for change
 */
protected boolean splitSegments() {
    boolean change = false;
    work.reset();
    for (int i = 0; i < splits.size - 1; i++) {
        change |= checkSplit(change, i, i + 1);
    }
    change |= checkSplit(change, splits.size - 1, 0);
    // swap the two lists
    GrowQueue_I32 tmp = work;
    work = splits;
    splits = tmp;
    return change;
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 7 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class SplitMergeLineFitSegment method splitSegments.

/**
 * Splits a line in two if there is a paint that is too far away
 * @return true for change
 */
protected boolean splitSegments() {
    boolean change = false;
    work.reset();
    for (int i = 0; i < splits.size - 1; i++) {
        int start = splits.data[i];
        int end = splits.data[i + 1];
        int bestIndex = selectSplitBetween(start, end);
        if (bestIndex >= 0) {
            change |= true;
            work.add(start);
            work.add(bestIndex);
        } else {
            work.add(start);
        }
    }
    work.add(splits.data[splits.size - 1]);
    // swap the two lists
    GrowQueue_I32 tmp = work;
    work = splits;
    splits = tmp;
    return change;
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 8 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class ExampleSegmentSuperpixels method visualize.

/**
 * Visualizes results three ways.  1) Colorized segmented image where each region is given a random color.
 * 2) Each pixel is assigned the mean color through out the region. 3) Black pixels represent the border
 * between regions.
 */
public static <T extends ImageBase<T>> void visualize(GrayS32 pixelToRegion, T color, int numSegments) {
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    // Draw each region using their average color
    BufferedImage outColor = VisualizeRegions.regionsColor(pixelToRegion, segmentColor, null);
    // Draw each region by assigning it a random color
    BufferedImage outSegments = VisualizeRegions.regions(pixelToRegion, numSegments, null);
    // Make region edges appear red
    BufferedImage outBorder = new BufferedImage(color.width, color.height, BufferedImage.TYPE_INT_RGB);
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0xFF0000, outBorder);
    // Show the visualization results
    ListDisplayPanel gui = new ListDisplayPanel();
    gui.addImage(outColor, "Color of Segments");
    gui.addImage(outBorder, "Region Borders");
    gui.addImage(outSegments, "Regions");
    ShowImages.showWindow(gui, "Superpixels", true);
}
Also used : ListDisplayPanel(boofcv.gui.ListDisplayPanel) ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 9 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class ExampleMultiviewSceneReconstruction method initialize.

/**
 * Initialize the 3D world given these two images.  imageA is assumed to be the origin of the world.
 */
private void initialize(int imageA, int imageB) {
    System.out.println("Initializing 3D world using " + imageA + " and " + imageB);
    // Compute the 3D pose and find valid image features
    Se3_F64 motionAtoB = new Se3_F64();
    List<AssociatedIndex> inliers = new ArrayList<>();
    if (!estimateStereoPose(imageA, imageB, motionAtoB, inliers))
        throw new RuntimeException("The first image pair is a bad keyframe!");
    motionWorldToCamera[imageB].set(motionAtoB);
    estimatedImage[imageB] = true;
    processedImage[imageB] = true;
    // create tracks for only those features in the inlier list
    FastQueue<Point2D_F64> pixelsA = imagePixels.get(imageA);
    FastQueue<Point2D_F64> pixelsB = imagePixels.get(imageB);
    List<Feature3D> tracksA = imageFeature3D.get(imageA);
    List<Feature3D> tracksB = imageFeature3D.get(imageB);
    GrowQueue_I32 colorsA = imageColors.get(imageA);
    for (int i = 0; i < inliers.size(); i++) {
        AssociatedIndex a = inliers.get(i);
        Feature3D t = new Feature3D();
        t.color = colorsA.get(a.src);
        t.obs.grow().set(pixelsA.get(a.src));
        t.obs.grow().set(pixelsB.get(a.dst));
        t.frame.add(imageA);
        t.frame.add(imageB);
        // compute the 3D coordinate of the feature
        Point2D_F64 pa = pixelsA.get(a.src);
        Point2D_F64 pb = pixelsB.get(a.dst);
        if (!triangulate.triangulate(pa, pb, motionAtoB, t.worldPt))
            continue;
        // the feature has to be in front of the camera
        if (t.worldPt.z > 0) {
            featuresAll.add(t);
            tracksA.add(t);
            tracksB.add(t);
        }
    }
    // adjust the scale so that it's not excessively large or small
    normalizeScale(motionWorldToCamera[imageB], tracksA);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint) Se3_F64(georegression.struct.se.Se3_F64) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 10 with GrowQueue_I32

use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.

the class VisualizeImageSegmentationApp method performSegmentation.

private void performSegmentation() {
    long before = System.currentTimeMillis();
    alg.segment(color, pixelToRegion);
    long after = System.currentTimeMillis();
    System.out.println("Total time " + (after - before));
    int numSegments = alg.getTotalSuperpixels();
    // Computes the mean color inside each region
    ImageType<T> type = color.getImageType();
    ComputeRegionMeanColor<T> colorize = FactorySegmentationAlg.regionMeanColor(type);
    FastQueue<float[]> segmentColor = new ColorQueue_F32(type.getNumBands());
    segmentColor.resize(numSegments);
    GrowQueue_I32 regionMemberCount = new GrowQueue_I32();
    regionMemberCount.resize(numSegments);
    ImageSegmentationOps.countRegionPixels(pixelToRegion, numSegments, regionMemberCount.data);
    colorize.process(color, pixelToRegion, regionMemberCount, segmentColor);
    VisualizeRegions.regionsColor(pixelToRegion, segmentColor, outColor);
    VisualizeRegions.regions(pixelToRegion, segmentColor.size(), outSegments);
    // Make edges appear black
    ConvertBufferedImage.convertTo(color, outBorder, true);
    VisualizeRegions.regionBorders(pixelToRegion, 0x000000, outBorder);
}
Also used : ColorQueue_F32(boofcv.struct.feature.ColorQueue_F32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Aggregations

GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)60 Test (org.junit.Test)35 Point2D_I32 (georegression.struct.point.Point2D_I32)21 GrayS32 (boofcv.struct.image.GrayS32)10 ArrayList (java.util.ArrayList)7 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 Point2D_F64 (georegression.struct.point.Point2D_F64)5 FastQueue (org.ddogleg.struct.FastQueue)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)3 ColorQueue_F32 (boofcv.struct.feature.ColorQueue_F32)3 GrayF32 (boofcv.struct.image.GrayF32)3 GrowQueue_I8 (org.ddogleg.struct.GrowQueue_I8)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BrightFeature (boofcv.struct.feature.BrightFeature)2 LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)2 Point3D_F64 (georegression.struct.point.Point3D_F64)2 Se3_F64 (georegression.struct.se.Se3_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)2 BufferedImage (java.awt.image.BufferedImage)2