Main Content

generateArucoMarker

Generate ArUco marker images

Since R2024a

Description

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

example

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

Examples

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.

tiledlayout(3,4,TileSpacing="compact")
for i = 1:numMarkers
    nexttile
    imshow(imgs(:,:,i))
    title("ID = " + ids(i))
end

Write each marker image to a PNG file.

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

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)
"DICT_ARUCO_ORIGINAL"5-by-510243
"DICT_4X4_50"4-by-4504
"DICT_4X4_100"1003
"DICT_4X4_250"2502
"DICT_4X4_1000"10002
"DICT_5X5_50"5-by-5508
"DICT_5X5_100"1007
"DICT_5X5_250"2506
"DICT_5X5_1000"10005
"DICT_6X6_50"6-by-65013
"DICT_6X6_100"10012
"DICT_6X6_250"25011
"DICT_6X6_1000"10009
"DICT_7X7_50"7-by-75019
"DICT_7X7_100"25018
"DICT_7X7_250"25017
"DICT_7X7_1000"100014

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

Functions