...

/

Creating Single ArUco Markers and AprilTags with OpenCV

Creating Single ArUco Markers and AprilTags with OpenCV

Learn how to draw ArUco markers and AprilTags.

Generating ArUco markers

In the following example, we’ll learn how to generate ArUco markers.

Press + to interact
import cv2
import numpy as np
print(cv2.__version__)
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_6X6_250)
marker_id = 42
marker_size = 200
marker_image = np.zeros((marker_size, marker_size), dtype=np.uint8)
marker_image = cv2.aruco.drawMarker(aruco_dict, marker_id, marker_size, marker_image, borderBits=1)
cv2.imwrite("output/aruco_marker_42.png", marker_image)

Lines 1–2: To generate markers, we first need to import the required libraries, cv2 and numpy.

Line 4: We print the version of the cv2 library to make sure that we have installed the correct version.

Then, we’ll get the dictionary containing the specific ArUco markers that we are interested in. For ...