Abstract: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.
In view of the long length, please refer to the following:
Qrcode two-dimensional code generation scheme and its application in logo-type two-dimensional code (2) http://blog.csdn.net/johnsuna/article/details/8525743