I am Charmie

メモとログ

ArUco in OpenCV

ArUco is a fiducial marker tracking method against occlusion published in Pattern Recognition in 2014. ArUco was integrated into OpenCV modules. This blog post is to know its definition, how-to-use, etc. for my works.

ArUco provides three types of markers:
1. ArUco markers: a single marker is encoded by black and white patterns similar to QR code. You can change the number of bits and the number of total markers.
2. ArUco boards: a single board combines multiple ArUco markers as a tracking target. Therefore, the accuracy of corner detection is increased.
3. ChArUco boards: a single board combines a chessboard and a set of ArUco markers on the grid chessboard pattern, ChArUco provide better tracking accuracy than ArUco boards.

To know the detail of ArUco, we should better to read the documentation of the original library.

Each marker has the following information:
- marker ID
- 4 points representing its corners in the image
- marker size in meters
- rotation and translation represents the motion between the marker center and camera location.

A marker consists of an external black border and an internal binary pattern. ArUco provides several marker sets with different number of bits and markers.

Marker detection is done by the following steps:
1. binarize image by adaptive thresholding
2. find contours from the binarized image
3. ignore non-marker borders
4. identify the markers from their internal patterns

To get an ArUco dictionary object that contains the aruco_dict_id-th set of marker information,
[code lang="python"]
aruco_dict = aruco.Dictionary_get(aruco_dict_id)
print('#markers:', aruco_dict.bytesList.shape[0])
[/code]

aruco_dict_id is integer but its alias is encoded as DICT_BxB_M where B and M denote the number of bits per line and the number of markers. So, a dictionary of DICT_6x6_250 contains 250 markers, each of which is encoded by 6x6 binary pattern.

To get the marker_id-th marker of an ArUco dictionary aruco_dict as a numpy.array of marker_size x marker_size,
[code lang="python"]
marker = cv2.aruco.drawMarker(aruco_dict, marker_id, marker_size)
[/code]

To make a ChArUco board consists of num_h x num_v patterns using aruco_dict as a numpy.array of image_width x image_height,
[code lang="python"]
board = aruco.CharucoBoard_create(num_h, num_v, 0.8, aruco_dict)
img_board = board.draw*1
[/code]

*1:image_width, image_height