Search in sources :

Example 46 with Point2D_I32

use of georegression.struct.point.Point2D_I32 in project BoofCV by lessthanoptimal.

the class TestFitLinesToContour method closestPoint.

@Test
public void closestPoint() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    Point2D_F64 p = new Point2D_F64(15.5, 11);
    Point2D_I32 corner = alg.contour.get(alg.closestPoint(p));
    assertEquals(15, corner.x);
    assertEquals(12, corner.y);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 47 with Point2D_I32

use of georegression.struct.point.Point2D_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)

Example 48 with Point2D_I32

use of georegression.struct.point.Point2D_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 49 with Point2D_I32

use of georegression.struct.point.Point2D_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 50 with Point2D_I32

use of georegression.struct.point.Point2D_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)

Aggregations

Point2D_I32 (georegression.struct.point.Point2D_I32)153 Test (org.junit.Test)64 ArrayList (java.util.ArrayList)41 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)21 Point2D_F64 (georegression.struct.point.Point2D_F64)11 EdgeContour (boofcv.alg.feature.detect.edge.EdgeContour)8 GrayF32 (boofcv.struct.image.GrayF32)8 GrayS32 (boofcv.struct.image.GrayS32)7 Contour (boofcv.alg.filter.binary.Contour)6 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)6 GrayU8 (boofcv.struct.image.GrayU8)6 PackedSetsPoint2D_I32 (boofcv.struct.PackedSetsPoint2D_I32)5 RectangleLength2D_I32 (georegression.struct.shapes.RectangleLength2D_I32)5 UtilPoint2D_I32 (georegression.geometry.UtilPoint2D_I32)4 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)4 EdgeSegment (boofcv.alg.feature.detect.edge.EdgeSegment)3 Corner (boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner)3 FactoryDescribeImageDense (boofcv.factory.feature.dense.FactoryDescribeImageDense)3 PointIndex_I32 (boofcv.struct.PointIndex_I32)3 LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)3