Search⌘ K
AI Features

Creating Single ArUco Markers and AprilTags with OpenCV

Explore how to create single ArUco markers and AprilTags using Python with OpenCV. Learn to select marker dictionaries, define marker IDs, set sizes, and generate marker images. This lesson helps you understand key steps for producing fiduciary markers useful in positioning and augmented reality.

Generating ArUco markers

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

Python 3.10.4
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 ...