Search in sources :

Example 1 with SquareGrid

use of boofcv.alg.fiducial.calib.squares.SquareGrid in project BoofCV by lessthanoptimal.

the class TestDetectChessboardSquarePoints method putIntoCanonical.

@Test
public void putIntoCanonical() {
    SquareGridTools tools = new SquareGridTools();
    DetectChessboardSquarePoints alg = new DetectChessboardSquarePoints(2, 2, ConfigLength.fixed(10), null);
    for (int rows = 2; rows <= 5; rows++) {
        for (int cols = 2; cols <= 5; cols++) {
            SquareGrid uber = createGrid(rows, cols);
            alg.putIntoCanonical(uber);
            checkCanonical(uber);
            // make it do some work
            boolean oddRow = rows % 2 == 1;
            boolean oddCol = cols % 2 == 1;
            if (oddRow == oddCol) {
                if (oddRow && rows == cols) {
                    tools.rotateCCW(uber);
                } else {
                    tools.reverse(uber);
                }
            }
            alg.putIntoCanonical(uber);
            checkCanonical(uber);
        }
    }
}
Also used : SquareGrid(boofcv.alg.fiducial.calib.squares.SquareGrid) SquareGridTools(boofcv.alg.fiducial.calib.squares.SquareGridTools) Test(org.junit.Test)

Example 2 with SquareGrid

use of boofcv.alg.fiducial.calib.squares.SquareGrid in project BoofCV by lessthanoptimal.

the class TestDetectChessboardSquarePoints method computeCalibrationPoints.

@Test
public void computeCalibrationPoints() {
    DetectChessboardSquarePoints<GrayU8> alg = new DetectChessboardSquarePoints<>(2, 2, ConfigLength.fixed(0.01), null);
    double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
    for (int rows = 2; rows <= 5; rows++) {
        for (int cols = 2; cols <= 5; cols++) {
            // System.out.println(rows+" "+cols);
            SquareGrid grid = createGrid(rows, cols);
            assertTrue(alg.computeCalibrationPoints(grid));
            assertEquals((rows - 1) * (cols - 1), alg.calibrationPoints.size());
            double x0 = w / 2;
            double y0 = w / 2;
            int index = 0;
            for (int i = 0; i < rows - 1; i++) {
                for (int j = 0; j < cols - 1; j++) {
                    double x = x0 + j * w;
                    double y = y0 + i * w;
                    Point2D_F64 p = alg.calibrationPoints.get(index++);
                    assertTrue(p.distance(x, y) < 1e-8);
                }
            }
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) SquareGrid(boofcv.alg.fiducial.calib.squares.SquareGrid) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 3 with SquareGrid

use of boofcv.alg.fiducial.calib.squares.SquareGrid in project BoofCV by lessthanoptimal.

the class TestDetectChessboardSquarePoints method createGrid.

public static SquareGrid createGrid(int rows, int cols) {
    SquareGrid grid = new SquareGrid();
    grid.columns = cols;
    grid.rows = rows;
    double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            if (row % 2 == 0) {
                if (col % 2 == 0) {
                    grid.nodes.add(createSquare(col * w, row * w, w));
                } else {
                    grid.nodes.add(null);
                }
            } else {
                if (col % 2 == 0) {
                    grid.nodes.add(null);
                } else {
                    grid.nodes.add(createSquare(col * w, row * w, w));
                }
            }
        }
    }
    for (int row = 0; row < rows - 1; row++) {
        for (int col = 0; col < cols; col++) {
            SquareNode n = grid.get(row, col);
            if (n == null)
                continue;
            if (col > 0) {
                SquareNode a = grid.get(row + 1, col - 1);
                connect(n, 3, a, 1);
            }
            if (col < cols - 1) {
                SquareNode a = grid.get(row + 1, col + 1);
                connect(n, 2, a, 0);
            }
        }
    }
    return grid;
}
Also used : SquareGrid(boofcv.alg.fiducial.calib.squares.SquareGrid) SquareNode(boofcv.alg.fiducial.calib.squares.SquareNode)

Example 4 with SquareGrid

use of boofcv.alg.fiducial.calib.squares.SquareGrid in project BoofCV by lessthanoptimal.

the class TestDetectChessboardSquarePoints method ensureCCW.

@Test
public void ensureCCW() {
    int[][] shapes = new int[][] { { 4, 5 }, { 2, 3 }, { 3, 2 }, { 2, 2 } };
    DetectChessboardSquarePoints<GrayU8> alg = new DetectChessboardSquarePoints<>(2, 2, ConfigLength.fixed(0.01), null);
    for (int[] shape : shapes) {
        // System.out.println(shape[0]+" "+shape[1]);
        SquareGrid grid = createGrid(shape[0], shape[1]);
        assertTrue(isCCW((grid)));
        assertTrue(alg.ensureCCW(grid));
        assertTrue(isCCW((grid)));
        if (grid.columns % 2 == 1)
            alg.tools.flipColumns(grid);
        else if (grid.rows % 2 == 1)
            alg.tools.flipRows(grid);
        else
            continue;
        assertFalse(isCCW((grid)));
        assertTrue(alg.ensureCCW(grid));
        assertTrue(isCCW((grid)));
    }
}
Also used : SquareGrid(boofcv.alg.fiducial.calib.squares.SquareGrid) GrayU8(boofcv.struct.image.GrayU8) Test(org.junit.Test)

Example 5 with SquareGrid

use of boofcv.alg.fiducial.calib.squares.SquareGrid in project BoofCV by lessthanoptimal.

the class TestDetectSquareGridFiducial method extractCalibrationPoints.

@Test
public void extractCalibrationPoints() {
    SquareGrid grid = TestSquareGridTools.createGrid(3, 4);
    DetectSquareGridFiducial alg = new DetectSquareGridFiducial(3, 4, 1, null, null);
    new SquareGridTools().orderSquareCorners(grid);
    alg.extractCalibrationPoints(grid);
    List<Point2D_F64> list = alg.getCalibrationPoints();
    assertEquals(4 * 3 * 4, list.size());
    double w = TestSquareRegularClustersIntoGrids.DEFAULT_WIDTH;
    double x0 = -w / 2;
    double y0 = -w / 2;
    for (int row = 0; row < grid.rows * 2; row++) {
        for (int col = 0; col < grid.columns * 2; col++) {
            double x = x0 + col * w;
            double y = y0 + row * w;
            Point2D_F64 p = list.get(row * grid.columns * 2 + col);
            assertEquals(x, p.x, 1e-8);
            assertEquals(y, p.y, 1e-8);
        }
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) SquareGrid(boofcv.alg.fiducial.calib.squares.SquareGrid) SquareGridTools(boofcv.alg.fiducial.calib.squares.SquareGridTools) TestSquareGridTools(boofcv.alg.fiducial.calib.squares.TestSquareGridTools) Test(org.junit.Test)

Aggregations

SquareGrid (boofcv.alg.fiducial.calib.squares.SquareGrid)6 Test (org.junit.Test)4 SquareGridTools (boofcv.alg.fiducial.calib.squares.SquareGridTools)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2 GrayU8 (boofcv.struct.image.GrayU8)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 TestSquareGridTools (boofcv.alg.fiducial.calib.squares.TestSquareGridTools)1