Skip to end of metadata
Go to start of metadata
  

BarCode Recognition Basics

Aspose.BarCode for C++ component contains two powerful classes, BarCodeBuilder and BarCodeReader, handling BarCode images generation and recognition respectively. BarCodeReader reads most commonly used 1D and 2D barcodes, detecting them anywhere.

How to scan a barcode from a picture

The following example demonstrate how to scan a picture of a barcode image using Aspose.BarCode

A barcode image

Scan results

Supporting Image Formats

Summary

BarCodeReader accepts many standard image formats, which are as followed:

  1. BMP
    BMP is a standard format to store device-independent and application-independent images. The number of bits per pixel (1, 4, 8, 15, 24, 32, or 64) for a given BMP file is specified in a file header. BMP files with 24 bits per pixel are common. BMP files are usually not compressed.
  2. Graphics Interchange Format (GIF)
    GIF is a common format for images that appear on Web pages. GIFs are compressed, but no information is lost in the compression process; a decompressed image is exactly the same as the original. One color in a GIF can be designated as transparent, so that the image will have the background color of any Web page that displays it. GIFs store at most 8 bits per pixel, so they are limited to 256 colors.
  3. Joint Photographic Experts Group (JPEG)
    JPEG is a compression scheme that works well for natural scenes such as scanned photographs. Some information is lost in the compression process, but often the loss is imperceptible to the human eye. JPEGs store 24 bits per pixel, so they are capable of displaying more than 16 million colors. JPEGs do not support transparency.
  4. Exchangeable Image File (EXIF)
    EXIF is a file format used for photographs captured by digital cameras. An EXIF file contains an image that is compressed according to the JPEG specification. An EXIF file also contains information about the photograph (date taken, shutter speed, exposure time, and so on) and information about the camera (manufacturer, model, and so on).
  5. Portable Network Graphics (PNG)
    The PNG format retains many of the advantages of the GIF format but also provides capabilities beyond those of GIF. Like GIF files, PNG files are compressed with no loss of information. PNG files can store colors with 8, 24, or 48 bits per pixel and grayscales with 1, 2, 4, 8, or 16 bits per pixel. In contrast, GIF files can use only 1, 2, 4, or 8 bits per pixel. A PNG file can also store an alpha value for each pixel, which specifies the degree to which the color of that pixel is blended with the background color.
  6. Tag Image File Format (TIFF)
    TIFF is a flexible and extendable format that is supported by a wide variety of platforms and image-processing applications. TIFF files can store images with an arbitrary number of bits per pixel and can employ a variety of compression algorithms.

BarCodeReader will reads in a jpg image

Before

After

Recognizing Specific Barcode Symbology

This section shows the basic settings of BarCodeReader. We will specify the Symbology type in the constructor of BarCodeReader class and use Read() method to
recognize the barcodes from the image. This should be the case if we already know the Symbology Type.

SymbologyType of a barcode

If we specify the Symbology Type in the constructor, the program will know beforehand about the symbology type to be recognized and it will be faster than not passing symbology type in the constructor. If we know the types of barcode ahead, recognition will speed up a lot. The following code snippet shows you how to specify the symbology Type.

 

For unknown types of barcodes, either set call Read() method with no arguments or programmatically loop through every Symbology.

BarCodeReadType

GetReadType() method of BarCodeReader class returns the symbology type of the recognized barcode. Continuing the sample above, the first recognised barcode's SymbologyType is: For those variation barcode Symbologies, its original SymbologyType or super set SymbologyType will be returned. For example, both Code39Standard and Code39Extended barcode will be recognised as Code39Extended barcode.

CodeText

GetCodeText() method of a BarCodeReader class returns the string which is the decoded data from the barcode.

Recognizing Multiple Symbologies in Single Image

There might be such situations in which there are multiple barcodes in a single image. Aspose.BarCode can easily recognize all the barcodes of the supported symbology types. This can be done by specifying multiple symbology types separated by bitwise OR operator “|” in the barcode constructorSee the image below. It contains 2 barcodes of type Code39Standard and Pdf417. Since BarCodeReader.Read() method returns a Boolean value, you can call it in a while loop to recognize all the barcodes in the image. The Read() method will return true for the first barcode, again return true for the second barcode and then it will return false in the third iteration.

 

In the above code snippet, we assumed that we already knew the symbology types of the barcodes in the image. So, we specified the symbologies separated by bitwise OR “|” operator. If the symbologies are not known in advance, you can simple use BarCodeReadType.AllSupportedTypes to check for any symbology type. In this case, the constructor in the above code snippet will be modified as follows:

