Many companies often add their logo to the QR code for commercial purposes. However, if the logo block area is large enough, the QR code Becomes unrecognizable. Is there a way to "empty" the above area in advance (to specifically place the logo), while other areas are dedicated to placing the valid data of the QR code? -- This is the question to be discussed in this article.
This article focuses on the advanced application and improvement of QR codes. The main idea isImprove the QR code generation in advance through mask and other means.
Because QR codes are usually black and white blocks and cannot be directly identified by human eyes, many companies are happy to add their logo to the QR codes for commercial and promotional purposes, to facilitate direct identification.
For ease of understanding, compare the following two figures:
Figure 1 color QR code without logo 2 color QR code with logo
However, once the logo is added to the QR code, especially when the logo is conspicuous enough to block the QR code and affect its identification, the problem arises. The two-dimensional code area covered by the logo is identified.
Figure 3 area of the QR code covered by the logo
We can imagine that if the logo block area is large enough, the QR code will become unrecognizable. Is there a way to "empty" the above area in advance (to specifically place the logo), while other areas are dedicated to placing the valid data of the QR code? -- This is the question to be discussed in this article.
As we all know, in order to increase the reliability of QR code reading, it is best to arrange the dark and light color modules in a balanced manner. Avoid the occurrence of Bitmap 1011101 similar to the position detection image in other areas of the symbol as much as possible.
To meet the above conditions, the mask should be performed as follows:
1) The mask is not used for functional graphics;
2) use multiple matrix images to continuously perform XOR operations on the module images in known encoding regions (except for format and version information. The XOR operation places the module images in the form of each hidden image in sequence, and reverse the modules corresponding to the hidden module (the light color turns to the dark color, or the opposite );
3) partial scores for each result graph to evaluate these results;
4) Select the image with the lowest score.
The following table provides the reference (Binary reference placed in the format information) and the condition for generating the form. A masking chart is generated by defining the modules whose conditions in the Encoding Area (excluding those reserved for the format information and version information) as a dark color. In the conditions shown in, I represents the row position of the module, j Represents the column position of the module, and (I, j) = (0, 0) represents the position in the upper left corner of the symbol.
Figure 4 masking chart reference and conditions
Figure 5 qrcode's eight mask schemes
Figure 6 mask result (all the mask shapes of version 1 Symbols, refer to the mask results from 111 to with the mask shapes ).
Mask process:
Figure 7 mask process of the symbol
These mask schemes feature a uniform geometric distribution of black spots and white spots. After they are different from the original pattern or operated, the image after the mask will significantly improve the original image and facilitate better identification.
Penalty score:
After each mask image is used in sequence, you must take a penalty score for each of the following situations to evaluate each result. The higher the score, the more unavailable the result is. In the following table, N1 to N4 are the weights of scores penalized for bad features (n1 = 3, n2 = 3, N3 = 40, N4 = 10 ), I is the number of times that the number of identical modules is greater than 5, and K is the ratio of the symbol dark module to 50%. The step size is 5%. Although the mask operation only applies to the encoding area, excluding the format information, the evaluation is based on the entire symbol.
Finally, the mask image with the lowest penalty score in the mask result should be used for the symbol mask.
Figure 8 penalty Score Table
From the table above, we can see that the penalty score method has a certain level of human nature, especially from N1 to N4, which is the weight of the penalty score for bad features (n1 = 3, n2 = 3, N3 = 40, n4 = 10 ). Some people use the variance in statistics to solve this general problem. The method is to calculate the black spots and white points of each small block. If the difference is greater than the expected average distribution value, the more unavailable it is. The more samples the system samples, the smaller the Sampling window, and the more accurate the obtained data. The calculation results are compared based on the average variance of the above eight mask schemes, and the optimal mask is selected.
Similar to this:
Double comparevariance (bool [] [] matrix)
{
Int S = 0;
For (INT I = 0; I <matrix. length; I ++)
For (Int J = 0; j <matrix [0]. length; I ++)
If (! (Matrix [I] [J] ^ matrix [I] [J + 1]) s ++;
For (Int J = 0; j <matrix [0]. length; I ++)
For (INT I = 0; I <matrix. length; I ++)
If (! (Matrix [I] [J] ^ matrix [I] [J + 1]) s ++;
Double S = s/(2n (n-1 ));
Return S;
}
In order to achieve the above goals described in this article, we will improve the QR code generation scheme before implementing the mask, and reserve a specific location for the logo in advance as needed.
First, let's take a look at the symbol character area of the QR code, and then look at its encoding process.
Qrcode structure:
Figure 9 Structure of qrcode
Represents the character area of the QR code:
Figure 10 character area distribution of 2-M characters in version 10
Figure 11 symbol character layout of the 7-H symbol
We can see from the above that there are error correction blocks and data blocks in the character area distribution.
Let's look at the coding process:
Step 1 Data Analysis
Analyze the input data streams and determine the types of characters to be encoded. QR codes support extended interpretation and can be encoded for data different from the default character set. QR codes include several different modes (ECI, numbers, letters and numbers, 8-bit bytes, Japanese characters, Chinese characters, hybrid, structural links, fnc1 mode, etc ), in order to efficiently convert different character subsets into symbolic characters. If necessary, data can be converted between modes to be binary strings more efficiently.
Select the expected error detection and rectification level. If you do not specify the symbolic version, select the smallest version that is compatible with the data.
Step 2 Data Encoding
The data character is converted to a bitstream according to the defined rules in the adopted mode. When mode conversion is required, add a mode indicator before the start of the new mode segment to perform mode conversion. Add a terminator after the data sequence. The bitstream is divided into eight bitwise code words. If necessary, add a fill character to fill in the number of data characters required by the version.
Step 1 Error Correction Code
The code sequence is segmented as needed to generate corresponding error correction code by block, and add it to the back of the corresponding data code sequence.
Step 2 construct final information
Add the data and Error Correction Code in each part according to the relevant standard steps, and add the remaining bit if necessary.
Step 2: deploy modules in the Matrix
Put the image search image, separator, positioning image, and correction image together with the code module into a matrix.
Step 2 mask
In turn, the masking chart is used for the symbol Encoding Area. Evaluate the results, and select the results that optimize the ratio of the dark color modules and minimize the number of unwanted images.
Step 1: Format and version information
Generate format and version information (if used) to form a symbol.
(Writing, not finished)