Creating and using square barcode markers - hipandayu/artoolkitx GitHub Wiki

artoolkitX supports the use of two-dimensional (2D) barcode markers. These work on the same basic principle as pictorial square markers in that they are square with a solid border, but instead of the picture in the marker interior, feature a matrix grid of black and white squares. artoolkitX treats the squares in a matrix pattern as a 2D-barcode; each unique matrix pattern being associated with an predetermined identifier.

Barcode markers offer superior performance and reduced identification error rates

Identification of 2D barcode markers does not require the generation or loading of a pattern file. Instead the marker's ID is read directly from the barcode. This is computationally less costly than identifying a pattern-based marker. When using pattern markers, the interior of every black square in the image captured from the camera must be compared against every known marker pattern at all four possible orientations. For a handful of markers, this computation comes at small cost, but as the number of markers in use in a single tracker rises to 20 or 100; the cost becomes significant. Additionally, pattern based markers are more likely to be confused by the tracker when there are a large number of markers (since there is a lower degree of uniqueness within the set of markers), leading to markers being misrepresented as each other.

2D barcode markers can incorporate error detection and correction (EDC) in the pattern, so that when a marker is found in the video frame, it is possible to identify which marker it is with a high degree of confidence. This makes 2D barcodes with EDC a very good choice for tracking when a large numbers of markers must be able to be reliably identified.

Choosing the right barcode set.

artoolkitX supports several different barcode densities and EDC algorithms. The choice of density and EDC algorithm constrain the possible maximum number of barcodes that can be used in a given application. In general, using better EDC will result in a smaller set of barcodes being available, but lower likelihood of markers being misrecognized during tracking.

The barcode type is set via the function [arSetMatrixCodeType][arSetMatrixCodeType]

The following table sets out the available types, in order from most robust to least robust:

Matrix code type Maximum number of markers Number of bit errors that can be detected Number of bit errors that can be corrected
AR_MATRIX_CODE_5x5_BCH_22_7_7 127 6 3
AR_MATRIX_CODE_4x4_BCH_13_5_5 32 4 2
AR_MATRIX_CODE_5x5_22_12_5 4095 4 2
AR_MATRIX_CODE_3x3_HAMMING63 8 2 1
AR_MATRIX_CODE_4x4_BCH_13_9_3 512 2 1
AR_MATRIX_CODE_3x3_PARITY65 32 1 0
AR_MATRIX_CODE_3x3 64 0 0
AR_MATRIX_CODE_4x4 8192 0 0
AR_MATRIX_CODE_5x5 4194304 0 0
AR_MATRIX_CODE_6x6 8589934592 0 0

For example, the first row tells us that a 2D-barcode marker with a 5x5 matrix of squares yields 127 rotationally unique patterns that are associated with predetermined identifiers (IDs), and can detect up to 6 bits errors and correct 3 bit errors in the ID code.

In general, it is better to use the barcode type with the greatest possible Hamming distance, as this results in the lowest likelihood of one marker being misrecognized as a different marker.

Generating the images of the barcode markers

An online marker generator allows complete customisation of barcode size, EDC type, and border width. It is available at http://au.gmented.com/app/marker/marker.php

Pre-generated images of some of the 2D barcode marker types are included in the artoolkitX distribution in the folder Documentation/Square marker pattern images.

Testing barcode marker tracking using check_id

The artoolkitX utility check_id is an easy to use utility for realtime examination of 2D barcode marker tracking. Open a command-line session window (on macOS / Linux, open a Terminal window, on Windows, choose "Run" from the Start menu, type "cmd"). On Linux / macOS, type ./artoolkitx_check_id. On Windows, type artoolkitx_check_id.exe

You will see some output in your terminal, and a live camera window: ![check_id][check_id]

Point the camera directly at your marker. If artoolkitX has identified the marker, it will outline it with red lines and display the numerical marker ID. If artoolkitX has identified a trapezoidal region on the screen that could be a marker but which did not pass one or more of the marker identification stages, it will be outlined in a different colour. Pressing the '?' key will bring up a colour key indicating at which processing stage the potential marker was rejected.

There are more options that you can set (such as size of the marker border). Running the utility with the --help option will show the various command-line options for adjusting the default settings. The help text is reproduced here:

Usage: artoolkitx_check_id [options] [Multimarker config. file [Multimarker config. file 2]]
Options:
  --vconf <video parameter for the camera>
  --cpara <camera parameter file for the camera>
  --pattRatio f: Specify the proportion of the marker width/height, occupied
             by the marker pattern. Range (0.0 - 1.0) (not inclusive).
             (I.e. 1.0 - 2*borderSize). Default value is 0.5.
  --pattSize n: Specify the number of rows and columns in the pattern space
             for template (pictorial) markers.
             Default value 16 (required for compatibility with ARToolKit prior
             to version 5.2). Range is [16, 64] (inclusive).
  --pattCountMax n: Specify the maximum number of template (pictorial) markers
             that may be loaded for use in a single matching pass.
             Default value 50. Must be > 0.
  --borderSize f: DEPRECATED specify the width of the pattern border, as a
             percentage of the marker width. Range (0.0 - 0.5) (not inclusive).
             (I.e. (1.0 - pattRatio)/2). Default value is 0.25.
  -border=f: Alternate syntax for --borderSize f.
  --matrixCodeType k: specify the type of matrix code used, where k is one of:
             AR_MATRIX_CODE_3x3 AR_MATRIX_CODE_3x3_HAMMING63
             AR_MATRIX_CODE_3x3_PARITY65 AR_MATRIX_CODE_4x4
             AR_MATRIX_CODE_4x4_BCH_13_9_3 AR_MATRIX_CODE_4x4_BCH_13_5_5
             AR_MATRIX_CODE_5x5 AR_MATRIX_CODE_6x6 AR_MATRIX_CODE_GLOBAL_ID
  --labelingMode AR_LABELING_BLACK_REGION|AR_LABELING_WHITE_REGION
  --patternDetectionMode k: specify the pattern detection mode, where k is one
             of: AR_TEMPLATE_MATCHING_COLOR AR_TEMPLATE_MATCHING_MONO
             AR_MATRIX_CODE_DETECTION AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX
             AR_TEMPLATE_MATCHING_MONO_AND_MATRIX
  --version: Print artoolkitX version and exit.
  -loglevel=l: Set the log level to l, where l is one of DEBUG INFO WARN ERROR.
  -h -help --help: show this message