Search in sources :

Example 1 with Node

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method shuffle.

private void shuffle(Node[] edges) {
    for (int i = 0; i < 4; i++) {
        int src = rand.nextInt(4 - i);
        Node a = edges[src];
        Node b = edges[4 - i - 1];
        edges[4 - i - 1] = a;
        edges[src] = b;
    }
}
Also used : Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node)

Example 2 with Node

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node in project BoofCV by lessthanoptimal.

the class TestChessboardCornerGraph method node_countEdges.

@Test
void node_countEdges() {
    Node n = new Node();
    assertEquals(0, n.countEdges());
    n.edges[1] = new Node();
    assertEquals(1, n.countEdges());
    n.edges[3] = new Node();
    assertEquals(2, n.countEdges());
    n.edges[0] = new Node();
    n.edges[2] = new Node();
    assertEquals(4, n.countEdges());
}
Also used : Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node) Test(org.junit.jupiter.api.Test)

Example 3 with Node

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node in project BoofCV by lessthanoptimal.

the class TestChessboardCornerGraph method node_rotateEdgesDown.

@Test
void node_rotateEdgesDown() {
    Node[] tmp = new Node[4];
    tmp[1] = new Node();
    tmp[2] = new Node();
    tmp[3] = new Node();
    Node n = new Node();
    System.arraycopy(tmp, 0, n.edges, 0, 4);
    n.rotateEdgesDown();
    for (int i = 0; i < 4; i++) {
        assertSame(tmp[(i + 1) % 4], n.edges[i]);
    }
}
Also used : Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node) Test(org.junit.jupiter.api.Test)

Example 4 with Node

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node 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 Node

use of boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node in project BoofCV by lessthanoptimal.

the class TestChessboardCornerClusterToGrid method alignEdges.

@Test
void alignEdges() {
    for (int rows = 2; rows <= 4; rows++) {
        for (int cols = 2; cols <= 4; cols++) {
            DogArray<Node> corners = createGrid(rows, cols, true);
            // Shift the edges so that they won't be aligned
            // They are already in order
            Node[] tmp = new Node[4];
            for (Node n : corners.toList()) {
                int amount = rand.nextInt(3);
                System.arraycopy(n.edges, 0, tmp, 0, 4);
                for (int i = 0; i < 4; i++) {
                    n.edges[(i + amount) % 4] = tmp[i];
                }
            }
            ChessboardCornerClusterToGrid alg = new ChessboardCornerClusterToGrid();
            assertTrue(alg.alignEdges(corners));
            // Check using (i+2)%4 rule
            for (Node n : corners.toList()) {
                for (int i = 0; i < 4; i++) {
                    if (n.edges[i] == null)
                        continue;
                    assertSame(n, n.edges[i].edges[(i + 2) % 4]);
                }
            }
        }
    }
}
Also used : Node(boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node) Test(org.junit.jupiter.api.Test)

Aggregations

Node (boofcv.alg.fiducial.calib.chess.ChessboardCornerGraph.Node)14 Test (org.junit.jupiter.api.Test)11 ChessboardCorner (boofcv.alg.feature.detect.chess.ChessboardCorner)8 DogArray (org.ddogleg.struct.DogArray)3 GridInfo (boofcv.alg.fiducial.calib.chess.ChessboardCornerClusterToGrid.GridInfo)2 ArrayList (java.util.ArrayList)1