Barcode Recognition Settings

Overview

In the barcode recognition process implemented in Aspose.BarCode for Android via Java, barcode data decoding is initiated according to the special protocol after scanning the raw data from a graphical representation. Some linear and postal barcode types have passed standardization after their wide implementation, and therefore, it has lead to the presence of incompatible decoding formats. To resolve possible conflicts, class BarCodeReader provides a special class called BarcodeSettings used to manage barcode decoding settings.

Checksum Verification

Varios 1D and postal types include checksum control mechanisms for data integrity verification. To adjust checksum settings for data validation purposes, class BarcodeSettings contains the ChecksumValidation enum. Generally, barcode types can be classified according to the following types: with obligatory checksum controls and with optional ones. The ChecksumValidation enum suggests different options for these two groups. The barcode recognition procedure varies in line with checksum settings.

Checksum Validation for symbologies with Obligatory Checksum

Barcoded types with obligatory checksum controls require performing compulsive checksum validation when ChecksumValidation is initialized using ChecksumValidation.DEFAULT or ChecksumValidation.ON values. Alternatively, setting the ChecksumValidation.Off value turns off checksum verification and in this way, allows decoding information from invalid barcodes. This option increases the probability of incorrect recognition.

The following code sample shows how to adjust checksum settings for the barcode type with obligatory checksum controls (namely, *Code 11*).

//create barcode
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code11, "123456"))
{
    gen.Parameters.Barcode.XDimension.Pixels = 2;
    gen.Save($"{path}Code11.png", BarCodeImageFormat.Png);
}

//read barcode image with ChecksumValidation.Default being set
Console.WriteLine("ReadChecksumCode11:");
Console.WriteLine("ChecksumValidation: Default");
using (BarCodeReader read = new BarCodeReader($"{path}Code11.png", DecodeType.Code11))
{
    read.BarcodeSettings.ChecksumValidation = ChecksumValidation.Default;
    foreach (BarCodeResult result in read.ReadBarCodes())
    {
        Console.WriteLine($"CodeType:{result.CodeTypeName}");
        Console.WriteLine($"CodeText:{result.CodeText}");
        Console.WriteLine($"1D Value:{result.Extended.OneD.Value}");
        Console.WriteLine($"1D CheckSum:{result.Extended.OneD.CheckSum}");
    }
}

//read barcode image with ChecksumValidation.Off being set
Console.WriteLine("ChecksumValidation: Off");
using (BarCodeReader read = new BarCodeReader($"{path}Code11.png", DecodeType.Code11))
{
    read.BarcodeSettings.ChecksumValidation = ChecksumValidation.Off;
    foreach (BarCodeResult result in read.ReadBarCodes())
    {
        Console.WriteLine($"CodeType:{result.CodeTypeName}");
        Console.WriteLine($"CodeText:{result.CodeText}");
        Console.WriteLine($"1D Value:{result.Extended.OneD.Value}");
        Console.WriteLine($"1D CheckSum:{result.Extended.OneD.CheckSum}");
    }
}
–>

Checksum Validation for Barcodes with Optional Checksum

ChecksumValidation allows enabling and disabling checksum controls for barcode standards with optional checksum verification. To request checksum validation, the following setting should be used: ChecksumValidation.ON. When other options, ChecksumValidation.DEFAULT and ChecksumValidation.OFF, are enabled, checksum controls are disabled.

The following code snippet illustrates recognition options for symbologies with optional checksum controls (i.e. *Code 39*).

//create barcode
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code39Extended, "123456"))
{
    gen.Parameters.Barcode.XDimension.Pixels = 2;
    gen.Parameters.Barcode.IsChecksumEnabled = EnableChecksum.Yes;
    gen.Save($"{path}Code39.png", BarCodeImageFormat.Png);
}

//read barcode image with ChecksumValidation.Default being set
Console.WriteLine("ReadChecksumCode39:");
Console.WriteLine("ChecksumValidation: Default");
using (BarCodeReader read = new BarCodeReader($"{path}Code39.png", DecodeType.Code39Extended))
{
    read.BarcodeSettings.ChecksumValidation = ChecksumValidation.Default;
    foreach (BarCodeResult result in read.ReadBarCodes())
    {
        Console.WriteLine($"CodeType:{result.CodeTypeName}");
        Console.WriteLine($"CodeText:{result.CodeText}");
        Console.WriteLine($"1D Value:{result.Extended.OneD.Value}");
        Console.WriteLine($"1D CheckSum:{result.Extended.OneD.CheckSum}");
    }
}

//read barcode image with ChecksumValidation.On being set
Console.WriteLine("ChecksumValidation: On");
using (BarCodeReader read = new BarCodeReader($"{path}Code39.png", DecodeType.Code39Extended))
{
    read.BarcodeSettings.ChecksumValidation = ChecksumValidation.On;
    foreach (BarCodeResult result in read.ReadBarCodes())
    {
        Console.WriteLine($"CodeType:{result.CodeTypeName}");
        Console.WriteLine($"CodeText:{result.CodeText}");
        Console.WriteLine($"1D Value:{result.Extended.OneD.Value}");
        Console.WriteLine($"1D CheckSum:{result.Extended.OneD.CheckSum}");
    }
}
–>

Managing Barcodes with Unicode Encodings

Aspose.BarCode for Android via Java provides class BarcodeSettings that contains a special method called setDetectEncoding that enables the automatic recognition of UTF8 and UTF16 Unicode encodings for 2D symbologies and allows re-encoding barcode information into a string with Unicode characters. If this recognition mode is turned off, barcode information can be scanned and decoded manually based on the desired encoding.

FNC Symbols

The GS1 association suggests using FNC character to perform decoding of some symbologies, including Code 128 and Code 128. Four types of FNC symbols (FNC1-4) are supported. FNC1 is the most widely used one that is intended for GS1 Application Identifier (AI) marking. When a barcode does not relate to any of GS1 types (e.g. Code 128 or GS1 Code 128), the decoder processes FNC symbols as “<FNC#>”. These symbols can be removed from decoding results passing the False value to the setStripFNC method.

Australia Post Barcodes

Australia Post is a 4-state postal barcode type implemented by the Australian Post. This type requires including special two-digit format control code (FCC) fields and eight-digit sorting code (SC) fields into barcode information. FCC fields are intended to set one of three supported types with various fixed number of bars: 37, 52, or 67 bars. For some FCC, barcodes may comprise a customer information (CI) field that indicates one of the encoding types supporting numerical or alphanumeric characters. Customer information can take 31 bars in 67-length barcodes or 16 bars in 52-length ones. The Australia Post symbology has checksum controls and supports Reed-Solomon error correction.

Because of the possible presence of customer information in barcode information for Australia Post, the recognition process has some peculiarities. Aspose.BarCode for Android via Java provides class AustraliaPostSettings to manage recognition parameters according to specific industrial needs.

Decoding Customer Information in Standard Formats

The Australia Post standard enables encoding additional customer data in three formats; automatic detection of the used format is not supported. The desired decoding format can be enabled through the setCustomerInformationInterpretingType method of enum CustomerInformationInterpretingType that can take different values explained in the table below.

Australia Post Encoding Table Supported Symbols
CTable Numerical digits, English letters, space symbol, and #
NTable Numerical digits
Other 0, 1, 2, and 3 that correspond to H, A, D, and T states

CTable

Other

Removal of Fill Patterns

The Australia Post type requires setting fixed size for each subtype. When the CTable format is enabled, the empty space included in the input message is decoded as “z”. To disable this property, the setIgnoreEndingFillingPatternsForCTable method needs to be called.