Code reading

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 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 to Whole 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 and Size format. The intensity threshold between the bars and the background comes from Find Threshold tool. You can limit the maximum number of codes the detector tries to find with the Max 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 as Automatic, the tool tries to guess it but does not always get it right. The tool outputs sets of Frame and Size 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 by Frame and Size. Notice that the tool has two different input methods for the code location. The method is chosen with the Reading 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 and 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 Type input parameter. This makes the reading faster and more reliable. If you don't know the code type, set the value to Auto-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 at Element 0 input are the code strings and the entries at Element 1 are the code types. If there are, say, four codes found in the original input image, the output at Result 0 will be a 4-by-2 table. Notice that Sync input has to be connected to the corresponding Sync output in Begin Iterate Tool.

Begin Iterate and End Iterate mark parts of the graph that are repeated.

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. Script which filters out empty strings

The same image can contain both QR codes and barcodes.

Four QR codes and two different bar codes were detected.

Four QR codes and two different bar codes were detected.