I decided to do a QR code just for the fun and learning how QR code algorithm works. QR Code usage is widespread in many countries (China and South Asia) . You can use it for almost anything such as doing a financial transaction, purchasing your fruits (or anything) , URL or sending a message. The scope of usage is up to our imagination.
This is my QR Code generator project over the weekend
QR code (abbreviated from Quick Response code) is a two dimensional barcode or matrix barcode implemented by Masahiro Hara and his team (under Denso Wave) in 1994. In practice, QR codes often contain data for identifier or tracker that points to a website or application. A QR code uses four standardized encoding modes (numeric, alphanumeric, byte/binary and kanji and kanji) to store data efficiently; extensions may also be used.
QR Code Pictorial Information
The picture above shows the version 7. The algorithm is made up of two different stages.
The first stage is where the matrix gets transformed in limited shape to real or tridiagonal / Hessenberg form. This subsequent stage prepares the actual iterations of Hessenberg / Tridiagonal matrix. You can see from the above image that this resulted in alignment and cells.
Implementation
In most algorithm implementation , they go through this 4 general process
- Data Analysis — the QR standard has 4 modes of encoding text — numeric , alphanumeric , byte and Kanji. Each mode encodes the text as a string of bits. but each mode uses a different method for converting the text into bits and each encoding method is optimized to encode the data with shortest possible string of bits. The first step is the analyse which mode it is most optimal
- Data Encoding — After selecting the encoding mode, the next step is to encode the text into a string of bits that is split up into data codewords that are each 8 bits long
- Error Correction Coding — This process will use the string of data bits to generate error correction codewords using Reed-Solomon error correction. This is to ensure that the scanner can determine if the data is correct by comparing the data codewords and error correction codewords.
- Structure Final Message — The data and error correction codewords are arranged in proper order in blocks and those blocks must adhere to QR code specification
- Module Placement in Matrix — This step will place the order of step 4 into the QR code matrix in a specific way. The algorithm will place the patterns that are common in all QR codes such as the boxes in the three corners as dictate in the matrix specification.
- Data Masking — Some patterns in QR code matrix make it difficult to read the code, so the algorithm will determine which mask patterns result in the least undesirable traits by altering the QR code according to a particular pattern. The final matrix will be the one with the lowest penalty score
- Format and Version Information — This is optional but version information is added to QR code . The format pixels contain information such as versioning and mask pattern.
Amount of Data Capacity in QR code (Numeric / Alphanumeric / Binary)
Limitations
- The limitation for QR code is that the first stage create a fill-in sparse matrices which resulted in massive memory usage.
- It is for short string such as 2900–7000 characters depending on the mode. You cannot use it to send long message either.
Advantages
A two dimension (or 2D) barcode have several distinct advantages
- More information
- Fewer errors in barcode — no duplication of information to guard against a code being misprinted or damaged. It make built-in error checking systems faster.
- Easier to read — no special equipment needed. It can be read by in built camera such as mobile phones.
- It can be transmitted easily via sms
- More secure than traditional barcode. QR Code can be encrypted
Features of QR code
- Capable of reading Chinese and Japanese encordings as fast as English characters
- Able to read in any direction as they are 2D matrix
- High data encoding capacity
If you want to implement it from scratch, you will first have to understand ISO/IEC 18004:2000(E) for encoding and decoding.
If you do not want to implement on your own, there are hundred of QR Code libraries. A search in node will comes out to more than 10 QR Code libraries. Similarly in other language , there should be QR Code libraries.
A quick search yield more than 30 QR code libraries
Hence you are spoilt for choices for QR Code libraries. Otherwise just do like what I do — for the fun and learning behind the algorithm.
Posted originally in here : https://www.linkedin.com/pulse/qr-code-demystify-ivan-tay/
References
Yarden : QR Code Algorithm (2014). http://blog.visualead.com/qr-code-algorithm/
Keng T. Tan, Hiroko Kato, Douglas Chai. Barcodes for Mobile Devices by Cambridge University Press (2010). A good, basic introduction to 2D barcodes.
QR-Code Tutorial by Tonkey . https://www.thonky.com/qr-code-tutorial/introduction
Taylor : QR Code Limitation . http://qrcode.meetheed.com/technical.html
Deso Wave . https://www.denso-wave.com/