Search in sources :

Example 16 with GrowQueue_I32

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

the class TestMinimizeEnergyPrune method computeSegmentEnergy.

@Test
public void computeSegmentEnergy() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 20, 30);
    // test with everything perfectly lining up
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    alg.contour = contours;
    double split = alg.splitPenalty;
    double[] expected = new double[] { split / 100.0, split / (18.0 * 18.0), split / 100.0, split / (18.0 * 18.0) };
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        double found = alg.computeSegmentEnergy(corners, j, i);
        assertEquals(expected[j], found, 1e-8);
    }
    // Now make the corners less than perfect and see if the energy increases
    corners.set(1, corners.get(1) + 1);
    corners.set(3, corners.get(3) + 1);
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        double found = alg.computeSegmentEnergy(corners, j, i);
        assertTrue(expected[j] < found);
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 17 with GrowQueue_I32

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

the class TestMinimizeEnergyPrune method prune_obvious.

/**
 * Adds an obviously redundant corner and see if it gets removed
 */
@Test
public void prune_obvious() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 20, 30);
    corners.add(corners.get(3) + 4);
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    GrowQueue_I32 output = new GrowQueue_I32();
    alg.prune(contours, corners, output);
    assertEquals(4, output.size());
    // see if the two sets of corners are equivalent, taking in account the possibility of a rotation
    checkMatched(corners, output);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 18 with GrowQueue_I32

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

the class TestRefinePolyLineCorner method fit_six_sides.

/**
 * Fit six sided shape
 */
@Test
public void fit_six_sides() {
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(0, 0, 20, 0, points);
    addPoints(20, 0, 20, 20, points);
    addPoints(20, 20, 40, 20, points);
    addPoints(40, 20, 40, 40, points);
    addPoints(40, 40, 0, 40, points);
    addPoints(0, 40, 0, 0, points);
    GrowQueue_I32 corners = new GrowQueue_I32();
    corners.add(0);
    corners.add(20);
    corners.add(40);
    corners.add(60);
    corners.add(80);
    corners.add(120);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    for (int i = 0; i < 10; i++) {
        // noise up the inputs
        for (int j = 0; j < corners.size(); j++) {
            corners.data[j] = CircularIndex.addOffset(corners.data[j], rand.nextInt(10) - 5, points.size());
        }
        assertTrue(alg.fit(points, corners));
        assertEquals(0, corners.get(0));
        assertEquals(20, corners.get(1));
        assertEquals(40, corners.get(2));
        assertEquals(60, corners.get(3));
        assertEquals(80, corners.get(4));
        assertEquals(120, corners.get(5));
    }
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 19 with GrowQueue_I32

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

the class TestRefinePolyLineCorner method fit_quad_segment.

/**
 * Fit to a square, but only a disconnected polyline on 3 sides
 */
@Test
public void fit_quad_segment() {
    int x0 = 10, y0 = 15;
    int x1 = 60, y1 = 99;
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(x0, y0, x1, y0, points);
    addPoints(x1, y0, x1, y1, points);
    addPoints(x1, y1, x0, y1, points);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(false);
    for (int i = 0; i < 10; i++) {
        GrowQueue_I32 corners = new GrowQueue_I32();
        corners.add(0);
        corners.add(50 + rand.nextInt(6) - 3);
        corners.add(50 + 84 + rand.nextInt(6) - 3);
        corners.add(points.size() - 1);
        assertTrue(alg.fit(points, corners));
        assertEquals(0, corners.get(0));
        assertEquals(50, corners.get(1));
        assertEquals(134, corners.get(2));
        assertEquals(points.size() - 1, corners.get(3));
    }
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 20 with GrowQueue_I32

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

the class TestRefinePolyLineCorner method fit_quad.

/**
 * Fit to a square
 */
@Test
public void fit_quad() {
    int x0 = 10, y0 = 15;
    int x1 = 60, y1 = 99;
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(x0, y0, x1, y0, points);
    addPoints(x1, y0, x1, y1, points);
    addPoints(x1, y1, x0, y1, points);
    addPoints(x0, y1, x0, y0, points);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    GrowQueue_I32 corners = new GrowQueue_I32();
    corners.add(0);
    corners.add(50);
    corners.add(50 + 84);
    corners.add(50 + 84 + 50);
    assertTrue(alg.fit(points, corners));
    assertEquals(0, corners.get(0));
    assertEquals(50, corners.get(1));
    assertEquals(134, corners.get(2));
    assertEquals(184, corners.get(3));
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

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