Code readingπ
Summaryπ
The code reading demo shows how to detect and decode QR codes and bar codes.
Downloadsπ
Detailed descriptionπ
Let us walk through the processing graph below from top to bottom.

The processing graph of the code reading demo.π
The images originate from a virtual camera configured in Image Source.
Crop Image can be used for selecting a part of the image for analysis. By default,
Size
is set toWhole Image
so the tool is in pass-through mode.Histogram and Find Threshold tools determine the threshold between white background and dark bars and modules in the code.
Now the processing path is split into two branches. The rightmost one detects and reads QR codes, whereas the left one detects and reads barcodes. Otherwise the paths are symmetrical. Letβs start with barcodes.
Find Barcode finds the positions of barcodes in customary
Frame
andSize
format. The intensity threshold between the bars and the background comes fromFind Threshold
tool. You can limit the maximum number of codes the detector tries to find with theMax Detections
input parameter.There is always some white space around the first and the last bars of the barcode. This space is called a quiet zone. If you roughly know how wide the quiet zone is in terms of world coordinates (or pixels in case of uncalibrated camera), you can help the code finder by setting the estimate in parameter
Quiet Zone Width
. If the width is set asAutomatic
, the tool tries to guess it but does not always get it right. The tool outputs sets ofFrame
andSize
matrices which locate the positions and orientations of the found codes.Begin Iterate Tool has been configured to input the sets of frames and sizes from the detector. It splits frame and size matrix sets back to single entities. For instance, assume that there are four barcodes in the image. In this case Iterate Tool splits the 16-by-4 frame matrix into four individual 4-by-4 matrices and the 4-by-2 size matrix into four 1-by-2 matrices.
Read Barcode Tool inputs the image and a
Frame
/Size
-locator and reads the code bounded by the box defined byFrame
andSize
. Notice that the tool has two different input methods for the code location. The method is chosen with theReading Mode
parameter. The options are:- Single Line
the barcode is read along a line specified by start and end points.
- Area
the location of the barcode is set by
Frame
andSize
. This method is used in this example.
If you know the code type in advance (e.g.Β EAN-13, Code128 etc), you can configure it with the
Code Type
input parameter. This makes the reading faster and more reliable. If you donβt know the code type, set the value toAuto-detect
which is the default.The code contents and the detected code type are given as outputs.
End Iterate Tool is a counterpart to
Begin Iterate Tool
described above. It stacks up entries received in its inputs, producing either matrices or tables as output. In this example, the entries received atElement 0
input are the code strings and the entries atElement 1
are the code types. If there are, say, four codes found in the original input image, the output atResult 0
will be a 4-by-2 table. Notice thatSync
input has to be connected to the correspondingSync
output inBegin Iterate Tool
.

Begin Iterate and End Iterate mark parts of the graph that are repeated.π
JavaScript Tool runs a simple script that takes the table of strings and filters out the empty one. This is necessary because sometimes the barcode is easier to find than it is to read. If the reading fails, the reader produces an empty string that is filtered out by the script.
The processing sequence for QR code reading is nearly identical.
Find Matrix Code inputs the image and the intensity threshold as before. Again, you can limit the maximum number of codes the detector tries to find with the
Max Detections
parameter.
The found position candidates are now iterated over just as they were in
barcode reading. The healthy codes are filtered by the script. The same
script is used by both QR and barcode readers.
The same image can contain both QR codes and barcodes.

Four QR codes and two different bar codes were detected.π