Recognizing Barcode in WPF Project

Aspose.BarCode supports recognizing barcodes in WPF projects. To do so, specify the symbology type in the constructor of the BarCodeReader class and use the Read() method to recognize the barcodes from the barcode control. Aspose.BarCode.WPF.dll should be referenced in WPF applications for barcode generation and recognition. To use Barcode in WPF Project please follow below steps.

  1. Create a new WPF application is Visual Studio 2012.
  2. Add a reference to Aspose.BarCode.WPF.dll by right-clicking the project and selecting Add Reference.
  3. Locate the DLL in the folder that you installed Aspose.BarCode to.
  4. Add the Aspose.BarCode control on the toolbox.
  5. Drag the control to the form.
  6. Right-click the control and select Properties.
  7. Adjust barcode properties like code text, symbology type, fonts, colors etc.
  8. Please see details: Using with WPF.

Now write the code that recognizes the barcode:

  1. Drag a button control to the form.
  2. Add the following code to its Click event.

The code below specify the symbology read type and image format in the BarCodeReader class constructor.

 

For more WPF samples, please view the Downloads section at www.aspose.com.

Detect Orientation of a BarCode

Aspose.BarCode allows developers to detect orientation of a detected bar code by calling GetAngle method of BarCodeReader class. The following code snippet shows you how to detect orientation of a barcode.

Detect an Unreadable Barcode on the Image

Aspose.BarCode for C++ APIs allow developers to detect an unreadable barcode on the image.  It is currently supported by QR and Code128 recognition engines and enabled by the modes: RecognitionMode.MaxBarCodes and RecognitionMode.ManualHints with ManualHint.IncorrectBarcodes. All recognition modes are defined in this help topic: Switch Barcode Recognition Modes According to the Requirement. The new GetIsDeniable method has been added to the Aspose.BarCode class in order to indicate whether the image contains any unreadable barcodes. The following code snippet shows you how to detect an unreadable barcode on the Image.

 

Scan result: Code128: A;000000014941, IsDeniable: True

Detect Decorated Datamatrix Barcode

Aspose.BarCode for C++ API allow developers to detect decorated datamatrix barcode on the image. To detect the decorated datamatrix barcode, developers have to settings the RecognitionMode property to ManualHints and ManualHints property to SpecialFormOfCells of the BarCodeReader class will detect the decorated datamatrix barcode. The following code snippet shows you how to detect decorated datamatrix barcode.

 

Result: DataMatrix: StarDatamatrix

Detect Dot Peen Datamatrix Barcode

Aspose.BarCode for C++ API allow developers to detect dot peen datamatrix barcode on the image. To detect the dot peen datamatrix barcode, developers have to set the RecognitionMode property to ManualHints and ManualHints property to SpecialFormOfCells of the BarCodeReader class will detect the decorated datamatrix barcode. Following is the code illustration.

 

Result:
DataMatrix: BERMA Macchine Budrio (BO)
DataMatrix: BERMA Macchine Budrio (BO)
DataMatrix: BERMA Macchine Budrio (BO)
DataMatrix: BERMA Macchine Budrio (BO)
DataMatrix: BERMA Macchine Budrio (BO)
DataMatrix: BERMA Macchine Budrio (BO)

Select an ECC Type to Encode a Barcode

Aspose.BarCode API allow developers to select an ECC 000 to 140 and ECC 200 levels to encode a DataMatrix barcode. The new DatamatrixECC property is added to the BarCodeBuilder class in order to select an appropriate ECC level while encoding DataMatrix barcode. DataMatrix symbology adopts two types of error correction algorithm, depending on the ECC level employed. The ECC levels 000 to 140, which offer five different error correction levels. However, the commonly used ECC 200 level uses Reed-Solomon error correction. The new DataMatrixEccType Enum has been added to specify the type of the ECC to encode.

  • EccAuto - Specifies that encoded Ecc type is defined by default Reed-Solomon error correction or ECC 200.
  • Ecc000 - Specifies that encoded Ecc type is defined ECC 000.
  • Ecc050 - Specifies that encoded Ecc type is defined ECC 050.
  • Ecc080 - Specifies that encoded Ecc type is defined ECC 080.
  • Ecc100 - Specifies that encoded Ecc type is defined ECC 100.
  • Ecc140 - Specifies that encoded Ecc type is defined ECC 140.
  • Ecc200 - Specifies that encoded Ecc type is defined ECC 200.
    (This is recommended to use)
Labels
  • No labels