Search in sources :

Example 1 with GrowQueue_I32

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

the class CompareTwoImagePanel method findBestPoints.

private void findBestPoints(int x, int y, List<Point2D_F64> pts, List<Integer> selected) {
    double bestDist = clickDistance * clickDistance;
    GrowQueue_I32 bestIndexes = new GrowQueue_I32(20);
    for (int i = 0; i < pts.size(); i++) {
        if (!isValidPoint(i))
            continue;
        Point2D_F64 p = pts.get(i);
        double d = UtilPoint2D_F64.distanceSq(p.x, p.y, x, y);
        if (d < bestDist) {
            bestDist = d;
            bestIndexes.reset();
            bestIndexes.add(i);
        } else if (Math.abs(d - bestDist) < 0.01) {
            bestIndexes.add(i);
        }
    }
    if (bestIndexes.size() > 0) {
        int indexRight = bestIndexes.get(0);
    }
    for (int i = 0; i < bestIndexes.size(); i++) {
        selected.add(bestIndexes.get(i));
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) UtilPoint2D_F64(georegression.geometry.UtilPoint2D_F64) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 2 with GrowQueue_I32

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

the class TestAssociateNearestNeighbor method various.

/**
 * Several tests combined into one
 */
@Test
public void various() {
    Dummy<Integer> nn = new Dummy<>();
    // src = assoc[i] where src is the index of the source feature and i is the index of the dst feature
    nn.assoc = new int[] { 2, 0, 1, -1, 4, -1, -1, 2, 2, 1 };
    AssociateNearestNeighbor<TupleDesc_F64> alg = new AssociateNearestNeighbor<>(nn, 10);
    FastQueue<TupleDesc_F64> src = new FastQueue<>(10, TupleDesc_F64.class, false);
    FastQueue<TupleDesc_F64> dst = new FastQueue<>(10, TupleDesc_F64.class, false);
    for (int i = 0; i < 5; i++) {
        src.add(new TupleDesc_F64(10));
    }
    for (int i = 0; i < 10; i++) {
        dst.add(new TupleDesc_F64(10));
    }
    alg.setSource(src);
    alg.setDestination(dst);
    alg.associate();
    FastQueue<AssociatedIndex> matches = alg.getMatches();
    assertTrue(nn.pointDimension == 10);
    assertEquals(7, matches.size);
    for (int i = 0, count = 0; i < nn.assoc.length; i++) {
        if (nn.assoc[i] != -1) {
            int source = nn.assoc[i];
            assertEquals(source, matches.get(count).src);
            assertEquals(i, matches.get(count).dst);
            count++;
        }
    }
    GrowQueue_I32 unassoc = alg.getUnassociatedSource();
    assertEquals(1, unassoc.size);
    assertEquals(3, unassoc.get(0));
    unassoc = alg.getUnassociatedDestination();
    assertEquals(3, unassoc.size);
    assertEquals(3, unassoc.get(0));
    assertEquals(5, unassoc.get(1));
    assertEquals(6, unassoc.get(2));
}
Also used : TupleDesc_F64(boofcv.struct.feature.TupleDesc_F64) FastQueue(org.ddogleg.struct.FastQueue) AssociatedIndex(boofcv.struct.feature.AssociatedIndex) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 3 with GrowQueue_I32

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

the class BinaryThinning method apply.

/**
 * Applies the thinning algorithm.  Runs for the specified number of loops or until no change is detected.
 *
 * @param binary Input binary image which is to be thinned.  This is modified
 * @param maxLoops Maximum number of thinning loops.  Set to -1 to run until the image is no longer modified.
 */
public void apply(GrayU8 binary, int maxLoops) {
    this.binary = binary;
    inputBorder.setImage(binary);
    ones0.reset();
    zerosOut.reset();
    findOnePixels(ones0);
    for (int loop = 0; (loop < maxLoops || maxLoops == -1) && ones0.size > 0; loop++) {
        boolean changed = false;
        // do one cycle through all the masks
        for (int i = 0; i < masks.length; i++) {
            zerosOut.reset();
            ones1.reset();
            masks[i].apply(ones0, ones1, zerosOut);
            changed |= ones0.size != ones1.size;
            // mark all the pixels that need to be set to 0 as 0
            for (int j = 0; j < zerosOut.size(); j++) {
                binary.data[zerosOut.get(j)] = 0;
            }
            // swap the lists
            GrowQueue_I32 tmp = ones0;
            ones0 = ones1;
            ones1 = tmp;
        }
        if (!changed)
            break;
    }
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 4 with GrowQueue_I32

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

the class TestBinaryThinning method findBlackPixels.

private void findBlackPixels(GrayU8 img) {
    GrowQueue_I32 marked = new GrowQueue_I32();
    BinaryThinning alg = new BinaryThinning();
    alg.binary = img;
    alg.findOnePixels(marked);
    assertEquals(2, marked.size());
    assertEquals(img.getIndex(4, 1), marked.get(0));
    assertEquals(img.getIndex(2, 3), marked.get(1));
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32)

Example 5 with GrowQueue_I32

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

the class SplitMergeLineFitLoop method mergeSegments.

/**
 * Merges lines together if the common corner is close to a common line
 * @return true the list being changed
 */
protected boolean mergeSegments() {
    // See if merging will cause a degenerate case
    if (splits.size() <= 3)
        return false;
    boolean change = false;
    work.reset();
    for (int i = 0; i < splits.size; i++) {
        int start = splits.data[i];
        int end = splits.data[(i + 2) % splits.size];
        if (selectSplitOffset(start, circularDistance(start, end)) < 0) {
            // merge the two lines by not adding it
            change = true;
        } else {
            work.add(splits.data[(i + 1) % splits.size]);
        }
    }
    // swap the two lists
    GrowQueue_I32 tmp = work;
    work = splits;
    splits = tmp;
    return change;
}
Also used : 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