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.
Crop Image 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 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
Sizeformat. The intensity threshold between the bars and the background comes from
Find Thresholdtool. 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
Automatic, 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.
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
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.
End Iterate Tool is a counterpart to
Begin 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
Begin Iterate Tool.
- Jave 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.
- 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
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- and barcodes.