Search in sources :

Example 1 with DogArray_B

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

the class TestChessboardPolygonHelper method filterPixelPolygon_border.

@Test
void filterPixelPolygon_border() {
    ChessboardPolygonHelper alg = new ChessboardPolygonHelper();
    Polygon2D_F64 distorted = new Polygon2D_F64(2);
    DogArray_B touches = new DogArray_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));
    // this should pass because more than one corner is 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 : DogArray_B(org.ddogleg.struct.DogArray_B) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Example 2 with DogArray_B

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

the class TestChessboardPolygonHelper method filterPixelPolygon_AllBorder.

@Test
void filterPixelPolygon_AllBorder() {
    ChessboardPolygonHelper alg = new ChessboardPolygonHelper();
    Polygon2D_F64 distorted = new Polygon2D_F64(3);
    DogArray_B touches = new DogArray_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 : DogArray_B(org.ddogleg.struct.DogArray_B) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Example 3 with DogArray_B

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

the class TestDetectChessboardSquarePoints method adjustBeforeOptimize.

@Test
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 DogArray_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 DogArray_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 : DogArray_B(org.ddogleg.struct.DogArray_B) GrayU8(boofcv.struct.image.GrayU8) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Example 4 with DogArray_B

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

the class TestDetectChessboardSquarePoints method adjustBeforeOptimize_touchesBorder.

@Test
void adjustBeforeOptimize_touchesBorder() {
    DetectChessboardSquarePoints<GrayU8> alg = new DetectChessboardSquarePoints<>(2, 2, ConfigLength.fixed(0.01), null);
    DogArray_B touches = new DogArray_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 : DogArray_B(org.ddogleg.struct.DogArray_B) GrayU8(boofcv.struct.image.GrayU8) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Example 5 with DogArray_B

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

the class TestDetectPolygonFromContour method determineCornersOnBorder.

@Test
void determineCornersOnBorder() {
    DetectPolygonFromContour alg = createDetector(GrayU8.class, 4, 4);
    alg.imageWidth = width;
    alg.imageHeight = height;
    Polygon2D_F64 poly = new Polygon2D_F64(0, 0, 10, 0, 10, 10, 0, 10);
    DogArray_B corners = new DogArray_B();
    alg.determineCornersOnBorder(poly, corners);
    assertEquals(4, corners.size());
    assertTrue(corners.get(0));
    assertTrue(corners.get(1));
    assertFalse(corners.get(2));
    assertTrue(corners.get(3));
}
Also used : DogArray_B(org.ddogleg.struct.DogArray_B) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.jupiter.api.Test)

Aggregations

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