Skip to end of metadata
Go to start of metadata

Optimized Scan for Barcode Recognition

There are two approaches addressing recognition optimization, the first is towards accuracy, the second is towards speed:

Pinpointing barcode

  • SymbologyType setting. If the barcode type is unknown, try not to pass the symbology type (BarCodeReadType) in the constructor. Instead, try to recognize separately.
  • BarCodeReader's internal optimization schema will sacrifice accuracy for speed if symbology type is not specified in the BarCodeReader’s constructor.

Speed up

  • Reduce image size. Larger images will lead to longer processing time.

Handling Barcode Orientation

Sometimes, the barcode in an image or document might be printed at an angle, for example 90 degrees as shown below. In this case, the barcode reader tries to detect the barcode in all possible directions. It will read it but it may take longer to detect the barcode than it would otherwise. If you know the angle or orientation of the barcode in advance, you can set the orientation in BarCodeReader to reduce the recognition time. These orientation hints are used to rotate the bar code before passed in recognition.

Setting the Barcode Orientation

The barcode above image is at a 90 degree angle and has an orientation of top to bottom. Orientation is set using the BarCodeReader.OrientationHints property with the RecognitionHints.OrientationHints class’ properties. Aspose.BarCode for C++ supports the following orientation hints:

  • NoRotate – no rotation needed.
  • Rotate90 – the image is rotated 90 degrees.
  • Rotate180 – the image is rotated 180 degrees.
  • Rotate270 – the image is rotates 270 degrees.

The sample code snippet below shows how to recognize the barcode in above image using orientation hints.

Better and Faster Image Processing for Barcode Recognition

Aspose.BarCode for C++ provides better and faster barcode recognition with the following image processing algorithms:

  • Complex background
    This technique can locate a barcode region in complex or colored background through region-based image analysis.
  • Invert image
    This technique inverts the image before recognition. It helps the code to recognize images with a black background and white, or near, barcode.
  • Line Codes Restoration Filter
    This filter restores corrupted strokes for 1D barcodes. This degradation could come from dirty, dusty products or discarded barcode resulting in touched or missing parts of bars.
  • Median smoothing image processing
    Median smoothing removes the noise from the image while preserving the image edges. This technique gives a perfect result. In more complicated images, less data is lost by taking the median.
    • MedianSmoothingWindowSize: Gets or sets the median smoothing window size. Typical values are 3 or 4. The default value is 3. The recognition hint MedianSmoothing must be set. For noisy images, 4 is good value.

Recognition Hints Samples

The following code snippet shows how to use the grayscale image processing technique during barcode recognition.

Marking BarCode Regions in Image

In this section, we will read the image and mark all the barcode regions, for all the recognized barcodes in the image. The barcode region is the part of the image that only contains the barcode itself. In a large image, it is possible that there are other texts or images along with the barcode. Getting the barcode region will separate the barcodes from other text/objects in the image by marking their edges or by filling with some color. First, we will read the BarCodes in the image using the BarCodeReader.Read() method. Then, we will get the region of the barcode using BarCodeReader.GetRegion() method, which will return an instance of type BarCodeRegion. We can then draw edges around the barcode using BarCodeRegion.DrawBarCodeEdges() method.

Switch Barcode Recognition Modes According to the Requirement

Aspose.BarCode for C++ provides some recognition modes, those help developers to quickly set up and tune the processing speed and quality in a way which is the most appropriate for their need.

  • Max Performance
    It finds all the possible good and average quality barcodes. Uses only the fastest algorithms. Enabled by default.
  • Max Quality
    It finds all the possible barcodes with good or bad quality. It doesn't return potential barcodes. Uses different fast and slow algorithms.
  • Max Barcodes
    It extends max quality. Finds even potential barcodes. Uses extra algorithms which may recognize incorrect barcodes, barcodes on complex background, noisy or damaged barcodes, etc. You may observe extra spurious barcodes.
  • Manual Hints
    Developers configure hints optionally. It allows them to adjust the balance between speed and quality manually.

Apply Manual Hints

It allows developers to configure options of recognition accuracy and speed manually. We need to change the property "RecognitionMode" to "RecognitionMode.ManualHints". Its default value is None.

    • None
      There are no heavy recognition algorithms. The fastest recognition algorithms are used there, however if image is noisy recognition will fail. Used by default.
    • Invert Image
      Use when image is white on black background. Typically BarCode images are white on black background.
    • Incorrect Barcodes
      Additional algorithms are included to recognize incorrectly generated or damaged barcodes (skipped bars, stop symbol, etc).
    • Complex Background
      It analyzes barcode background. Useful with complex or colored backgrounds.

The following code snippet shows how to switch the barcode recognition modes:

Optimize BarCode Recognition Process

ProcessorSettings class of namespace Aspose.BarCodeRecognition allow us to speed up the recognition process by defining the settings to involve multi-threading calculations and setting how many number of processor cores to use.Let's experience this feature and see how it works.

Aspose.BarCodeRecognition namespace introduced a class ProcessorSettings to define the settings for involving multi-threading & number of processor cores to be used. ProcessorSettings can be found as a static member of class BarCodeReader. Developers can set UseAllCores property to TRUE or FALSE to specify whether to use all cores of the processor or not. In case it is set to FALSE then set how many core to be use by setting UseOnlyThisCoresCount propery that takes in an integer value. The following code snippet shows you how to optimize barode Recognition Process

Speed Up Barcode Recognition using Manual Hints

This example shows how to speed up the recognition process using manual hints.

Optimizing BarCode Recognition Process

BarCodeReader.ManualHints property has been introduced to speed up recognition process. ManualHint Enumeration can be used to set different manual hints.

  • No labels