How to scan an inverted barcode

Kevin July 30, 2024 3 mins read
app store

❓ How does a barcode scanner recognize that a barcode is inverted (i.e., white bars and black spaces) and still scan it accurately?

Answer

tl;dr: The quiet zone around a barcode lets scanners tell whether it’s inverted. Camera-based scanners can also use the start and stop patterns in 1D barcodes and the finder patterns in 2D barcodes. They then invert it again to arrive at a non-inverted version and decode that. Laser scanners cannot read them.

Long answer:

Take a look at the following barcodes. Can you guess which one is the original, and which is the inverted version?

Without trying to decode both the inverted and non-inverted version, it’s just as difficult for a barcode scanner to know the difference in advance. But there are some things it can check.

That’s because barcodes don’t just encode the values to be read out by a scanner, but also provide additional information that makes it easier to do so.

If you look at the top barcode (the original), there are three black bars with three white spaces on the left. On the right, there are four black bars and three white spaces. These constitute the code’s start and stop pattern, respectively.

These patterns tell the barcode scanner where the main data begins and ends. They are missing in the inverted version, so at least there’s no risk of a false positive. But if you’re using a traditional laser scanner, the scan will just fail, and there’s nothing more you can do.

A camera-based barcode scanner can go further, thanks to its image processing capabilities. For example, it can look at the barcode’s quiet zone (a blank area around the barcode that helps scanners locate it). If it’s black instead of white, that’s a tell-tale sign that the barcode is inverted.

In the version above, this border area is missing. The following inverted barcode has a proper black quiet zone, and camera scanners will have no trouble reading it:

Inverted Code 128 with quiet zone

With 2D barcodes, detecting inverted codes is much easier, since they feature prominent identification markers that are easily recognizable as inverted.

Uninverted QR code
Inverted QR code

Some scanning software instead offers an “inverted mode” to speed up scans of inverted barcodes. This mode simply inverts the camera input, creating a non-inverted version of the barcode for the software to process. 

This approach depends on users selecting the correct mode. However, they may not even be aware that they are scanning an inverted barcode. Having the software automatically detect inversion is usually better.

Since inverted barcodes are often used on product packaging or marketing materials to better mesh with the overall design, as well as in industries like manufacturing, a barcode scanner has to be able to read inverted barcodes. That’s why we train the machine-learning model powering our Barcode Scanner SDK on all kinds of barcode variations, including inverted ones. There is no need to switch to a different scanning mode – the SDK automatically picks the best way to scan.If you’d like to try it out on the barcode examples in this article, feel free to download our demo app and give it a go!