The code reading demo shows how to detect and decode QR codes and bar codes.
Let us walk through the processing graph below from top to bottom.
The images originate from a virtual camera configured in Image Source.
Adaptive Normalization normalizes the image so that the average intensity in any subimage of size
Target Mean. This makes it possible to separate dark codes from light background using a static threshold.
Cropping Tool can be used for selecting a part of the image for analysis. By default,
Sizeis set to
Whole Imageso the tool is in pass-through mode.
Now the processing path is split into two branches. The rightmost one detects and reads barcodes, whereas the left one detects and reads QR-codes. Otherwise the paths are symmetrical. Let's start with bacode reading.
Barcode Detection inputs the image and the region of interest in the customary
Size-format. You can limit the maximum number of codes the detector tries to find with the
Max Detectionsinput 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 as zero, the tool tries to guess it but does not always get it right. The tool outputs sets of
Sizematrices which locate the positions and orientations of the found codes.
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.
Barcode Reading Tool inputs the image and a
Size-locator and reads the code bounded by the code. Notice that the tool has two different input methods for the code location. The method is chosen with the
Reading Modeparameter. The options are:
- Single Line
- the barcode is read along a line specified by start and end points.
- the location of the barcode is set by
Size. 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 Typeinput parameter. This makes the reading faster and more reliable. If you don't know the code type, set the value to
Auto-detectwhich is the default.
The code contents and the detected code type are given as outputs.
Collect Tool is a counterpart to the
Iterate Tooldescribed above. It stacks up entries received in its inputs, producing either matrices or tables as output. In this example, the entries received at
Element 0input are the code strings and the entries at
Element 1are the code types. If there are, say, four codes found in the original input image, the output at
Result 0will be a 4-by-2 table. Notice that
Syncinput has to be connected to the corresponding
Script 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.
- Matrix Code Detection inputs the image and the region of interest in the customary
Size-format. As before, you can limit the maximum number of codes the detector tries to find with the
Max Detectionsparameter. The tool also needs to know the threshold that separates dark code modules from white background. In this case the images have been normalized so it would be possible to set a fixed threshold (e.g. 120 in this case). However, for the sake of demonstration, automatic threshold finding with Grayscale Histogram and Threshold Finding has been used.