2D codes๐
More Info
Learn about reading 2D codes, print quality inspection, and many other topics in interactive online courses at our MVTec Academy.
2D code symbols are a special kind of two-dimensional patterns that encode text and numbers. HALCON is able to read the most popular 2D codes: Data Matrix ECC 200, QR Code, Micro QR Code, Aztec Code, PDF417, and DotCode.
Except for DotCodes, all these codes contain a
Due to the special design of the codes, they can be decoded even if some parts are disturbed.

Figure 1. Reading a 2D code of type PDF417
This image is from the example program 2d_data_codes_default_settings.hdev.
2D code types๐
HALCON supports the following 2D code types:
2D codes encode characters and numbers in graphical symbols that are constructed by dark and light bars or dots that are called modules.
In contrast to 1D bar codes, for the symbols of 2D codes changes occur along both directions.
Thus, the same information can be encoded in smaller symbols.
The actual size of a symbol, i.e., the number of modules in both directions, mainly depends on the length of the encoded message and the level of the applied error correction.
The latter is needed to completely decode a symbol even when it has small defects, for example, if some of the modules are not visible.
There are different types of 2D codes.
Two common types are the so-called stacked codes and matrix codes.
While stacked codes can also be read row by row by a 1D bar code reader, matrix codes can only be decoded by inspecting images, i.e., a camera is needed.
The HALCON operators for reading 2D codes assume images as the source for matrix codes as well as for stacked codes.
A basic goal of HALCON is that all 2D code operators are applied as easily as possible.
Every 2D code operator can be applied to all supported symbol types; only the assigned parameters vary.
Additionally, finding, reading, and decoding of a symbol can be done with a single operator call.
Stacked 2D codes๐
Of the stacked codes, HALCON supports PDF417 (Figure 2).
Its symbol is built up by several 1D bar codes, which are arranged in rows and columns.
Each 1D bar code encodes an individual codeword.
According to the name of the symbol type, each codeword consists of four dark as well as four light bars (spaces) and is built up by 17 modules.
It always starts with a dark and ends with a light bar.
The number of rows and columns of a PDF417 symbol is variable in a range of 3 to 90 rows and 1 to 30 columns.
Start and stop patterns frame the symbol on the left and right border.
The first and the last columns of codewords are called left and right row indicators.
These codewords provide important information for the decoding, like the number of rows and columns, the error correction level etc.
Around the symbolโs border, a homogeneous frame is placed, which is called quiet zone.
For small symbols, a variant of PDF417 exists, where no right row indicator exists and the stop pattern is reduced to a one module wide bar. This variant is called compact or truncated PDF417. HALCON operators can read both conventional and truncated PDF417.
Figure 2. Stacked code of type PDF417
Start pattern
Left row indicator
Data encoded in 2 columns
Right row indicator
Stop pattern
Composition of a PDF417 codeword: four dark and four light bars, built up by 17 modules
Matrix codes๐
Matrix codes use graphical patterns. They consist of three components: a so-called finder element or finder pattern (except for DotCode symbols), which is needed to find the symbol and its orientation in an image, the data patterns, which consist of binary modules grouped relative to the finder pattern, and a quiet zone, similar to the one needed for PDF417 symbols. The 2D code modules can be square, rectangular, or circular and are ordered in rows and columns. The number of rows and columns define the size of a symbol.
Data Matrix ECC 200๐
The finder element of a Data Matrix ECC 200 consists of an L-shape, and alternating dark and light modules on the opposite borders.
Figure 3. Data Matrix ECC 200 (finder pattern marked orange)
QR Code๐
The finder element of a QR Code consists of three squares, which are called position detection pattern. The number of rows and columns of a QR Code is directly linked to its version number (the higher the version number, the bigger the symbol).
Figure 4. QR Code (finder pattern marked orange)
Micro QR Code๐
The Micro QR Code has only one finder pattern which is square shaped. This โposition detection patternโ is located in the upper left corner of the symbol.
Figure 5. Micro QR Code (finder pattern marked orange)
Aztec Code๐
The finder element of the Aztec Code consists of squares that are nested into one another and are located in the middle of the code.
Figure 6. Aztec Code (finder pattern marked orange)
DotCode๐
The DotCode does not contain a finder pattern.
Figure 7. DotCode