How does deep learning benefit barcode scanning?

Although barcode scanners have been around since the 1970s, their performance is still increasing. The latest leap in speed and accuracy came with the introduction of deep learning algorithms, which help cameras detect and read both 1D and 2D barcodes in a matter of milliseconds. Let us take a closer look at how this works.

app store

Scanning barcodes with mobile devices

In 2002, Japanese phone manufacturers started shipping devices with built-in QR code scanners. The quality of phone cameras has come a long way since then, making it possible to read a huge range of barcode symbologies.

With the rise of the smartphone, traditional handheld scanners have become less relevant, since most people now carry a powerful barcode scanning tool wherever they go. Thanks to computer vision technology, a smartphone camera is more than capable of scanning any 1D and 2D barcode symbology as long as the scanning software supports it. However, camera-based scanning used to perform poorly under real-world conditions.

That’s where deep learning comes into play. The ability of these models to recognize patterns make them a perfect tool for barcode detection, improving on classic computer vision approaches. With some optimization, a high degree of accuracy can be achieved even on mobile devices.

Deep learning for barcode scanning can improve performance in all areas:

  1. Locating the barcode
  2. Recognizing the barcode type
  3. Processing the barcode

Let’s take a look at what each of these entails.

Locating the barcode

Before the scanning software can start decoding the information stored in a barcode, it first has to find it in the live image feed of the device’s camera. This is easier said than done: Not only are there many different barcode symbologies the software has to be able to recognize as such, it also needs to work in a range of conditions.

Training a deep learning model on a large set of example images improves its ability to locate a barcode quickly. For every image, this model outputs a set of bounding boxes that represent the possible locations of the barcode – or barcodes – within it.

Since it may detect multiple bounding boxes for a single barcode, a post-processing step known as “non-maximum suppression” is applied. This removes redundant detections and retains only the most confident one.

This final output is returned as the location of the barcode within the image, as represented by a bounding box or a set of coordinates.

Recognizing the barcode

In the next step, the scanner has to figure out which of the many supported barcode symbologies the located code belongs to. Some barcode types, like the QR code or the Aztec code, have distinct finder patterns that differentiate them. Others, like the RSS code, can pose a problem: Since it is a stacked symbology, the model might mistake it for two separate barcodes.

A convolutional neural network (CNN) can help with that. CNNs are commonly used for image processing and can efficiently recognize different shapes, which makes them well-suited for detecting barcode type.

This requires training a CNN on a large dataset of labeled barcode images. The CNN learns to recognize their distinctive features, such as the sequences of black and white bars or the finder patterns. Preprocessing the input by adjusting its contrast or reducing image noise can improve the CNN’s results.

Since a CNN processes an image in multiple stages, extracting its features bit by bit, it is very effective at recognizing barcodes in challenging conditions such as low light or low resolution. This method also helps it differentiate between barcode formats, whether 1D barcodes such as UPC or 2D barcodes such as QR.

Processing the barcode

Once a barcode’s symbology has been correctly recognized, it’s time to read its data. This is encoded in the black bars or squares and the white space in between. Different types of barcodes use different encoding schemes and algorithms, each with its own decoding rules.

In general, decoding a barcode involves four steps:

Finding the start and stop characters

Most barcodes feature special patterns that indicate the beginning and end of the encoded data. The decoder looks for these start and stop characters to determine the boundaries of the data.

2D barcodes also contain such patterns, though they are usually more complex. They can provide the scanner with additional information about how to decode the contained data.

Applying the decoding algorithm

The appropriate decoding algorithm is applied to the sequence of bars or squares and the spaces between them. This may involve translating the pattern into a specific data format, such as binary, numeric, or alphanumeric code.

Checking for reading errors

Many barcode symbologies include check digits that are used to detect any errors in the decoded data. The decoder takes the scan result, calculates a checksum according to a known formula, and compares this to the check digit. If they do not match, the scan has to be repeated. 2D barcodes employ error correction formulas to prevent this to some degree.

Outputting the decoded data

Finally, the decoded information is shown to the user in a readable format, such as a string of numbers or letters. It can also be transmitted to a database or backend solution for further processing.

Optimizing barcode scanning with deep learning algorithms

Thanks to advances in computer vision and deep learning technologies, barcode scanners are now more powerful than ever. Our Barcode Scanner SDK, which can be integrated into any mobile or web app, scans barcodes in 0.2 seconds and with 98.7% accuracy. Its AR Overlay can preview the contents of multiple barcodes in real time, enabling use cases that would have been impossible just a few years ago.

Powerful barcode scanning software like this has the potential to greatly expand the possibilities of this tried and true technology. We are already seeing robots that make manual stocktaking obsolete by driving through aisles and scanning whole shelves’ worth of items at once. 

This requires neither expensive hardware nor a lot of storage space. Our mobile apps are less than 100 megabytes in size and run smoothly on budget phones. Many tasks that required specialized hardware just a few years ago can now be handled with the same device we carry everywhere we go.

Switching from hardware to software solutions can lead to significant cost savings in the long run. Now is the perfect time to seize this opportunity.

Developers, ready to get started?

Adding our free trial to your app is easy. Download the Scanbot SDK now and discover the power of mobile data capture