Two-dimensional code (QR code) basic structure and generation principle

Source: Internet
Author: User

What is a QR code

A QR code (2-dimensional bar code) is a black-and-white graphic that distributes data symbols in a plane (two-dimensional direction) by a certain geometry.

In many kinds of two-dimensional barcode, the commonly used code system is: Data Matrix, Maxi code, Aztec, QR Code, Vericode, PDF417, Ultracode, code, code 16K, and so on.

Two-dimensional barcode/Two-D code can be divided into stacked/row-type two-dimensional barcode and matrix two-dimensional barcode.

1. Stacked/row-type two-dimensional bar code, stacked/row-type two-dimensional bar code is also known as stacked two-dimensional bar code or layer of two-dimensional bar code, the coding principle is based on a one-dimensional bar code, as needed to accumulate into two lines or more lines. It inherits some features of one-dimensional barcode in coding design, calibration principle and reading mode, and is compatible with barcode printing and one-dimensional barcode technology. However, due to the increase of the number of rows, it is necessary to determine the line, and its decoding algorithm and software are not exactly the same as the one-dimensional barcode. A representative row of two-dimensional bar codes are: Code 16K, Code 49, PDF417, MicroPDF417 and so on.

2. Matrix Two-dimensional code, the most popular is the QR code, we often say that the QR code is it. Matrix Two-dimensional barcode (also known as checkerboard two-dimensional barcode) It is encoded in a rectangular space by the different distributions of black and white pixels in the matrix. In the position of the corresponding element of the matrix, the occurrence of the point (square point, dot, or other shape) represents the binary "1", the point does not appear to represent the binary "0", the arrangement of the points to determine the matrix of two-dimensional bar code represents the meaning. Matrix Two-dimensional barcode is a new type of graphic symbol automatic reading and processing system based on computer image processing technology and combinatorial coding principle. The representative matrix two-dimensional barcode has: code one, Maxicode, QR code, Data Matrix, Han Xin code, Grid matrix and so on.

The application of QR code in the real life is more and more common because of the popularity of the code, QR code.

Features of the QR code

1. Storing Large capacity information

Traditional barcodes can handle only about 20 bits of information, compared to a QR code that handles dozens of times times as much as hundreds of times times the amount of information in barcodes.

In addition, the QR code can support all types of data. (such as: numbers, English letters, Japanese letters, Chinese characters, symbols, binary, control codes, etc.). A QR code can handle up to 7089 words (with only numbers) of huge amounts of information.

2. Print within a small space

QR code uses vertical and horizontal two directions to process data, if the same amount of information, the QR code occupies about one-tenth of the barcode. (micro QR Codes are also supported to process data in a smaller space.) )

3. Effective expression of various letters

The QR code is a Japanese-made two-dimensional code, which makes it ideal for processing Japanese letters and kanji. QR Code set specifications are defined in accordance with the Japanese standard "JIS first and second level of Chinese characters", so in Japanese processing, each full-width letter and Chinese characters are 13 bits of data processing, high efficiency, compared with other two-dimensional code, can store more than 20% of the information.

4. Strong adaptability to fouling and breakage

The QR code has an "error correction function" that restores data even if some of the codes become dirty or damaged. Data recovery in code word units (is composed of internal data units, in the case of the QR code, each 8-bit represents 1 code word), up to 30% error correction (depending on the degree of fouling and breakage, there is also unrecoverable situation).

5. Can read from any direction

QR codes can be read quickly from any direction in the 360°. The mystery lies in the QR code of 3 positioning patterns, can help the QR code is not affected by the background style, to achieve fast and stable reading.

6. Support Data Merge function

QR codes can divide data into multiple encodings and support up to 16 QR codes. With this feature, you can also print a QR code in a narrow area. Alternatively, you can combine multiple split encodings into a single data.

Information and version of QR code

QR codes are available in different versions from 1 to 40 (types), each with an inherent code structure (number of code elements). (code element refers to the square black and white dots that make up the QR code.) )

"CODE element Structure" refers to the number of code elements in two-dimensional code. Starting from version 1 (21 yards x21 code Element), in portrait and landscape respectively in 4 yards increments, until version 40 (177 yards x177 code element).

Each version of the QR code combines data volume, character type, and error correction level, with the corresponding maximum number of input characters. In other words, if you increase the amount of data, you need to use more code elements to form a QR code, the QR code will become larger.

