Skip to content

04a How it works

tei187 edited this page Aug 23, 2024 · 1 revision

...

One may say that it is easier to decode and encode the QR, saving it as vector-based image, rather than analysing the image and rebuild it without actualy encoding happening. In a way, that is true. If you do not have to keep the code exactly the same, decode/encode would make a lot of sense.

However, if you must keep the looks of the QR the same as original, it is a better idea to rebuild it basing on image analysis. Why? Due to certain things user may not be fully aware of, like using different models or error correction levels, and minor level of variability in certain edge cases.

How does it work?

  1. Standardize the image a little bit, which means applying threshold filter and trimming the white borders of the background.
  2. Find the width (or height) of the upper left corner marker. Initially, the script checks a (0,0) image position for black pixel and if found proceeds down the x-axis to find the first white square, which should signify the end of the marker. Width and height of corner markers always consists of 7 modules, therefore the length of the marker divided by 7 will give us a rough estimate of the module dimensions in the image.