Recognize 2D matrix barcodes with spatial distortions in .NET

Blog category: Barcode.NET

May 6, 2020

VintaSoft Barcode .NET SDK can be used in .NET/C# application for recognition of two-dimensional Aztec, QR Code and Han Xin Code barcodes with random surface distortions. In practice this allows significantly simplify the barcode recognition from photographic camera, web camera or smartphone camera, because now it is not necessary to align the barcode in front of camera, and it is even possible to recognize barcodes from uneven surfaces.

First sample of Aztec barcode with spatial distortions


Our developers have spent a lot of fascinating hours developing and improving the algorithm of distortion correction using web and photographic cameras. Below you can watch on such barcodes via "eyes" of our barcode reader:

View to the Aztec barcode with spatial distortions via 'eyes' of barcode reader of VintaSoft Barcode .NET SDK

At some moment our developers started to see the barcodes exactly like that. :)


Here is C# code that allows to recognize Aztec, QR and Han Xin Code barcodes with spatial distortions:
/// <summary>
/// Recognizes 2D matrix barcodes (Aztec, QR Code and Han Xin Code) with spatial distortions.
/// </summary>
public void Recognize2dBarcodeWithSpatialDistortions()
{
    // create barcode reader
    using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
    {
        // specify that reader must search for Aztec, QR and Han Xin Code barcodes
        reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.Aztec |
            Vintasoft.Barcode.BarcodeType.QR |
            Vintasoft.Barcode.BarcodeType.HanXinCode;

        // specify that reader must search for horizontal and vertical barcodes only
        reader.Settings.ScanDirection = Vintasoft.Barcode.ScanDirection.Horizontal | Vintasoft.Barcode.ScanDirection.Vertical;

        // read barcodes from image file
        Vintasoft.Barcode.IBarcodeInfo[] barcodeInfos = reader.ReadBarcodes("barcodes.png");

        // if barcodes are not detected
        if (barcodeInfos.Length == 0)
        {
            System.Console.WriteLine("Barcodes are not found.");
        }
        // if barcodes are detected
        else
        {
            // get information about recognized barcodes

            System.Console.WriteLine(string.Format("{0} barcode(s) found:", barcodeInfos.Length));
            System.Console.WriteLine();
            for (int i = 0; i &lt; barcodeInfos.Length; i++)
            {
                Vintasoft.Barcode.IBarcodeInfo barcodeInfo = barcodeInfos[i];
                System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, barcodeInfo.BarcodeType));
                System.Console.WriteLine(string.Format("Value:      {0}", barcodeInfo.Value));
                System.Console.WriteLine(string.Format("Region:     {0}", barcodeInfo.Region));
                System.Console.WriteLine();
            }
        }
    }
}


The tests showed that the barcode reader can handle successfully one or more type of distortions specified below:

Here are some images with distorted barcodes:
Second sample of Aztec barcode with spatial distortions

Third sample of Aztec barcode with spatial distortions

First sample of Han Xin Code barcode with spatial distortions

Second sample of Han Xin Code barcode with spatial distortions

First sample of QR barcode with spatial distortions

Second sample of QR barcode with spatial distortions


More images with distorted barcodes you can find within the distributive package of VintaSoft Barcode .NET SDK.

If you face any problems in barcode recognition and you feel that our barcode recognition algorithm should solve them, please send your images for test and review at support@vintasoft.com.