Main Content


Generate ArUco marker images

Since R2024a



imgs = generateArucoMarker(markerFamily,ids,markerSize) generates ArUco marker images imgs of the specified family markerFamily and size markerSize with the corresponding identifiers ids.

imgs = generateArucoMarker(___, NumBorderBits=Value) sets the number of marker border bits to add when generating the marker, in addition to all input arguments from the previous syntax. Specify Value as a positive integer value. The default value is set to 1.


collapse all

Generate 12 ArUco marker images, display them, and write them to PNG files.

Specify the number, size, family, and IDs of the markers to generate.

numMarkers = 12;
markerSize = 50; % in pixels
markerFamily = "DICT_4X4_250";
ids = 1:numMarkers;

Generate the ArUco markers.

imgs = generateArucoMarker(markerFamily,ids,markerSize);

Display the markers.

for i = 1:numMarkers
    title("ID = " + ids(i))

Write each marker image to a PNG file.

for i = 1:numMarkers
    filename = markerFamily + "_ID" + ids(i) + ".png";
    imwrite(imgs(:,:,i), filename)

Input Arguments

collapse all

ArUco marker families, specified as a character vector, string scalar, vector of strings, or cell array of character vectors. Each element must be one of the valid ArUco marker families listed in the table. Select a marker family suitable for your application based on the total number of markers needed, the marker length, and the Hamming distance between the marker code words. The minimum Hamming distance between markers in the same family, determine the ability to detect them and correct errors. Marker families with less number of markers can be more robust against errors than a family with a large number of markers, which can increase marker detection difficulty due to a greater number of bits to extract. These general rules apply:

  • The less number of bits to detect, the longer the range in distance a marker can be detected.

  • For correct identification and decoding, ArUco markers require a white border, also known as the quiet zone.

FamilyMarker Size (bits)Number of Markers in FamilyMinimum Hamming Distance Between Markers (bits)

Data Types: char | string | cell

Marker IDs, specified as an N-element vector of positive integers. Each element must be nonnegative and less than the family size, which is the total number of markers available in the marker family. For example, the family size of "DICT_7X7_250" is 250.

Size of each marker, in pixels, specified as a positive integer. This value sets the length of one side of a square ArUco marker. The marker size must be large enough to store the number of bits required for the specified marker family. For example, you cannot generate an image of 5-by-5 pixels for a marker from the "DICT_6X6_100" family, which requires defines a 6-by-6 pixel size. For more information, see the table in the markerFamily input description.

Output Arguments

collapse all

Marker images, returned as an M-by-M-by-N array.

Data Types: uint8

Version History

Introduced in R2024a

See Also