Search in sources :

Example 51 with Point2D_I32

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

the class TestRefinePolyLineCorner method addPoints.

private void addPoints(int x0, int y0, int x1, int y1, List<Point2D_I32> points) {
    if (x0 == x1) {
        int length = Math.abs(y1 - y0);
        int dir = y1 > y0 ? 1 : -1;
        for (int y = 0; y < length; y++) {
            points.add(new Point2D_I32(x0, y0 + dir * y));
        }
    } else {
        int length = Math.abs(x1 - x0);
        int dir = x1 > x0 ? 1 : -1;
        for (int x = 0; x < length; x++) {
            points.add(new Point2D_I32(x0 + dir * x, y0));
        }
    }
}
Also used : Point2D_I32(georegression.struct.point.Point2D_I32)

Example 52 with Point2D_I32

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

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

Example 54 with Point2D_I32

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

the class TestPolylineSplitMerge method computePotentialSplitScore.

@Test
public void computePotentialSplitScore() {
    PolylineSplitMerge alg = new PolylineSplitMerge();
    alg.setMinimumSideLength(5);
    alg.setThresholdSideSplitScore(0);
    List<Point2D_I32> contour = new ArrayList<>();
    for (int i = 0; i < 20; i++) {
        contour.add(new Point2D_I32(i, 0));
    }
    // add some texture
    contour.get(3).y = 5;
    contour.get(15).y = 5;
    // this will be selected as the corner since it's the farthest away
    contour.get(10).y = 20;
    alg.addCorner(0);
    alg.addCorner(19);
    Element<Corner> e = alg.list.getHead();
    e.object.sideError = 20;
    alg.computePotentialSplitScore(contour, e, false);
    assertTrue(e.object.splitable);
    assertTrue(e.object.splitError0 > 0);
    assertTrue(e.object.splitError1 > 0);
    assertEquals(10, e.object.splitLocation);
}
Also used : Corner(boofcv.alg.shapes.polyline.splitmerge.PolylineSplitMerge.Corner) ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) Test(org.junit.Test)

Example 55 with Point2D_I32

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

the class TestPolylineSplitMerge method distanceAbs.

@Test
public void distanceAbs() {
    Point2D_I32 a = new Point2D_I32(2, 4);
    Point2D_I32 b = new Point2D_I32(10, -3);
    int expected = Math.abs(2 - 10) + Math.abs(4 + 3);
    double found = PolylineSplitMerge.distanceAbs(a, b);
    assertEquals(expected, found, GrlConstants.TEST_F64);
}
Also used : Point2D_I32(georegression.struct.point.Point2D_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