For example, if you need to enter a 100-bit number, use the following procedure to select it.
1. Suppose the type of data to be entered is "number"
2. Select the error correction level from "L" "M" "Q" "H". (Suppose "M" is selected)
3. Look at the table below, first from the number column to find the number of 100 and close to 100, followed by the error correction level "M", the two parts of the intersection is the best version.

The calculation method for the total number of bits is calculated for each character type by the following calculation.


Error correction of QR code

QR Code has "error correction function". Automatically recovers data even if the code becomes dirty or damaged. This "error correction capability" is available in 4 levels, and users can choose the appropriate level based on the environment they use. Increase the level, the error correction ability is correspondingly improved, but because the data volume will increase, the coding size will also become larger.
Users should consider the use of environment, coding size and other factors after selecting the appropriate level. In the factory, such as easy to contaminate the environment, can choose the level Q or H, in a less dirty environment, and the amount of data, you can also choose the level L. In general, most users choose a level of M (15%).


The ratio of error-correcting levels is the ratio of all code words to code words that can be corrected.
For example, there are 100 code word data that need to be encoded, and you want to correct half of them, that is, 50 code words, the calculation method is as follows. Error correction requires a symbol equivalent to twice times the code word (RS code ※), so in this case the number is 50 x2=100 code word. Therefore, the total number of code word is 200, which is used as error correction code word is 50, so calculated, relative to all code Word error correction rate is 25%. This ratio is equivalent to the "Q" level in the QR Code error correction level.

In addition, in the above example, it can be considered that the error rate is 50% relative to the code-word data, but the dirty or damaged parts are not limited to the code-Word data part, so in the QR code, or the relative to the full code word ratio to describe the error correction rate.

※RS encoding: The error correction function of a QR code is achieved by attaching RS encoding to the original data. RS encoding is a mathematical error correction method used in music CDs and other applications. It can be corrected in bytes and is suitable for burst errors where the error location will be concentrated.

Types of QR Codes

Basic structure of QR code

QR (Quick-response) code is widely used in a two-dimensional code, decoding speed fast. It can store multi-use types and is the basic structure of QRCode:

Position detection graphics, position detection graphics separators, positioning graphics: for the two-dimensional code positioning, for each QR code, the location is fixed existence, but the size of the specification will be different;
Correction Graphics: The specification determines the number and position of the corrected graph;
Format information: Indicates the error correction level of the two-dimensional code, divided into L, M, Q, H;

Version information: That is, two-dimensional code specifications, QR code symbols have a total of 40 specifications of the matrix (generally black and white), from 21x21 (version 1), to 177x177 (version 40), each version of the symbol than the previous version of each side of the addition of 4 modules.

Data and Error correction code word: The actual saved QR code information, and error correction code word (for correcting the errors caused by the two-dimensional code corruption).

encoding process of QR code

Here is a brief QR coding process:

1. Data analysis: Determine the encoded character type, converted to a symbolic character by the corresponding character set, select the error-correcting level, the higher the error-correcting level, the smaller the capacity of the real data under the condition of certain specification.

2. Data encoding: Convert data characters to bit streams, each 8 bits of a code word, the whole form a code sequence of data. Actually know this data code word sequence to know the data content of the two-dimensional code.

The capacity is as follows:

Format capacity
Numbers up to 7089 characters
Letters up to 4296 characters
Binary number (8 bit) up to 2953 bytes
Kanji/Katakana up to 1817 characters (with shift JIS)
Chinese characters up to 984 characters (with UTF-8)
Chinese characters up to 1800 characters (with BIG5)

The pattern code is as follows:

Pattern indicator
ECI0111
Number 0001
Alpha-Numeric 0010
8-bit byte 0100
Japanese Kanji 1000
Chinese characters 1101
Structure Link 0011
FNCI0101 (first position)
1001 (second position)
Terminator (end of message) 0000


Data can be encoded in a pattern for more efficient decoding, for example: 01234567 encoding (version 1-h) for data:
1) Group: 012 345 67
2) turn into binary:
012→0000001100
345→0101011001
67→1000011
3) turn into sequence: 0000001100 0101011001 1000011
4) Number of characters turn into binary: 8→0000001000
5) Add mode indicator (digital) 0001:0001 0000001000 0000001100 0101011001 1000011

