Search in sources :

Example 11 with GrowQueue_I32

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

the class TestFitLinesToContour method fitLinesUsingCorners.

@Test
public void fitLinesUsingCorners() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 30, 40);
    alg.lines.resize(3);
    alg.anchor0 = 1;
    alg.fitLinesUsingCorners(3, corners);
    LineGeneral2D_F64 expected = new LineGeneral2D_F64();
    for (int i = 0; i < 3; i++) {
        alg.fitLine(corners.get((i + 1) % 4), corners.get((i + 2) % 4), expected);
        LineGeneral2D_F64 found = alg.lines.get(i);
        assertEquals(expected.A, found.A, 1e-8);
        assertEquals(expected.B, found.B, 1e-8);
        assertEquals(expected.C, found.C, 1e-8);
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 12 with GrowQueue_I32

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

the class TestFitLinesToContour method fitLine.

@Test
public void fitLine() {
    FitLinesToContour alg = new FitLinesToContour();
    // create the rectangle so that two sizes are less than max samples and the other two more
    int w = alg.maxSamples;
    alg.contour = createSquare(10, 12, 10 + w - 1, 12 + w + 4);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 10 + w - 1, 12 + w + 4);
    LineGeneral2D_F64 line = new LineGeneral2D_F64();
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        alg.fitLine(corners.get(j), corners.get(i), line);
        // see if the line lies perfectly along the side
        int contour0 = corners.get(j);
        int contour1 = corners.get(i);
        int length = CircularIndex.distanceP(contour0, contour1, alg.contour.size());
        for (int k = 0; k < length; k++) {
            int contourIndex = CircularIndex.addOffset(contour0, k, alg.contour.size());
            Point2D_I32 p = alg.contour.get(contourIndex);
            double found = Distance2D_F64.distance(line, new Point2D_F64(p.x, p.y));
            assertEquals(0, found, 1e-8);
        }
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 13 with GrowQueue_I32

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

the class TestFitLinesToContour method linesIntoCorners.

@Test
public void linesIntoCorners() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 30, 40);
    // first generate the lines it will fit
    alg.lines.resize(3);
    alg.anchor0 = 1;
    alg.fitLinesUsingCorners(3, corners);
    // now extract the corners
    GrowQueue_I32 found = new GrowQueue_I32(corners.size);
    found.resize(corners.size());
    alg.anchor0 = 1;
    alg.linesIntoCorners(3, found);
    // only corners 2 and 3 should be updated with no change
    for (int i = 2; i < found.size(); i++) {
        assertEquals(corners.get(i), found.get(i));
    }
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 14 with GrowQueue_I32

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

the class TestFitLinesToContour method sanityCheckCornerOrder.

@Test
public void sanityCheckCornerOrder() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    GrowQueue_I32 corners = new GrowQueue_I32();
    corners.add(6);
    corners.add(12);
    corners.add(20);
    corners.add(41);
    corners.add(1);
    // test positive cases first
    for (int i = 0; i < 5; i++) {
        alg.anchor0 = i;
        assertTrue(alg.sanityCheckCornerOrder(3, corners));
    }
    // should fail
    corners.add(8);
    corners.add(3);
    alg.anchor0 = 3;
    assertFalse(alg.sanityCheckCornerOrder(4, corners));
}
Also used : GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 15 with GrowQueue_I32

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

the class TestMinimizeEnergyPrune method energyRemoveCorner.

@Test
public void energyRemoveCorner() {
    List<Point2D_I32> contours = createSquare(10, 12, 20, 30);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 20, 30);
    MinimizeEnergyPrune alg = new MinimizeEnergyPrune(1);
    alg.contour = contours;
    alg.computeSegmentEnergy(corners);
    // compute the energy with the skipped corner
    double expected = 0;
    for (int i = 0; i < 4; i++) {
        expected += alg.energySegment[i];
    }
    // add the corner which is going to be skipped
    corners.add(corners.get(3) + 4);
    alg.computeSegmentEnergy(corners);
    double found = alg.energyRemoveCorner(4, corners);
    assertEquals(expected, found, 1e-8);
    // add it in another location
    corners.removeTail();
    corners.insert(3, corners.get(2) + 3);
    alg.computeSegmentEnergy(corners);
    found = alg.energyRemoveCorner(3, corners);
    assertEquals(expected, found, 1e-8);
    // skip a different corner and the energy should go up
    corners = createSquareCorners(10, 12, 20, 30);
    for (int i = 0; i < 4; i++) {
        assertTrue(expected < alg.energyRemoveCorner(i, corners));
    }
}
Also used : 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