
Creating a QR Code step by step - nayuki
https://www.nayuki.io/page/creating-a-qr-code-step-by-step
======
robin_reala
A while ago I found a generator that took an image and a text and tried to use
a genetic algorithm to evolve a QR code that looked like (a 2-bit dither of)
the image. Unfortunately I’ve since lost the link, but I was quite impressed
that it managed to generate a QR code for my then-employer’s URL that looked
like their logo. Impressive what’s possible with a lot of error correction.

~~~
magnat
Here is a paper and demo describing creation of such codes:
[http://vecg.cs.ucl.ac.uk/Projects/SmartGeometry/halftone_QR/...](http://vecg.cs.ucl.ac.uk/Projects/SmartGeometry/halftone_QR/halftoneQR_sigga13.html)

Sadly, original online demo doesn't work anymore, but by looking for "halftone
qr code" you'll find plenty of alternative implementations like this:
[http://jsfiddle.net/lachlan/r8qWV/](http://jsfiddle.net/lachlan/r8qWV/)

------
tln
This is fantastic.

From this, I learned that making your URLs uppercase makes for a more compact
code! The links at the bottom are great reads as well, especially:

[https://research.swtch.com/qart](https://research.swtch.com/qart)

I hope that QR codes become more widely used, now that iOS and Android both
include QR capabilities directly in the native camera apps.

~~~
dwohnitmok
Visit China to see a cornucopia of QR codes. Everything there is QR codes.
Almost all payment is done through scanning a QR code (even tiny stands by the
side of the road). Public transportation is accessed through QR codes. Adding
people on social networks is done through QR codes. Some restaurants don't
even have menus and you access their menu via a QR code (and of course pay
again through the same). QR codes everywhere.

~~~
nayuki
Ironically in China the popular name for QR Codes is 二維碼 (literally "2D
code"). This is disappointing because there are other types of 2D barcodes
(Data Matrix, Aztec, PDF417, etc.) and because it fails to acknowledge the QR
brand.

~~~
wholien
Isn't it more like it's calling a square a rectangle? All these codes are 2D
codes - the general public doesn't care if it's a QR Code or DataMatrix or
Aztec etc. Anyway, the Baidu Wiki [0] says QR Code is a kind of 二維碼.

[0]:
[https://baike.baidu.com/item/%E4%BA%8C%E7%BB%B4%E7%A0%81/238...](https://baike.baidu.com/item/%E4%BA%8C%E7%BB%B4%E7%A0%81/2385673)

------
0898
A guy I know ran IT for a London borough's libraries. Part of his job was to
generate QR codes to go on various posters, stands and literature. He
generated hundreds of them.

Recently, he checked how many times they'd been scanned by a member of the
public.

It was zero.

~~~
tomwilson
It’s weird how in China QR codes are basically ubiquitous and yet the rest of
the world basically ignores them. The difference as far as I can tell is
WeChat, which basically everyone has, has great QR code support built in

iOS has great integration built in now to the camera app which should help,
but android is still spotty.

~~~
otachack
Android is terrible. The best thing to do is piggy back zebra crossing's open
source app and integrate it directly into the app. But as for a general use
scanner, Android still depends on the user to download a external app.
Motorola has it built into their camera app but I feel users don't know and
don't reach out for it on reflex.

Google has their own solution but it is the stupidest, roundabout way of using
it where the host app has to dynamically download the library that has the
necessary barcode scanning.

~~~
Severian
Hmm, interesting, Moto Camera automatically detects and provides the QR code
text/info. I guess I took it for granted and thought it was stock Google photo
app.

------
rubenbe
I often use QR codes to quickly transfer long URLs etc from my PC to my phone.

In the commandline you can run "qrencode --type UTF8 -o - <text>" and get a
pure text-only QR code.

------
fit2rule
That is really a brilliant web page, and the interaction of the data and the
text is also very fascinating .. seems to have a brettvictor-like effect, I no
longer felt like I was viewing a web page but rather an interactive document
that was teaching me something technical while allowing me to explore the
subjects edge cases .. Nice!

------
classichasclass
Actually, I kind of hoped he _would_ show the computation of the Reed-Solomon
codes, or at least had a popout for it if it would have made the page too
long.

~~~
akalin
You might be interested in [https://www.akalin.com/intro-erasure-
codes](https://www.akalin.com/intro-erasure-codes)

~~~
classichasclass
Ah, excellent. Thank you both.

------
luisrudge
Thanks amazing. Thanks! I always wondered how companies create their own type
of QR-code. Anyone has any idea how something like this can be built?
[https://i.imgur.com/wtxZDdh.png](https://i.imgur.com/wtxZDdh.png)

~~~
xhruso00
Messenger codes: [https://itunes.apple.com/us/app/scan-code-editor-for-
messeng...](https://itunes.apple.com/us/app/scan-code-editor-for-messenger-
codes/id1148316864?mt=12)

~~~
luisrudge
I’m wondering how can I build a custom qr code like those for my own project,
but thanks for the link

~~~
ribasushi
[https://research.swtch.com/qr/draw](https://research.swtch.com/qr/draw)

------
tazard
Thanks! That was really interesting. This is the first time I have found the
processes broken down in a way I can easily follow

------
lisper
Awesome!

Now, how do I _read_ a QR code?

~~~
nayuki
See:
[https://www.reddit.com/r/programming/comments/9th8a7/creatin...](https://www.reddit.com/r/programming/comments/9th8a7/creating_a_qr_code_step_by_step/e8x20ck/)
;
[https://www.youtube.com/watch?v=KA8hDldvfv0](https://www.youtube.com/watch?v=KA8hDldvfv0)

~~~
lisper
Yeah, that's not quite what I meant. Once I have the QR-code's pixel map,
decoding that is easy. What I don't know how to do is to recover the pixel map
from an image without knowing the scale, orientation, and viewing angle.

~~~
tekromancr
I think that's the purpose of the finder patterns.

From a Source image I imagine you would locate the finders, find the edges,
unskew the source image, and use the finders to correct the rotational
orientation, and then crop the image. Maybe binarize the new image to make the
next step easier.

At that point, it's a matter of working out the size of each cell to generate
a grid to drop on top of the image. Then you can sample each cell of the grid.
If it's light, 1. If it's dark 0. Now you have the pixel map.

I am sure it's more complex, but I think a lot of this sounds like stuff you
could do with openCV

~~~
lisper
Yes. Obviously. If you know where the finders are everything else is easy. But
how do you locate the finders?

~~~
ynniv
[http://dsynflo.blogspot.com/2014/10/opencv-qr-code-
detection...](http://dsynflo.blogspot.com/2014/10/opencv-qr-code-detection-
and-extraction.html)

~~~
lisper
Thanks!

