Decoding small QR codes by hand (2012)
blog.qartis.com
blog.qartis.com
I see a lot of cutesy QR codes out there that include a logo in the center.
These are basically intentionally damaged and depend on error correction to recover the missing bits that are covered by the logo.
> Instead of scribbling on redundant pieces and relying on error correction to preserve the meaning, we can engineer the encoded values to create the picture in a code with no inherent errors
But as another commenter noted, this likely increases the scan time required.
Then the uncontrollable pixels can be hidden in areas of the image which would normally be grey, with the uncontrollable bits error contribution passed onwards to the controllable regions of the image.
WTF PEOPLE ARE NOT PUTTING A CLEAR TEXT URL NEXT TO THE QR CRAP?!?!?
Especially when the QR code itself points to a URL shortener.
Fortunately they still print the SSID and password on the back. But it's clear that AT&T would rather you go through their telemetry portal instead.
(And then there's how the signal on it was so weak that it couldn't penetrate interior walls more than 10 meters away. But that's another story.)
I use the Privacy Friendly QR Scanner, developed by a German university research group. More info available here: https://secuso.aifb.kit.edu/english/105.php
https://kitsunesoftware.wordpress.com/2017/04/10/executable-...
Since most people don't type URLs themselves and can scan a QR code, it might not even occur to you that having the URL in plain text can be useful. It also takes space and it's not necessarily pretty.
(I do put the URL when making a visual with a QR Code, and require the URL to be there if I'm involved but not making the visual)
If a piece of an URL looks like a word, factor that into your confidence scores as well, e.g. "somefoo.com/illusion/" is far more likely to be the correct URL, especially for something printed on paper, than "somefoo.com/iIIusion/", "somefoo.com/iIlusion/", or "somefoo.com/ilIusion/"
You don't even to do a full GET request, you can just use HEAD to save on mobile bandwidth.
For URLs that are printed on paper (e.g. at a restaurant table), have the backend do this and cache the correct URLs based on geolocation.
If it doesn't have error checking and checksums, it shouldn't be relied upon by the general public.
Let's say you're at a restaurant, they have one of those stupid QR codes to view the menu (I really wish they would print the damn menus, but that's another story ...). Why not just an URL of "myrestaurant.com/menu" and you just scan that URL? Who would typo-squat an alternate menu and paste it on the restaurant tables?
If there's a venue in which typo-squatting is a potential threat, QR-squatting would be an even bigger threat because even if only 5% of people have sharp enough eyes to spot a typo squat, probably only 0.0001% of people are good at decoding QR codes in their brain and would spot a QR squat. The typo squat is easier to spot.
If you really wanted, we could also establish an optional checksum protocol for URLs e.g. http://myrestaurant.com/menu#cs=123
If the checksum fails, the phone can try (a) all possible 1-2 character edits for error correction, which should take only a couple milliseconds (b) auto-Google the URL to see if there is a fixed version of the URL (c) error out if both of the above fail.
I'm suggesting that for real life we could just use URLs and OCR instead of QR codes.
No, because that's not reliable, and way more complicated and error-prone.
It's the same reason bar codes are used instead of directly the id they code.
Your earlier solution doesn't convince me. It's interesting, but not practical, and reading the URL should work even if internet is off or the server is down.
(Having a checksum next to the URL may start making OCR practical though)
https://apps.apple.com/us/app/barcode-qr-scanner-rawcode/id1...
Happy to add any features folks might be interested in!
Here’s some feedback:
* On launch, it asks for Camera permission. I declined and the app crashed. Next launch, it opens to the blank screen with a (scan) icon and an Edit option, both on the top right. Tap on the scan icon and the app crashes. Tap on Edit and it changes to Done (there are no previous scans, obviously). It should ideally provide instructions to enable Camera permissions in the Settings app and also say why it needs it and how it’ll be used.
* The App Privacy section for your app declares that it collects usage data and diagnostic data. It would be good to know more details of what’s collected (preferably in the app description). Generally, people wouldn’t expect such a (simple use case) app to collect and transmit information (unless they explicitly ask for it to be done).
See https://secuso.aifb.kit.edu/english/105.php for that and other apps developed by that research group.
That's also why the bottom right alignment pattern is missing in the schematics. He didn't forget it, it's just not there in a v1 code.
Correct, the alignment patterns only depend on the version, not the error correction level or text encoding.
Source: I read the spec and wrote my own QR encoder library.
On a linux computer, I take a screenshot and run zbar, a cli tool available in the repositories.
Looking at this guide, it's easy to understand the steps. But I don't get how one actually would apply them in code to a picture of a QR code. How?
To determine orientation scanners look for “alignment markers”.
I think I have the general idea on how all that works, but... isn't there an official spec/algorithm on how one is supposed to do this? The devil is in the details.
Some more things to include:
- perspective correction may be needed (the surface with the QR code is not parallel to the image plane, so pixels further away get smaller)
- if the algorithm takes parameters, such as color filters / black-vs-white thresholds, try with different parameter sets in sequence. The user is pointing the camera at the code for a relatively long time, compared to the time it takes to process an image.
- pixely images should produce a recognizable pattern in the fourier transform of the image. This gives you the size AND rotation at once.
(edit: formatting)
Disclaimer: I an the author of STRICH (https://strich.io) and have dived relatively deep into the topic.
Basically the entire of subject area of electronics and signal processing exists to find clever ways to solving all the problems you mention. So for people that do for a living, there’s a huge set of standard algorithms and approaches you can apply to solve the problem of “detecting QR codes”, in the same way there’s standard approaches to sorting a list, or building a B-tree, or creating a query planner.
It’s realistically not possible to summarise the process into a HN comment, because that would require explaining decades of signal processing research in a handful of sentences.
To give a flavour for solving this problem, QR code alignment markers are designed to be easy to detect, regardless of angle or being partially obscured. Their large simple pattern means you can use crude algorithms to find all alternating back and white patterns in your image, then analyse those patterns to detect which ones are noise and which ones might be alignment markers. Stuff like the regular spacing of the alignment patterns, plus the timing strips between them, give you anchors to rapidly check if your looking at a set of actual alignment markers, or just things that happen to have the same shape as alignment markers. At which point you can start the expensive process of attempting to decode the QR data.
As for what algos to use to go from colour to greyscale, well that’s up to you to figure out. Building a crude QR code decoder is “easy” building a fast robust one is hard, and quite valuable. Nobody is gonna give you that kinda secret sauce for free, not when they can charge you for the hundreds of hours of R&D involved.
There’s an official spec for QR codes, it might even give you basic guidance on how build a very basic QR code decoder. But asking for a detailed spec on a fast robust QR decoder is like asking the IEEE for a detailed spec on how to build a 10Gbs Ethernet controller. It ain’t gonna happen, because building such a thing is hard, even once you know what signals you’re decoding.
Why is that the case?
Nobody expects a detailed tutorial, but it's hard to even come by a list of techniques that are known to work (or maybe I'm just trash at search).
But just like Reed-Solomon encoding is a very specific algorithm, with many different applications, of which QR codes is one. What you’re looking for is similar, it’s a huge set of very specific algorithms with huge set of applications, of which one is QR codes.
QR codes are simply too niche for anyone to have put together a pubic document on what exact image processing techniques you might use to decode them. If you want to teach people about 2D signal processing, then QR codes are probably not a good starting point.
I would also argue that Reed-Solomon encoding is not “deep” anything. It’s one of many different 1D signal error correction algorithms that exist. For people who work on signal processing as day job, Reed-Solomon is about as “deep” as quick-sort is to programmers.
As for why quick-sort is well documented with many open implementations, and QR codes aren’t. I would argue it’s simple due to the industry they developed in. QR codes started in manufacturing, being used for inventory management, almost certainly by embedded and electronic engineers. All of those industries pre-date the open source movement by decades, trade secrets are still important for them, so they’re not naturally inclined to share IP.
I built a similar thing for Telegram a while ago[3] for recognizing the text in the machine-readable zone of passports and ID cards. It does different things after the initial detection/transform/binarization steps, but those would be the same for a QR code reader.
[1] https://en.wikipedia.org/wiki/Hough_transform
[2] https://en.wikipedia.org/wiki/Edge_detection
[3] https://github.com/DrKLO/Telegram/blob/master/TMessagesProj/...
For those who want to go the extra step and try the error correction by hand too, this article will be useful: https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_f...
(Side note: the example image of a QR tattoo evoked slight feelings of trypophobic disgust.)
Something like "no way this one random half-row of pixels on the left and the four pixels in the bottom right have a completely different meaning than the rest of the pixels!"
Also, I figure, it would be very difficult to reconstruct the mask patterns if you don't already know the formulas in advance. Someone might be able to figure out the codes that use the simple masks, but I figure, there'd still be many "unreadable" QR codes left that use the more complex masks.
https://www.nayuki.io/page/creating-a-qr-code-step-by-step
Previously discussed here:
Here you go: https://qrlogo.kaarposoft.dk/qrdecode.html
And experience has shown that, more often than not, such hack scripts find ways to grow into mission critical services. Sure, it's an ancient Mayan qr code that is unique in the world and we just so happen to have found precise decoding instructions; but are you sure the one of the stone bits isn't just a piece of fossilized bird poo that was not present in the original? Are you sure all the stone pieces were found? are you sure no other ancient qr codes will be found in the future?
Life is too short not to automate everthing.
And like you said, it’s an excellent way to teach implementors of automated QR code readers/writers.
Would it be possible to represent the whole decode process with all options, and do it purely pictorially?
See https://en.m.wikipedia.org/wiki/Cosmic_Call which points to https://www.plover.com/misc/Dumas-Dutil/messages.pdf . Read annex B of that message.
We spent a night decoding it with minimal hints, which was reasonably easy. Basically, page 1 defines numbers as dots, binary and their own symbol set. Then they define math operations. This allows them to describe some physical and chemical relations, from which the metric system is derived. This allows them to create descriptions of physical thing which, combined with some crude graphics, let them tell about our home planet.
If that's possible, explaining qr codes should also be possible
> I am stuck decoding a qr code.... I have tried several ways. It was sent a long time ago so maybe it has expired. Any takers?
I don't think they read the post...