Skip to content

ChArUco

CharucoCorrespondenceFinder(n_rows, n_columns, square_size, marker_length, family, legacy=False)

Bases: CorrespondenceFinderBase

ChArUco pattern correspondence finder.

Initialize a ChArUco correspondence finder.

Parameters:

Name Type Description Default
n_rows int

Number of rows (squares) in the ChArUco pattern.

required
n_columns int

Number of columns (squares) in the ChArUco pattern.

required
square_size float

Size of a square in the ChArUco pattern. Returned object points will be in units of this size.

required
marker_length float

Size of a marker in the ChArUco pattern. Returned object points will be in units of this size.

required
family int

ArUco family to use for the ChArUco pattern.

required
legacy bool

Whether to use the legacy ChArUco pattern (OpenCV <= 4.6).

False
Source code in src/compas_camcal/correspondence/charuco.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    n_rows: int,
    n_columns: int,
    square_size: float,
    marker_length: float,
    family: int,
    legacy: bool = False,
):
    """
    Initialize a ChArUco correspondence finder.

    Args:
        n_rows: Number of rows (squares) in the ChArUco pattern.
        n_columns: Number of columns (squares) in the ChArUco pattern.
        square_size: Size of a square in the ChArUco pattern. Returned object points will be in units of this size.
        marker_length: Size of a marker in the ChArUco pattern. Returned object points will be in units of this size.
        family: ArUco family to use for the ChArUco pattern.
        legacy: Whether to use the legacy ChArUco pattern (OpenCV <= 4.6).
    """
    super().__init__()

    # Create the ArUco dictionary
    self._dictionary = cv2.aruco.getPredefinedDictionary(family)

    # Create the ChArUco board
    self._board = cv2.aruco.CharucoBoard(
        (n_columns, n_rows), square_size, marker_length, self._dictionary
    )
    self._board.setLegacyPattern(legacy)

    # Create the detector
    self._detector = cv2.aruco.CharucoDetector(self._board)

find(image)

Find correspondences in an image.

Parameters:

Name Type Description Default
image ndarray

Image to find correspondences in.

required

Returns:

Type Description
Optional[Correspondence]

Correspondence object if found, None otherwise.

Source code in src/compas_camcal/correspondence/charuco.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def find(self, image: np.ndarray) -> Optional[Correspondence]:
    """
    Find correspondences in an image.

    Args:
        image: Image to find correspondences in.

    Returns:
        Correspondence object if found, None otherwise.
    """
    # Find chessboard and ChArUco markers
    self.logger.info("Finding ChArUco board")
    charuco_corners, charuco_ids, marker_corners, marker_ids = self._detector.detectBoard(image)

    if charuco_corners is None:
        self.logger.warning("No ChArUco board found")
        return None

    # Get object and image points
    charuco_object_points, charuco_image_points = self._board.matchImagePoints(
        charuco_corners, charuco_ids
    )

    return Correspondence(charuco_object_points[:, 0, :], charuco_image_points[:, 0, :])