Search in sources :

Example 1 with GrowQueue_B

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

the class TestChessboardPolygonHelper method filterPixelPolygon_AllBorder.

@Test
public void filterPixelPolygon_AllBorder() {
    ChessboardPolygonHelper alg = new ChessboardPolygonHelper();
    Polygon2D_F64 distorted = new Polygon2D_F64(3);
    GrowQueue_B touches = new GrowQueue_B();
    touches.add(false);
    touches.add(false);
    touches.add(false);
    // nothing is actually touching the border, should be valid
    assertTrue(alg.filterPixelPolygon(null, distorted, touches, true));
    touches.set(0, true);
    touches.set(1, true);
    touches.set(2, true);
    assertFalse(alg.filterPixelPolygon(null, distorted, touches, true));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Test(org.junit.Test)

Example 2 with GrowQueue_B

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

the class TestChessboardPolygonHelper method filterPixelPolygon_border.

@Test
public void filterPixelPolygon_border() {
    ChessboardPolygonHelper alg = new ChessboardPolygonHelper();
    Polygon2D_F64 distorted = new Polygon2D_F64(2);
    GrowQueue_B touches = new GrowQueue_B();
    // test initially with all corners inside
    touches.add(false);
    touches.add(false);
    assertFalse(alg.filterPixelPolygon(null, distorted, touches, true));
    distorted.vertexes.resize(3);
    touches.add(false);
    assertTrue(alg.filterPixelPolygon(null, distorted, touches, true));
    distorted.vertexes.resize(3);
    touches.add(false);
    assertTrue(alg.filterPixelPolygon(null, distorted, touches, true));
    // these should all fail because there are too many corners inside not touching the border
    for (int i = 0; i < 3; i++) {
        distorted.vertexes.resize(4 + i + 1);
        touches.add(false);
        assertFalse(alg.filterPixelPolygon(null, distorted, touches, true));
    }
    // this should pass because only 1 or 3 corners are inside
    for (int i = 0; i < touches.size(); i++) {
        touches.set(i, true);
    }
    for (int i = 0; i < 3; i++) {
        touches.set(i, false);
        assertTrue(alg.filterPixelPolygon(null, distorted, touches, true));
    }
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Test(org.junit.Test)

Example 3 with GrowQueue_B

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

the class TestDetectChessboardSquarePoints method adjustBeforeOptimize_touchesBorder.

@Test
public void adjustBeforeOptimize_touchesBorder() {
    DetectChessboardSquarePoints<GrayU8> alg = new DetectChessboardSquarePoints<>(2, 2, ConfigLength.fixed(0.01), null);
    GrowQueue_B touches = new GrowQueue_B();
    touches.add(true);
    touches.add(true);
    touches.add(false);
    touches.add(true);
    for (boolean clockwise : new boolean[] { true, false }) {
        Polygon2D_F64 polygon = new Polygon2D_F64(10, 12, 30, 12, 30, 40, 10, 40);
        if (clockwise)
            polygon.flip();
        alg.adjustBeforeOptimize(polygon, touches, clockwise);
        int[] table = clockwise ? new int[] { 0, 3, 2, 1 } : new int[] { 0, 1, 2, 3 };
        assertEquals(10, polygon.get(table[0]).x, UtilEjml.TEST_F64);
        assertEquals(12, polygon.get(table[0]).y, UtilEjml.TEST_F64);
        assertEquals(31.5, polygon.get(table[1]).x, UtilEjml.TEST_F64);
        assertEquals(12, polygon.get(table[1]).y, UtilEjml.TEST_F64);
        assertEquals(31.5, polygon.get(table[2]).x, UtilEjml.TEST_F64);
        assertEquals(41.5, polygon.get(table[2]).y, UtilEjml.TEST_F64);
        assertEquals(10, polygon.get(table[3]).x, UtilEjml.TEST_F64);
        assertEquals(41.5, polygon.get(table[3]).y, UtilEjml.TEST_F64);
    }
}
Also used : GrayU8(boofcv.struct.image.GrayU8) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 4 with GrowQueue_B

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

the class TestDetectChessboardSquarePoints method adjustBeforeOptimize.

@Test
public void adjustBeforeOptimize() {
    DetectChessboardSquarePoints<GrayU8> alg = new DetectChessboardSquarePoints<>(2, 2, ConfigLength.fixed(0.01), null);
    Polygon2D_F64 polygon = new Polygon2D_F64(10, 12, 30, 12, 30, 40, 10, 40);
    alg.adjustBeforeOptimize(polygon, new GrowQueue_B(), false);
    assertEquals(8.5, polygon.get(0).x, UtilEjml.TEST_F64);
    assertEquals(10.5, polygon.get(0).y, UtilEjml.TEST_F64);
    assertEquals(31.5, polygon.get(1).x, UtilEjml.TEST_F64);
    assertEquals(10.5, polygon.get(1).y, UtilEjml.TEST_F64);
    assertEquals(31.5, polygon.get(2).x, UtilEjml.TEST_F64);
    assertEquals(41.5, polygon.get(2).y, UtilEjml.TEST_F64);
    assertEquals(8.5, polygon.get(3).x, UtilEjml.TEST_F64);
    assertEquals(41.5, polygon.get(3).y, UtilEjml.TEST_F64);
    polygon = new Polygon2D_F64(10, 12, 30, 12, 30, 40, 10, 40);
    polygon.flip();
    alg.adjustBeforeOptimize(polygon, new GrowQueue_B(), true);
    assertEquals(8.5, polygon.get(0).x, UtilEjml.TEST_F64);
    assertEquals(10.5, polygon.get(0).y, UtilEjml.TEST_F64);
    assertEquals(31.5, polygon.get(3).x, UtilEjml.TEST_F64);
    assertEquals(10.5, polygon.get(3).y, UtilEjml.TEST_F64);
    assertEquals(31.5, polygon.get(2).x, UtilEjml.TEST_F64);
    assertEquals(41.5, polygon.get(2).y, UtilEjml.TEST_F64);
    assertEquals(8.5, polygon.get(1).x, UtilEjml.TEST_F64);
    assertEquals(41.5, polygon.get(1).y, UtilEjml.TEST_F64);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Test(org.junit.Test)

Example 5 with GrowQueue_B

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

the class TestDetectPolygonFromContour method determineCornersOnBorder.

@Test
public void determineCornersOnBorder() {
    DetectPolygonFromContour alg = createDetector(GrayU8.class, 4, 4);
    alg.getLabeled().reshape(width, height);
    Polygon2D_F64 poly = new Polygon2D_F64(0, 0, 10, 0, 10, 10, 0, 10);
    GrowQueue_B corners = new GrowQueue_B();
    alg.determineCornersOnBorder(poly, corners);
    assertEquals(4, corners.size());
    assertEquals(true, corners.get(0));
    assertEquals(true, corners.get(1));
    assertEquals(false, corners.get(2));
    assertEquals(true, corners.get(3));
}
Also used : Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) GrowQueue_B(org.ddogleg.struct.GrowQueue_B) Test(org.junit.Test)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Test (org.junit.Test)5 GrayU8 (boofcv.struct.image.GrayU8)2