For letters, Chinese, Japanese, and so on only the way of grouping, mode and other content is different. The basic method is consistent.

3. Error-Correcting code: According to the need to block the above code word sequence, and according to the error correction level and block code word, generate error correction code word, and the error correction code word added to the data code word sequence behind, become a new sequence.

Error correction level
l7% loadline Correction
m15% loadline Correction
q25% loadline Correction
h30% loadline Correction


In the case of two-dimensional code and error correction level, in fact, it can accommodate the total number of code and error correction code Word count is also determined, such as: Version 10, error correction level H, a total capacity of 346 code words, of which 224 error correction code word.

This means that about 1/3 of the code word in the QR code area is redundant. For these 224 error correcting code words, it can correct 112 substitution errors (such as black and white upside down) or 224 read errors (unreadable or unable to decode), so that the error correction capacity is: 112/346=32.4%.

4. Construction of final data information: In the specification of the conditions, the above-generated sequence is placed in the order of the block.

According to the provisions of the data block, and then the calculation of each block, the corresponding error-correcting code block, the error-correcting code word block in order to form a sequence, added to the original data code word sequence behind.
such as: D1, D12, D23, D35, D2, D13, D24, D36, ... D11, D22, D33, D45, D34, D46, E1, E23,e45, E67, E2, E24, E46, E68, ...

5. Construct the matrix: The probe graphics, separators, positioning graphics, correction graphics and code word module into the matrix.

Fill the entire sequence above into the area of the corresponding specification's QR code matrix.

6. Masking: The mask graphic is used for the coded area of the symbol, so that the dark and light (black and white) areas in the two-dimensional code graph can be optimally distributed.

7. Format and version information: Generate format and version information into the appropriate area.

Version 7-40 contains version information, and no version information is all 0. The two locations on the QR code contain the version information, which is redundant.

Version information A total of 18 bits, the 6x3 matrix, where 6 bits when the data is, such as version number 8, data bits of information when 001000, followed by 12 bits is corrected dislocation.

Application of QR Code

The QR code can be easily applied to a variety of occasions. In addition to printed material such as flyers and business cards, it can be used in a wide range of areas, such as settlement systems, and in various commercial areas such as factories and circulation. QR codes have become an indispensable tool in everyday life. In 2012, the Japan Design Revitalization Association of the Public Welfare Foundation has highly appraised the QR code, because the function of QR code is very close to life, the design is exquisite, and the QR Code "Excellent Design Award" is awarded in its design recommendation system.

Standardization of QR Codes

"Want more people to use QR Code", adhering to this concept, DENSO wave full disclosure of the relevant standards of the QR code. QR codes are now standardized in national and international standards and can be viewed by anyone.

※denso WAVE Incorporated has announced that the company will not be the standard QR code of the patent (patent number No. 2938338).

October 1997 Adopted as AIM International (International automatic Identification Industry Council) standard (ISS-QR Code)
March 1998 Adopted as JEIDA (Japan Electronics Industry Promotion Association) standard (JEIDA-55)
January 1999 adopted as JIS (Japanese industry standard) (JIS X 0510)
June 2000 adopted as ISO International Standard (ISO/IEC18004)
November 2004 Micro QR Code was adopted as JIS (Japanese industry standard) (JIS X 0510)
December 2011 ISO GS1 The adoption of QR codes as a standard for mobile terminals

A brief standard for QR codes


QR code standard file download

QR codes are standardized in ISO (iso/iec18004). Therefore, please purchase the QR Code standard file from the website of the following group, search 18004 in the following URL.

Http://www.iso.ch/iso/en/prods-services/ISOstore/store.html

However, the 2016 standard version of the price is slightly more expensive, you can download to my Resources 2006 standard version, the link is as follows:

http://download.csdn.net/detail/u012611878/9687105

In addition, here is a C + + written QRCode codec tool, based on the Zxing encoding library, Libqrcode decoding library, through the command line to complete the two-dimensional code image and text between the conversion, the link is as follows:

http://download.csdn.net/detail/u012611878/9705048

Welcome to the Cubs.


---------------------
Machinechen
Source: CSDN
Original: 53167009?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!

Two-dimensional code (QR code) basic structure and generation principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.