Main menu

QR Codes

You are probably familiar with images like the one on the right, which shows a QR code (QR is short for Quick Response). These codes are becoming more and more common, and can be found on business cards, ads, historical buildings, T-shirts, etc. You're meant to scan them using your smartphone (I use Barcode Scanner on an Android phone). They can contain all sorts of information, the most common being plain text, URLs, and contact information (e.g., in the form of a vCard). The information is in the code itself, the code is not a link into some vast database on the internet or something.

QR codes are an example of so-called matrix barcodes, which are a two dimensional alternative to the well-known “striped” barcodes. The example encodes the URL for this website. Because they are two dimensional, QR codes have a higher information density than traditional barcodes, which means that they can store more information on a given surface area.

Structure

QR code structure.

Apart from the seemingly “random” pixels, which encode the actual information, each code has a number of fixed elements. The example QR code is shown again on the right, with the important structural elements highlighted in different colors.

The three large indicators in red tell the scanner what the basic position of the QR code is. The three indicators together form a right-angled triangle. The scanner can use this information to determine the exact orientation of the QR code, even when the code is not scanned from a perpendicular angle. The smaller indicator in blue enables the scanner to align the image further. There is only one alignment indicator in this small QR code, but there are more in larger ones. You could easily miss the lines of alternating black and white pixels that are highlighted in yellow. These lines form a coordinate reference to determine the location of the rest of the symbols. Finally, the area highlighted in green must be kept empty, to avoid confusing the scanner.

The final building block of QR codes is the error correction mechanism, using the nifty Reed-Solomon encoding. Explaining Reed-Solomon error correction would require a separate article, I'll just mention here that this technique is really used a lot, for example on CDs and for satellite communications.