Search in sources :

Example 1 with GridInfo

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo in project BoofCV by lessthanoptimal.

the class CalibrationDetectorChessboardX method process.

@Override
public boolean process(GrayF32 input) {
    detectorX.findPatterns(input);
    DogArray<GridInfo> found = detectorX.getFoundChessboard();
    if (found.size >= 1) {
        detected = new CalibrationObservation(input.width, input.height);
        GridInfo info = found.get(0);
        for (int i = 0; i < info.nodes.size(); i++) {
            detected.add(info.nodes.get(i).corner, i);
        }
        // remove lens distortion
        if (pixel2undist != null) {
            for (int i = 0; i < info.nodes.size(); i++) {
                Point2D_F64 p = detected.points.get(i).p;
                pixel2undist.compute(p.x, p.y, p);
            }
        }
        return true;
    } else {
        detected = new CalibrationObservation(input.width, input.height);
        return false;
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) GridInfo(boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo) CalibrationObservation(boofcv.alg.geo.calibration.CalibrationObservation)

Example 2 with GridInfo

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method createGridInfo.

private GridInfo createGridInfo(int rows, int cols, boolean cornerSquare) {
    GridInfo output = new GridInfo();
    output.rows = rows;
    output.cols = cols;
    output.nodes.addAll(createGrid(rows, cols, cornerSquare).toList());
    return output;
}
Also used : GridInfo(boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo)

Example 3 with GridInfo

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method orderNodes.

void orderNodes(DogArray<Node> corners, int rows, int cols) {
    GridInfo info = new GridInfo();
    info.reset();
    ChessboardCornerClusterToGrid alg = new ChessboardCornerClusterToGrid();
    assertTrue(alg.orderNodes(corners, info));
    // rows and cols could be swapped arbitrarily
    if (rows == info.rows) {
        assertEquals(cols, info.cols);
    } else {
        assertEquals(rows, info.cols);
        assertEquals(cols, info.rows);
    }
}
Also used : GridInfo(boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo)

Example 4 with GridInfo

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method convert_extra.

/**
 * The input will be a rectangle, but with an extra corner that should be removed
 */
@Test
void convert_extra() {
    ChessboardCornerClusterToGrid alg = new ChessboardCornerClusterToGrid();
    alg.setRequireCornerSquares(true);
    ChessboardCornerGraph graph = new ChessboardCornerGraph();
    graph.corners = createGrid(4, 5, true);
    // add an extra node to the graph
    Node n = graph.corners.get(graph.corners.size - 1);
    Node extra = graph.corners.grow();
    extra.corner = new ChessboardCorner();
    extra.corner.orientation = n.getOrientation() * -1;
    extra.corner.x = n.getX() + 30;
    extra.corner.y = n.getY();
    extra.index = graph.corners.size - 1;
    n.edges[0] = extra;
    extra.edges[2] = n;
    // See if it gets removed
    GridInfo info = new GridInfo();
    assertTrue(alg.clusterToSparse(graph));
    assertTrue(alg.sparseToGrid(info));
    assertTrue(info.hasCornerSquare);
    assertEquals(5, info.cols);
    assertEquals(4, info.rows);
    assertEquals(5 * 4, info.nodes.size());
}
Also used : ChessboardCorner(boofcv.alg.feature.detect.chess.ChessboardCorner) Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node) GridInfo(boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo) Test(org.junit.jupiter.api.Test)

Example 5 with GridInfo

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method convert.

void convert(ChessboardCornerClusterToGrid alg, int rows, int cols, boolean randomized) {
    ChessboardCornerGraph graph = new ChessboardCornerGraph();
    graph.corners = createGrid(rows, cols, true);
    if (randomized) {
        graph.corners.shuffle(rand);
        for (int i = 0; i < graph.corners.size; i++) {
            Node n = graph.corners.get(i);
            shuffle(n.edges);
            n.index = graph.corners.indexOf(n);
        }
    }
    GridInfo info = new GridInfo();
    assertTrue(alg.clusterToSparse(graph));
    assertTrue(alg.sparseToGrid(info));
    assertTrue(info.hasCornerSquare);
    // test shape
    if (rows == info.rows) {
        assertEquals(cols, info.cols);
    } else {
        assertEquals(rows, info.cols);
        assertEquals(cols, info.rows);
    }
    assertEquals(rows * cols, info.nodes.size());
    // first should be a corner
    Node n0 = info.get(0, 0);
    assertEquals(2, n0.countEdges());
    // it should also have coordinate (0,0)
    assertEquals(0, n0.getX(), UtilEjml.TEST_F64);
    assertEquals(0, n0.getY(), UtilEjml.TEST_F64);
    // test right handled
    for (int i = 0; i < 4; i++) {
        int j = (i + 1) % 4;
        if (n0.edges[i] != null && n0.edges[j] != null) {
            double angle0 = direction(n0, n0.edges[i]);
            double angle1 = direction(n0, n0.edges[j]);
            assertEquals(Math.PI / 2.0, UtilAngle.distanceCCW(angle0, angle1), 0.001);
            break;
        }
    }
}
Also used : Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node) GridInfo(boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo)

Aggregations

GridInfo (boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo)5 Node (boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node)2 ChessboardCorner (boofcv.alg.feature.detect.chess.ChessboardCorner)1 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)1 Point2D_F64 (georegression.struct.point.Point2D_F64)1 Test (org.junit.jupiter.api.Test)1