Eli5: how do QR codes work


QR codes have revolutionised how we share information. How does QR code work and what does the scanner scan in this scenario

In: 0

So simple answer the black and and white blocks represent binary black is on and white is off

There is also the larger blocks with the white centre which the scanner uses to determine the size of the qr aswel as the orientation so that no matter how stretched or tilted it is it will know how to read it.

This is how i understood the functionality when i was looking into making my own kind of qr.

QR codes use black and white squares to represent the 1s and 0s of binary information. The large squares in the corners (and sometimes along the edges) tell the scanner which way is “up” for the code, and a repeating pattern of “10” close to the top and side of the code (even with the bottom edge of the squares across the top, even with the right side of the squares along the lefthand side) tell the scanner how big the individual small squares are. There’s other information contained within the code to tell the scanner what version the code is in. After that, the scanner reads the code itself and follows whatever instructions are built into the code (usually a web address). Part of the code is actual information, and part of it is error correcting code (there’s an *awful* lot of math involved) in case part of the code itself is damaged.

It’s a good deal more complicated than that, but that’s the ELI5 version. If you want more details, the [wikipedia page](https://en.wikipedia.org/wiki/QR_code) does a good job of giving the history and linking to the actual standards of the codes being used.

A QR code is just a 2D version of the barcodes you see on pricetags for items at the supermarket.

Computer cameras are *bad* at reading complex things like text. They’re improving, but still nowhere near a point where you can let a text detection program loose on millions of random people, let them point their crummy phone cameras at some text in awful lighting conditions at strange angles and get consistently correct results. We want something that computers can read now, accurately, quickly, and consistently, in a wide variety of bad photo conditions.

If a computer is good at discerning anything in pictures, it’s noticing the difference between bright and dark spots. It’s just not that great at discerning the thin, swoopy curves of printed text. So instead of text, we write out alternating black and white blobs that encode information in a sort-of Morse code. Instead of dot-dot-dash you get light-light-dark, etc. To be clear, it is not actual Morse code, I’m only bringing up the comparison to demonstrate how alternating light and dark patches can store data.

Bar codes on price tags are an extremely simple use for this idea. The tall bars give the scanner lots of wiggle room to see them, you can twist the little scanner laser to nearly any angle and still get a reading. The bars at the two ends are special, and tell the scanner which side is the start and which side is the end. This allows the scanner to read bar codes even if they are upside-down–if the start and stop ends are flipped the wrong way, the scanner will simply read it backwards. It then proceeds to read the light and dark patches in order, like you’d read words on a page, to decode the message. For a bar code, it’s almost certainly the product ID number of the item you’re buying. The digits tend to be printed below the bars for humans to read.

If reading a barcode was like reading a one-line sentence, then a QR code is like reading a full book page. The QR code is basically many, many barcodes stacked on top of each other that are all read together, just like a book page is many, many sentences stacked on top of one another and all read together. The funny squares in the corners tell the camera which way is up, so just like a barcode you can read QR codes rotated any which way. It then reads the dot pattern like you’d read a book page, scanning left-to-right first and moving down one line at a time (I think QR codes actually do it exactly backwards from that, but that’s aside the point). The data stored in most QR codes you see tend to be website links, written exactly as you’d type them yourself in the address bar. But QR codes can store essentially whatever data you like. Just not a whole lot of it.