Error correction encoding and decoding method, system and storage medium of a two-dimensional code
Patent Information
- Application Number
- CN202611178250.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-05
- Publication Date
- 2026-10-30
AI Technical Summary
然而,随着大数据时代的到来,海量数据的存储与传输需求不断增长,传统QR码存在的容量和空间利用率不高的问题,逐渐凸显
(1)变长RS编码优点是利用率高,纠错能力强,缺点就是计算量大,速度慢。创新使用根据数据长度来动态调整RS有限域的,再结合根据域长度,将数据按比特位切分合并的方法压缩数据,减少运算。
Smart Images

Figure CN123013987A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of QR code technology, and in particular to a QR code error correction encoding and decoding method, system, and computer-readable storage medium. Background Technology
[0002] The widely used QR code (Quick Response Code) is a type of two-dimensional code. It boasts large storage capacity, low cost, and the ability to represent various textual information such as Chinese characters and images. Its strong security and anti-counterfeiting features, coupled with its ease of use, have led to its widespread adoption across various industries. It offers advantages such as high information density and fast reading speed, resulting in its application in numerous fields. However, with the advent of the big data era and the ever-increasing demand for storing and transmitting massive amounts of data, the limitations of traditional QR codes in terms of capacity and space utilization are becoming increasingly apparent.
[0003] Traditional QR codes have low capacity and space utilization: Traditional QR codes only support a maximum of 177*177 modules, limiting data capacity. They also use fixed large positioning patterns at the three corners and multiple auxiliary positioning blocks in the middle, along with version information, occupying approximately 10%-15% of the code surface space, thus limiting space utilization. Traditional QR codes also have insufficient error correction capabilities: They use a fixed 4-level error correction code configuration, resulting in a large range of error correction redundancy and low space utilization. For long characters, they use fixed-length interleaved grouping encoding, meaning their error correction capability is only optimal under special circumstances.
[0004] QR codes use error correction algorithms to generate a series of error-correcting codewords, which are added after the data codeword sequence so that the symbols do not lose data when they are corrupted. The table below shows four error correction levels, corresponding to four error correction capacities.
[0005]
[0006] Error-correcting codewords can correct two types of errors: rejection errors (where the location of the erroneous codeword is known) and substitution errors (where the location of the erroneous codeword is unknown). A rejection error is a symbolic character that was not scanned or cannot be decoded, while a substitution error is a symbolic character that was incorrectly decoded. Because QR codes are matrix symbols, if a defect causes a dark module to become a light module or vice versa, it can incorrectly decode a symbolic character as something that appears valid but is actually a different codeword. Such data substitution errors require two error-correcting codewords to correct.
[0007] The number of correctable substitution and rejection errors is given by the following formula: e + 2t ≤ d - p; where: e = number of rejection errors, t = number of substitution errors, d = number of error correction codewords, and p = error decoding protection codewords.
[0008] For example, a version 6-H symbol contains 172 codewords, of which 112 are error-correcting codewords (the remaining 60 are data codewords). These 112 error-correcting codewords can correct 56 substitution errors or 112 rejection errors, meaning the symbol error correction capacity is 56 / 172 or 32.6%.
[0009] In the formula above, p=3 for version 1-L symbols, p=2 for version 1-M and version 2-L symbols, p=1 for version 1-H, 1-Q, and 3-L symbols, and p=0 in all other cases. When p>0 (i.e., 1, 2, or 3), p codewords are used as error detection codewords to prevent data transmission from symbols where the error exceeds the error correction capacity. e must be less than d / 2. For example, in a version 2-L symbol, the total number of codewords is 44, of which 34 are data codewords and 10 are error correction codewords. As can be seen from Table 13, the error correction capacity is 4 substitution errors (e=0). Substituting into the formula above: 0 + (2×4) = 10 - 2. This means that only 8 error correction codewords are needed to correct 4 substitution errors, and the remaining 2 error correction codewords can be used to detect (but not correct) other errors. If more than 4 substitution errors are detected, decoding fails.
[0010] Based on the version and error correction level, the data codeword sequence is divided into one or more blocks, and error correction operations are performed on each block separately. Table 13-22 lists the total number of codewords, the total number of error-corrected codewords, and the structure and number of error-corrected blocks for each version and each error correction level. If a symbol version requires remaining bits to fill the remaining modules in the symbol capacity, all remaining bits should be 0.
[0011] Therefore, it is necessary to provide a new QR code error correction encoding method, system, and medium to reduce the amount of computation. Summary of the Invention
[0012] The main objective of this invention is to provide a method, system, and computer-readable storage medium for error correction encoding and decoding of QR codes to solve the aforementioned technical problems.
[0013] To achieve the above objectives, the present invention provides an error correction encoding method for a QR code. The QR code includes a functional graphic and a data graphic. The functional graphic includes a center finder positioning graphic block of size N*N, and the data graphic includes data blocks surrounding the center finder positioning graphic block. Wherein, N=8*n1+1, M=N+8*n2, n1 is a positive integer, and n2 is a positive integer greater than or equal to 2. The central image-finding graphic block includes: a central module composed of graphics of size N1*N1 with a first brightness, the center of which coincides with the center of the QR code; a central rectangular border module of size 3N1*3N1 composed of graphics of size N1*N1 with a second brightness, concentrically arranged around the central module; a rectangular outer border module of size N*N composed of graphics of size N1*N1 with a second brightness, concentrically arranged around the central module; a rectangular corner module composed of graphics of size aN1*bN1 with a second brightness, located at one inner corner of the rectangular outer border module; and a large square of first brightness, filled with graphics of size N1*N1 with a first brightness, surrounding the rectangular outer border module; wherein, N1+aN1+N1≤(N-1) / 2, N1+bN1+N1≤N / 2, a and b are integers greater than or equal to 1, and a≠b; The data graphic includes multiple codewords arranged in the region of the data graphic according to the arrangement order corresponding to the version information. Each codeword includes 8*n3 characters, where n3 is a positive integer. The characters are arranged in the codeword according to a preset compilation order. Including the following steps: S1, Obtain the data to be encoded, and calculate the version number and length information of the smallest module of the QR code data graphic based on the length of the data to be encoded, the version information of the QR code to be encoded, and the error correction level. S2, calculate RS error-corrected data based on the data to be encoded, version number, length information, and error correction level; including: S21, select either variable-length RS encoding or block interleaved RS encoding method based on the data to be encoded, version number, and length information; S221, when selecting variable-length RS coding, select an appropriate Galois field (GF) space operation according to the data length, perform error correction coding, and calculate RS error correction data; S222, when selecting group interleaved RS coding, performs error correction coding in the 8-bit GF field and calculates RS error correction data; S223, the length information, the data to be encoded, and the RS error correction data are concatenated to form the data to be filled; S23, Based on the QR code version information to be encoded, draw the functional graphic of the QR code, and fill the data to be filled into the data graphic of the QR code.
[0014] Preferably, the method further includes step S32, which involves performing an XOR operation on the binary representation of the data to be filled and the mask pattern data to obtain new data to be filled.
[0015] Preferably, step S221 includes: Calculate the number of bits in the data to be encoded and the number of bits occupied by the error correction data, and add them together to get the total number of data bits; Based on the total number of bits, find the smallest number of bits B in the Galois field; Based on the number of bits B in the Galois field, the original data is concatenated into a new dataset P by B bits; The new dataset P is used to obtain the error-corrected data E through the RS algorithm with a bit depth of B. Step S223 includes: concatenating P and E to form the data O to be written.
[0016] Preferably, step S222 includes: Based on the original data length and error correction level, the optimal GF space N and error correction number E are selected from 200 to 255 according to the principle of optimal capacity. The effective capacity of each block is K = N - 2 * E. The original data is divided into data blocks of K bytes each, resulting in a total of U data blocks; XOR each block of data by bytes to obtain a check block X; The error correction data is obtained by performing RS(N,K) calculation on both the U block data and the check block X. Step 223 includes: After the error-corrected data is concatenated to the original data block, a new data block F (U+1) is obtained. The data is cyclically mixed and interleaved from F to form a block of data O, which is the data to be written and filled.
[0017] Preferably, it also includes the following steps: S101, the data to be processed is divided into multiple data blocks; S102, the multiple data blocks are added to multiple redundant blocks through an erasure algorithm to obtain multiple single-code data, each single-code data including one of the data to be encoded; S103, generate multiple single-code QR codes from the data to be encoded according to steps S1 to S4; S104, the multiple single-code QR codes are combined into a multi-code QR code according to the preset aspect ratio and splicing order.
[0018] The present invention also provides a QR code, which is generated using the error correction encoding method for QR codes described above.
[0019] Preferably, the first brightness is white or transparent, the second brightness is black, N1 is one of the smallest size units of the QR code, and M is 25-529; n1 is 2, a=3, b=2.
[0020] The present invention also provides an error correction and decoding system for the above-mentioned QR codes, comprising the following steps: S10, Obtain the error correction encoding mode of the QR code; S201, when the error correction coding mode of the QR code is variable-length RS coding: Calculate the maximum data capacity bits based on the code version, and find the minimum GF space bit size B. Based on the error correction level and maximum capacity, calculate the maximum length K of the original data and the length E of the redundant data; Divide the data O into B-bit segments and concatenate them to form the data N; Perform RS decoding on the data N. After successful decoding, the original data is obtained. S202, when the error correction coding mode of the QR code is block interleaved RS coding: The maximum data capacity in bytes is calculated based on the code version, and the number of error correction bytes is calculated based on the error correction level. Calculate the original number of blocks U based on the capacity; The data O to be decoded is grouped into U+1 groups to restore the data F of each group; Perform RS decoding on each data block; When all data blocks can be successfully decoded, the data block bytes are concatenated to obtain the original data bytes, and the data is directly restored. When any group of data blocks fails to decode, and the last group of check blocks X is successfully decoded, the successfully decoded group and the check group can be XORed by bytes to restore the failed data block. The data block bytes are then concatenated to obtain the original data bytes, and the data is restored.
[0021] The present invention also provides a QR code encoding and decoding system, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described in any of the preceding claims.
[0022] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described in any of the preceding claims.
[0023] In view of the shortcomings and improvement needs of the existing technology, the QR code and its decoding method provided by the present invention have at least the following advantages: (1) The advantages of variable-length RS coding are high utilization and strong error correction capability, while the disadvantages are large computation and slow speed. Innovatively, the RS finite field is dynamically adjusted according to the data length, and the data is compressed by splitting and merging the data by bit according to the field length, thus reducing the computation.
[0024] (2) The block interleaved RS coding method is similar to the QR code, and only operates in the 8-bit GF field. It is fast, but its capacity and security are slightly lower than the variable length RS code mentioned above. Compared with the QR code, the addition of the check block X makes it more fault-tolerant. Attached Figure Description
[0025] The accompanying drawings, as part of this invention, are provided to further illustrate the invention. The illustrative embodiments and descriptions of the invention are used to explain the invention, but do not constitute an undue limitation thereof. Clearly, the drawings described below are merely some embodiments, and those skilled in the art can obtain other drawings based on these drawings without any creative effort.
[0026] Figure 1 This is a schematic diagram of a QR code in one embodiment of the present invention.
[0027] Figure 2 This is a schematic diagram illustrating the size and function of a QR code in one embodiment of the present invention.
[0028] Figure 3 This is a schematic diagram of a 25*25 QR code in one embodiment of the present invention.
[0029] Figure 4 This is a functional graphic diagram of a QR code in one embodiment of the present invention.
[0030] Figure 5 This is a schematic diagram of a center image-finding and positioning graphic block according to an embodiment of the present invention, wherein, Figure 5 (a) A schematic diagram of the dimensions of the center-finding image positioning graphic block. Figure 5 (b) A detailed structural diagram of the center-based image-finding graphic block.
[0031] Figure 6 This is a schematic diagram of the structure of a QR code composed of multiple single-code QR codes laid out in one embodiment of the present invention.
[0032] Figure 7 This is a schematic diagram of the region image D captured during the positioning process in one embodiment of the present invention.
[0033] Figure 8 This is a schematic diagram illustrating QR code boundary positioning in a multi-code tiling example according to an embodiment of the present invention, wherein... Figure 8 (a) is a schematic diagram of the boundary of the QR code by connecting adjacent center points. Figure 8 (b) is a schematic diagram of the correction graphics for locating the four corners of the QR code.
[0034] Figure 9 This is a schematic diagram illustrating the calculation of the QR code tilt angle and the recognition of the crosshair positioning line in one embodiment of the present invention, wherein... Figure 9 (a) is a schematic diagram for calculating the tilt angle of the QR code. Figure 9 (b) is a schematic diagram of crosshair identification.
[0035] Figure 10 This is a schematic diagram illustrating the calculation of the QR code tilt angle in a single-code example of an embodiment of the present invention.
[0036] Figure 11 This is a schematic diagram of the data structure of the header information graphic block in one embodiment of the present invention, wherein, Figure 11 (a) is a structural diagram of the header information graphic block located at the top. Figure 11 (b) is a structural diagram of the header information graphic block located below.
[0037] Figure 12 This is a flowchart illustrating a QR code decoding method according to an embodiment of the present invention.
[0038] Figure 13 This is a flowchart illustrating a QR code error correction encoding method according to an embodiment of the present invention.
[0039] Figure 14 This is a schematic diagram of the layout of a dot scanning method for a QR code in one embodiment of the present invention.
[0040] Figure 15 This is a schematic diagram of the byte scanning method layout of a QR code in one embodiment of the present invention.
[0041] Figure 16 This is a schematic diagram of the hardware structure for an error correction encoding / decoding method for running QR codes according to an embodiment of the present invention.
[0042] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0043] The technical problems solved by the embodiments of the present invention, the technical solutions adopted, and the technical effects achieved will be clearly and completely described below with reference to the accompanying drawings and specific embodiments. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other equivalent or obvious variations of embodiments obtained by those skilled in the art without creative effort fall within the protection scope of the present invention. The embodiments of the present invention can be embodied in various different ways as defined and covered by the claims.
[0044] It should be noted that many specific details are given in the following description for ease of understanding. However, it is obvious that the present invention may be implemented without these specific details.
[0045] It should be noted that, in the absence of explicit limitations or conflicts, the various embodiments and their technical features in this invention can be combined with each other to form a technical solution.
[0046] This invention proposes a QR code with a central image-finding graphic block. During decoding, based on the human visual recognition logic of "from whole to part," the code surface range can be quickly locked by first using the central image-finding graphic block, and then the coordinates can be accurately located by using the center point.
[0047] Please refer to Figures 1-11 In this embodiment, the QR code 100 has a symbol size of M*M and is composed of two graphics with different brightness. The QR code 100 includes functional graphics and data graphics.
[0048] The data graph includes multiple codewords (e.g., Figure 3 The regions D1-D24 are arranged in the data graph area according to the version information. Each codeword includes 8*n3 characters, where n3 is a positive integer. The characters are arranged within the codeword according to a preset compilation order. For example, please refer to... Figure 3 In this embodiment, the codewords are arranged in a horizontal column that is 2 modules wide, starting from the top left corner of the symbol and arranged from left to right and from top to bottom, for a total of 8 characters, with a maximum error correction capacity of 32%.
[0049] Similar to QR codes in existing technologies, data graphics can be XORed using a mask graphic. The purpose of this is to balance the ratio of dark to light modules in the symbol and reduce the appearance of graphics that would hinder fast image processing. Further details will not be elaborated here.
[0050] In this embodiment, the functional graphic includes a center image-finding graphic block 10 with a size of N*N, and the data graphic 20 includes data blocks surrounding the center image-finding graphic block. Wherein, N = 8*n1 + 1, M = N + 8*n2, n1 is a positive integer, and n2 is a positive integer greater than or equal to 2.
[0051] Specifically, in this embodiment of the QR code, in a preferred instance, N=17 and n1 is 2. For example, Figure 2 As shown, the QR code in this embodiment can support sizes from 25*25 to 529*529. Figure 3 The image shows a 25*25 QR code as a specific example where N=17 and M=25.
[0052] It is understandable that the larger the QR code size, the smaller the proportion of the center image-finding graphic block in the QR code, and the lower the speed and accuracy of locating the center image-finding graphic block in the image. Therefore, those skilled in the art can design N and M as needed to set the largest possible center image-finding graphic block while ensuring sufficient data storage bits for the data graphic. When n1 is 1, the supported QR code size will be reduced, suitable for QR codes with small data volumes; when n1 is 3, the supported QR code size can be larger (greater than 529*529), suitable for situations where a single QR code needs to store larger data. However, since larger QR codes will have larger errors during recognition and scanning, the probability of recognition errors will increase significantly; therefore, in a preferred embodiment, N=17 and n1=2, which balances both the storage capacity of the data graphic and the accuracy of scanning and recognition.
[0053] Please combine them together Figure 5 In this embodiment, the center image-finding and positioning graphic block 10 includes: a center module 11, a center rectangular border module 12, a rectangular outer border module 13, a rectangular corner module 14, and a first brightness large square 15.
[0054] Specifically, a central module 11 is composed of N1*N1 graphics of a first brightness level, and the center of the central module 11 coincides with the center of the QR code 100. For example, in this example, the first brightness level is white, the second brightness level is black, and N1 is one of the smallest size units of the QR code. The first and second brightness levels can also use grayscale or color, as long as they have sufficient differentiation and can be quickly identified; this is the same as the recognition technology of black and white QR codes, color QR codes, and grayscale QR codes in the prior art, and will not be described in detail here. N1 is one of the smallest size units of the QR code, that is, a size of 1*1; of course, in other embodiments, it can also be 2*2, 3*3, etc.
[0055] Specifically, a central rectangular border module 12, with a size of 3N1*3N1, is concentrically arranged around the central module 11, consisting of graphics of the second brightness with a size of N1*N1. Since the center of the central module 11 is the center of the QR code 100, when it is necessary to locate the central module 11, the central rectangular border module 12, which has a larger size and a strong contrast with the central module 11, can be located first to roughly locate the center, and then the central module 11 at the center of the central rectangular border module 12 can be located.
[0056] Specifically, a rectangular outer border module 13 of size N*N is concentrically arranged around the central module 11, consisting of N1*N1 second-brightness graphics. The rectangular outer border module 13 is the outer border of the center image-finding graphic block 10, separating the center image-finding graphic block 10 from the data graphics.
[0057] Specifically, a rectangular corner module 14 is formed by a second brightness graphic with a size of aN1*bN1, located at one of the inner corners of the rectangular outer frame module 13. The rectangular corner module 14 is located at one of the inner corners of the rectangular outer frame module 13. By positioning the rectangular corner module 14 and coordinating it with the center point, the tilt angle of the QR code can be calculated.
[0058] Specifically, the remaining portion surrounded by the rectangular outer frame module is composed of large squares 15 of first brightness, filled with graphics of size N1*N1 of first brightness.
[0059] Where N1+aN1+N1≤(N-1) / 2, N1+bN1+N1≤N / 2, a and b are integers greater than or equal to 1, and a≠b. Through the above size constraints of a and b, the rectangular corner module 14 is sufficiently far from the central rectangular border module 12, and the space between the rectangular corner module 14 and the central rectangular border module 12 belonging to the first brightness large square 15 is sufficiently large.
[0060] For example, in this embodiment, a=3 and b=2. It is understood that in other embodiments, when N=17, a and b can take values from 1 to 4, all of which can achieve the same effect.
[0061] The center finder graphic block 10 has a sufficiently large first brightness square 15 (relative to data = graphic). In a typical QR code, it is rare for such a large first brightness graphic to appear in the data graphic. Furthermore, since the data graphic is XORed with a mask graphic, it is impossible for a large first brightness graphic to appear in the QR code. Therefore, the center finder graphic block 10 can be quickly located by positioning the size of the first brightness graphic.
[0062] For example, please combine them together Figure 6 It is a combination of multiple QR codes, formed by stitching together 100 of each other, which can be accessed through... Figure 6 and Figure 7As can be seen intuitively, the white dots on the image are very obvious during image recognition, and can be quickly located and identified even with the naked eye. By rapidly scanning the image, the white dots can be located, thus pinpointing the approximate location P of the center image-finding localization block 10. Then, the image near location P is magnified to perform finer recognition of the other modules of the center image-finding localization block 10. The specific recognition steps will be described in detail later.
[0063] Please combine them together Figures 6-10 The specific image-finding principle of the center image-finding positioning graphic block 10 is as follows: After downscaling and converting the captured image to grayscale, the point with the highest first brightness (white) is found in the image and initially positioned as the location P of the center image-finding positioning graphic block; the corresponding area image D of the image at location P is extracted; the center rectangular border module 12 and the center module 11 in the image D are identified to locate the center point C; then the rectangular corner module and the rectangular outer border module in the image D are identified to identify the entire center image-finding positioning graphic block and calculate the tilt angle A and size Z of the center image-finding positioning graphic block 10, thereby locating the QR code.
[0064] like Figure 7 In the recognition method, if the center point (red cross position) is obtained through coarse contour positioning, the error is relatively large; the green X point is precisely located by using the black block (central rectangular border module 12) and the central white point (central module 11), and the error is relatively small. Selecting the center image-finding graphic block 10 in image D and using distance transformation to find the center position of the black block (central rectangular border module 12) has a much higher accuracy than contour positioning and stronger anti-interference ability (but the computational load is larger); the central white point (central module 11) can be used for center point correction or for precise positioning.
[0065] The size Z of the center image-finding graphic block 10 can be calculated based on the outline of the white block when performing fine recognition of the region image D.
[0066] Please combine again Figures 2-4 The functional graphic also includes correction graphics 30 located at at least three corners of the QR code 100.
[0067] In this embodiment, there are four correction graphics, located at the four corners of the QR code 100.
[0068] The correction pattern 30 includes a first correction block located at the inner corner of the QR code, consisting of a second brightness pattern of size N1*N1; a second correction block consisting of a first brightness pattern of size N1*N1 that surrounds the first correction block together with the outer edge of the QR code; and a third correction block consisting of a second brightness pattern of size N1*N1 that surrounds the second correction block together with the outer edge of the QR code.
[0069] QR code boundary recognition methods are divided into two modes: single code and multiple code. Please combine them together Figure 8 If it is a flat QR code pattern, such as Figure 8 (a) Connect adjacent center points; the perpendicular line from the center of the connecting line is the boundary of the QR code. The intersection of the perpendicular lines (red cross) can be used to initially locate the four corners of the QR code; for example... Figure 8 (b) Then find the accurate four corner positioning blocks (green cross points) near the intersection (red cross) (correction figure 30); If it is a single, independent QR code, the boundaries of the QR code are determined by reading the header information of the QR code to obtain the size information R of the QR code. Based on the center point C, the tilt angle A, and the size information R, the boundaries and four corners of the QR code are roughly located. Then, the accurate four-corner positioning blocks (correction graphic 30) are found near the positions of the four corners that were roughly located, and finally the four corners and boundaries of the QR code are obtained.
[0070] In addition, the four corner positioning blocks (correction graphics 30) can also be used to recalculate the center point to verify or correct the center point C identified and located by the center rectangular border module 12 and the center module 11.
[0071] Please combine them together Figure 9 and Figure 10 The recognition of the tilt angle A of the center image-finding and positioning graphic block 10 is divided into two methods: single code and multi code. If it is a tiled QR code pattern, such as Figure 9 (a) Connect adjacent center points, and the angle of the connecting line segment is the tilt angle A of the QR code; If it is a single, independent QR code, such as Figure 10The rotation and mirror direction of the QR code are determined by the diagonal of the center image-finding graphic block 10 and the orientation of the rectangular corner module 14, thereby locating the QR code. Specifically, the rotation angles of the center image-finding graphic block 10 are determined by the orientation of the rectangular corner module 14, which are 90°, 180°, and 270°. The rectangular corner module 14 is divided into left and right parts by the diagonal of the center image-finding graphic block 10. Since a≠b, the left and right parts are different sizes after the diagonal is cut, so it is possible to identify whether the image is mirrored and thus determine whether mirroring is required.
[0072] Please combine them together Figures 2-4 The functional graphic also includes a clock positioning graphic 20; the clock positioning graphic 20 is a crosshair positioning line, and the center of the clock positioning graphic 20 is consistent with the center of the center image-finding positioning graphic block 10.
[0073] The clock positioning pattern 20 includes horizontal and vertical positioning patterns extending from the four sides of the central image-finding positioning pattern block 10. The horizontal positioning pattern is located at the horizontal center of the QR code, and the vertical positioning pattern is located at the vertical center of the QR code. Both the horizontal and vertical positioning patterns are formed by alternating patterns of size N1*N1 with first and second brightness. Preferably, the beginning and end of the horizontal and vertical positioning patterns are both dark modules (second brightness).
[0074] The clock positioning pattern 20 extends from the four sides of the center image positioning pattern block 10, without obstructing the center image positioning pattern block 10, and will not affect the positioning of the center image positioning pattern block 10.
[0075] The horizontal and vertical positioning graphics serve to determine the density and version of the symbols, which is the same as in the prior art and will not be repeated here; at the same time, they also provide a reference position for determining the module coordinates, which can be used for auxiliary positioning.
[0076] Please combine them together Figure 9The principle of clock positioning pattern 20 for assisted positioning is as follows: the center point located by the center image-finding positioning pattern block 10 is used to locate the position of the crosshair positioning line. The pattern at the position of the crosshair positioning line is read, and it is determined whether it is a pattern formed by alternating patterns of first and second brightness with a size of N1*N1. If the recognition is successful, the QR code positioning is considered successful. If the recognition is unsuccessful, the center point can be corrected by recognizing the actual crosshair positioning line. Specifically, a pattern formed by alternating patterns of first and second brightness with a size of N1*N1 extending in a single direction can be found within a preset range around the position of the crosshair positioning line, and a new crosshair positioning line can be fitted to form it. The center intersection of the crosshair positioning lines is fitted using the new crosshair positioning line as the new center point.
[0077] Specifically, please refer to Figure 8 If the center point is not deviated, the clock line is a black and white dot value that is certain. Therefore, the center point located by the center image positioning graphic block 10, and the position of the crosshair positioning line is the black and white dot.
[0078] If the positioning point is off, the center point is re-established based on the clock line. Since the clock line consists of alternating black and white points with fixed values, the extreme points of the image are found around the original clock line: for example, the coordinates of the darkest point near the black points and the coordinates of the brightest point with the highest grayscale near the white points. Then, based on the new and old coordinates, a new clock line is fitted using the least squares method, along with the intersection point (i.e., the center point) and angle (i.e., the angle between the clock line and the Cartesian coordinate system). The two clock lines correspond to alternating black and white points on the X and Y axes, respectively. Therefore, during the calculation, only the X-coordinate fitting equation is used for the clock line on the X-axis, and only the Y-coordinate fitting equation is used for the clock line on the Y-axis. The details are as follows: 1) Based on the original clock line positioning, calculate the coordinates of each point on the clock line on the X-axis and Y-axis respectively; 2) Find the extreme point P1 within a module distance around each point's coordinates. For bright spots on the clock line, find the coordinates of the brightest point. For dark spots on the clock line, find the coordinates of the darkest point nearby. 3) Fit straight lines to the new points on the clock line using the least squares method, and remove points with large deviations based on the distance to obtain the point set P2 with smaller errors; 4) Define four unknowns: center point coordinates (x, y), slope k, and module point distance d. Calculate the parameter coordinates P3 of each point on the clock line. 5) For each point coordinate P2 and parameter coordinate point P3 found, the least squares method is used to fit the data based on the minimum distance between P2 and P3. Finally, the four unknowns in 4) are calculated, where (x,y) is the new coordinate center point, k is the tilt angle of the clock line (i.e., the tilt angle of the QR code), and d is the average point distance of the module.
[0079] exist Figure 9 (a) and Figure 9 In (b), the clock lines are arranged adjacent to each other in a regular black-and-white sequence on the central green line.
[0080] In this embodiment, the QR code 100 further includes at least one header information graphic block 40, which is located above, below, or simultaneously above and below the central image positioning graphic block 10.
[0081] The header information graphic block includes version information, error correction level, and code size level information.
[0082] The header information graphic block includes version information, error correction level, and code size level information. Specifically, the header information graphic block includes an information graphic and an error correction RS encoding graphic; the header information graphic block includes a left header information block and a right header information block with a size of (N-1) / 2*n4, separated to the left and right, where 1≤n4≤5; the left header information block and the right header information block are separated by the vertical positioning graphic of the crosshair positioning line.
[0083] Please combine them together Figure 3 , Figure 4 and Figure 11 In this embodiment, N=17, n1=2; there are two header information graphic blocks, which are respectively located above and below the central image-finding graphic block. The two header information graphic blocks, each consisting of 2 rows and 17 columns, are placed directly above and below the central image-finding graphic block.
[0084] n4=2; the total number of encoding bits for the header information graphic block is 32 bits, and the left header information block and the right header information block each include 16 encoding bits.
[0085] The left header information block of the header information graphic block located above has two bytes and a total of 16 data bits; the first byte includes 8 encoded bits, which store error correction information, including error correction level and algorithm; the second byte includes 8 encoded bits, which store version information, including the number of check blocks, mask graphic version and gray level. The remaining coded bits of the left and right header information blocks store error correction data. The 48 coded bits are error correction bits calculated using RS(64,16) encoding. The 48-bit error correction data is calculated according to the RS error correction algorithm and appended to the 16 data bits.
[0086] The following is a detailed explanation of the version and format information stored in two bytes: The first byte ( Figure 11 The data bits 0-7 contain error correction information. The 0th to 3rd data bits represent the number of error correction levels (2~16), 2*(N+1).
[0087] The 4th to 6th data bits, if they are global RS content, are the GF field value of the RS algorithm, 8+N; if they are local RS content, they are the RS algorithm mode, 0 for variable length RS, 1 for interleaved grouping, 2 for corner grouping, and 3~7 for extended reservation.
[0088] The 7th data bit is used to determine whether it is a global RS or a local RS. 1 indicates a variable-length global RS, and 0 indicates a grouped local RS.
[0089] The second byte ( Figure 11 The 8th to 15th data bits contain the symbol's version information: The 0th and 1st data bits are the remainder or check block number of the effective length of ModN (0~3).
[0090] The contents of the second to fourth data bits are for selecting the mask graphic version (Mask(0~7)).
[0091] The content of the 5th to 7th data bits is the gray level number (0 is black and white, 2~n levels).
[0092] For example, in a specific instance, please combine... Figure 14 and Figure 15 The data area contains length bytes (4) + original data (N) + error correction data (2E).
[0093] Algorithmically, the original data is prefixed with four bytes and then processed by RS error correction encoding. The resulting error-corrected data is placed at the end and then filled into the data area.
[0094] When filling data, fill by bit in an S-path, and scan between rows in an S-path as well (because RS code errors are counted by bytes, while code errors are counted by bits, so adjacent bits should be made as close as possible, and the broken points should be concentrated in the same byte as much as possible). The module size increases with the data size. When there are spare bits, the data is filled as much as possible to increase the fault tolerance level, and then the extra bits are filled with zeros.
[0095] The module increases by 8 bytes in length and width each time, plus 4 bytes on each side. The bytes are scanned in double rows, so each increase is exactly an integer number of bytes, ensuring the code is always byte-aligned. After byte alignment, pattern drawing and recognition / readback can be performed quickly. S-path conversion and concurrent processing can be implemented using a simple lookup table. Image and binary conversions can be accelerated using memory copying, a speedup feature that cannot be utilized with current computers when other QR code data patterns are misaligned.
[0096] Preferably, the data graphic area of the QR code is processed by XOR operation through a mask graphic.
[0097] Please combine them together Figures 1-11 This embodiment also provides a QR code decoding method as described above, including steps S1-S5.
[0098] S1. Acquire the captured image S. After downscaling and converting the captured image to grayscale, obtain a binary image B. Reduce the length of image S by 5 to 20 times and convert it to grayscale image M (downscaling can speed up the pattern search and location time by tens or hundreds of times). Select the median value between the maximum and minimum reflectance of the image to determine the threshold. Use the threshold to convert the image into a series of dark and light pixels to obtain the binary image B.
[0099] S2, by finding the point with the highest first brightness in image B, the position P of the center image-finding and positioning graphic block is initially determined.
[0100] S3, crop the image D of the corresponding position P in the image S, which is a region of a preset size.
[0101] In steps S1-S3, please combine them together Figure 6 It is a combination of multiple QR codes, formed by stitching together 100 of each other, which can be accessed through... Figure 7 As can be seen intuitively, the white dots on the image are very obvious when the image is being recognized, and can be quickly located and identified even with the naked eye. By quickly scanning the image, the white dots on the image can be located, thereby locating the approximate position P of the center image-finding positioning graphic block 10. Then, the image near position P is magnified to perform fine recognition of the other modules of the center image-finding positioning graphic block 10.
[0102] S4, identify the central rectangular border module, or the central rectangular border module and the central module in the image D, and locate the center point C.
[0103] Preferably, step S4 includes locating the central rectangular border module in the image D, and then locating the central module within the image area of the central rectangular border module to determine the center point C. Alternatively, the center point can be coarsely located directly from the central rectangular border module, followed by precise location of the central module in the center to determine the center point C. In specific implementations, the final precise location of the center module can serve as a verification of the coarsely determined center point or as a supplement to the precise location.
[0104] Please combine them together Figure 7 The specific image-finding principle of the center image-finding positioning graphic block 10 is as follows: after the captured image is reduced and grayscale value is converted, the point with the highest first brightness (white) is found in the image and initially determined as the position P of the center image-finding positioning graphic block; the corresponding area image D of the image at position P is extracted; the center rectangular border module 12 and the center module 11 in the image D are identified to locate the center point C.
[0105] like Figure 7 In the recognition method, the center image-finding and positioning graphic block 10 is selected in image D, and the center position of the black block (center rectangular border module 12) is found by using distance transformation. The accuracy is much higher than that of contour positioning, and the anti-interference ability is stronger (but the amount of calculation is larger). The center white point (center module 11) can be used for center point correction or for precise positioning.
[0106] The size Z of the center image-finding graphic block 10 can be calculated based on the outline of the white block when performing fine recognition of the region image D.
[0107] S5, identify the rectangular corner module and the rectangular outer border module in the image D to identify the entire center image-finding positioning graphic block and calculate the tilt angle A and size Z of the center image-finding positioning graphic block.
[0108] Preferably, step S5 includes, The rectangular corner module in the image D is located, and the tilt angle A of the center image positioning graphic block is calculated based on the orientation between the rectangular corner module and the center point C. The rectangular outer border module in the image D is identified to identify the center image-finding and positioning graphic block and to calculate the size Z of the center image-finding and positioning graphic block. Based on the tilt angle A and the orientation of the diagonal of the center image-finding positioning graphic block and the rectangular corner module, the rotation direction and mirror direction of the QR code are obtained, thereby performing angular positioning of the QR code.
[0109] Please combine them together Figure 9 and Figure 10 The recognition of the tilt angle A of the center image-finding and positioning graphic block 10 is divided into two methods: single code and multi code. If it is a tiled QR code pattern, such as Figure 9 (a) Connect adjacent center points, and the angle of the connecting line segment is the tilt angle A of the QR code; If it is a single, independent QR code, such as Figure 10 The rotation and mirror direction of the QR code are determined by the diagonal of the center image-finding graphic block 10 and the orientation of the rectangular corner module 14, thereby locating the QR code. Specifically, the rotation angles of the center image-finding graphic block 10 are determined by the orientation of the rectangular corner module 14, which are 90°, 180°, and 270°. The rectangular corner module 14 is divided into left and right parts by the diagonal of the center image-finding graphic block 10. Since a≠b, the left and right parts are different sizes after the diagonal is cut, so it is possible to identify whether the image is mirrored and thus determine whether mirroring is required.
[0110] S6, locate the position of the header information graphic block and read the header information; S7, decode the header information according to the corresponding preset RS error correction algorithm, and determine whether the decoding is successful; if the decoding is successful, proceed to step S81; S81, positioning correct, proceeding to the data graphic positioning and reading process.
[0111] Steps S6 and S7 verify the accuracy of the image seeker's location by decoding the header information graphic block. Only after accurate decoding does the encoding and recognition of the QR code's data graphic begin. If the header information is read incorrectly, the location will inevitably be inaccurate. The header information can only be decoded successfully when the location is accurate. This avoids interruptions and errors in data scanning due to minor positioning deviations, and verifies the accuracy of the positioning in advance.
[0112] Preferably, the QR code decoding method further includes the step of obtaining the boundary and size information R of the QR code, specifically including: When the QR code is a single code, the header information point of the QR code is read to obtain the size information R of the QR code, and the boundary of the QR code is located according to the tilt angle A and the size information R. When the QR code is designed as a multi-code tiled design, the adjacent center points C are connected, and the vertical line at the center of the connecting line is the boundary of the QR code.
[0113] QR code boundary recognition methods are divided into two modes: single code and multiple code. Please combine again Figures 2-4as well as Figure 8 The functional graphic also includes correction graphics 30 located at at least three corners of the QR code 100.
[0114] In this embodiment, there are four correction graphics, located at the four corners of the QR code 100.
[0115] The correction pattern 30 includes a first correction block located at the inner corner of the QR code, consisting of a second brightness pattern of size N1*N1; a second correction block consisting of a first brightness pattern of size N1*N1 that surrounds the first correction block together with the outer edge of the QR code; and a third correction block consisting of a second brightness pattern of size N1*N1 that surrounds the second correction block together with the outer edge of the QR code.
[0116] Preferably, the functional graphic further includes correction graphics located at at least three corners of the QR code; step S7 further includes, if decoding fails, proceeding to step S9, including: S91, based on the boundary, locate and identify the correction pattern within a preset range of the boundary; S92, the center point C is corrected according to the correction pattern.
[0117] Preferably, step S92 includes: recalculating the center point C' of the QR code based on the correction pattern; using the center point C' as the new center point C, and returning to step S5.
[0118] The center point is recalculated by using the four corner positioning blocks (correction graphic 30) to recalibrate the center point C identified and located by the center rectangular border module 12 and the center module 11; then the center image positioning graphic block is identified and located again.
[0119] Preferably, the functional graphic further includes a clock positioning graphic block; the clock positioning graphic block is a crosshair positioning line, and the center of the clock positioning graphic block coincides with the center of the center lookup positioning graphic block; the clock positioning graphic block includes horizontal positioning graphics and vertical positioning graphics extending from the four sides of the center lookup positioning graphic block respectively; the horizontal positioning graphics are located at the horizontal center of the QR code, and the vertical positioning graphics are located at the vertical center of the QR code, and both the horizontal and vertical positioning graphics are formed by alternating graphics of size N1*N1 with first brightness and second brightness; step S7 further includes, if decoding fails, proceeding to step S10; step S10 includes: S101, based on the center point C and the center image-finding positioning graphic block, locate the position of the crosshair positioning line, and search within a preset range around the position of the crosshair positioning line for a graphic of first brightness and second brightness that extends in a single direction and has a size of N1*N1, and fit it to form a new crosshair positioning line. S102, using the new crosshair positioning line, fit the center intersection of the crosshair positioning line as the new center point C, and return to step S5.
[0120] Please combine them together Figure 9 The principle of clock positioning pattern 20 for assisted positioning is as follows: the center point located by the center image-finding positioning pattern block 10 is used to locate the position of the crosshair positioning line. The pattern at the position of the crosshair positioning line is read, and it is determined whether it is a pattern formed by alternating patterns of first and second brightness with a size of N1*N1. If the recognition is successful, the QR code positioning is considered successful. If the recognition is unsuccessful, the center point can be corrected by recognizing the actual crosshair positioning line. Specifically, a pattern formed by alternating patterns of first and second brightness with a size of N1*N1 extending in a single direction can be found within a preset range around the position of the crosshair positioning line, and a new crosshair positioning line can be fitted to form it. The center intersection of the crosshair positioning lines is fitted using the new crosshair positioning line as the new center point.
[0121] Compared to traditional triangular positioning, the QR code and its decoding method in this embodiment can reduce the space occupied by the positioning pattern by more than 80%, freeing up the code surface for data storage.
[0122] In the design of multiple QR codes 100-fold tiling, after step S2, by finding the point with the highest first brightness in image B, the set Ps of the position P of the center image-finding graphic block and the set Rs of the QR code size are initially determined; then, the minimum distance between each pair of points in set Ps is identified, and erroneous positions P can be filtered out based on the average distance; simultaneously, a linear coordinate system is constructed based on the lines connecting the points in set Ps, and the intersection of the lines can be used as the corrected position P, and then step S3 is introduced. For the multi-QR code tiling design for data storage, the positioning effect of the center image-finding graphic block in this embodiment is better. With the multi-QR code tiling design, the larger the data volume, the more surrounding positioning points can be used to fill in the missing positioning points, so the larger the data, the higher the space utilization and the higher the recognition rate.
[0123] Specifically, after correct positioning in step S81, the data graphic positioning and reading process begins. Since version information, error correction level, code size level information, etc., have already been read from the header information graphic block, and the positioning is accurate, the QR code can now be scanned, read, compiled, and decoded according to the scanning mode corresponding to the version. This part is something that those skilled in the art can directly and unambiguously achieve based on conventional technical means in this field and the content disclosed in this embodiment, and will not be elaborated here.
[0124] This embodiment also provides a QR code decoding method as described above, including steps S21-S24.
[0125] S21, Obtain the data to be encoded, and calculate the version number and length information of the smallest module of the QR code data graphic based on the length of the data to be encoded, the version information of the QR code to be encoded, and the error correction level. S22, calculate RS error correction data based on the data to be encoded, version number, length information and error correction level; S23, the length information, the data to be encoded, and the RS error correction data are concatenated to form the data to be filled; S24, Based on the QR code version information to be encoded, draw the functional graphic of the QR code, and fill the data to be filled into the data graphic of the QR code.
[0126] Preferably, the method further includes step S32, which involves performing an XOR operation on the binary representation of the data to be filled and the mask pattern data to obtain new data to be filled.
[0127] Preferably, the functional graphic further includes at least one header information graphic block, and at least one of the header information graphic blocks is located adjacent to the central image-finding and positioning graphic block above, below, or simultaneously adjacent to both above and below; the header information graphic block includes version information, error correction level, and code size level information; It also includes the following steps: S401, Generate header padding data based on the version information, error correction level, and code size level information; S402, Draw the header information graphic block according to the header filling data.
[0128] Preferably, it also includes the following steps: S101, the data to be processed is divided into multiple data blocks; S102, the multiple data blocks are added to multiple redundant blocks through an erasure algorithm to obtain multiple single-code data, each single-code data including one of the data to be encoded; S103, generate multiple single-code QR codes from the data to be encoded according to steps S1 to S4; S104, the multiple single-code QR codes are combined into a multi-code QR code according to the preset aspect ratio and splicing order.
[0129] Please combine them together Figure 12 This embodiment also provides a QR code decoding method as described above, including steps S21-S24.
[0130] S1, Obtain the data to be encoded, and calculate the version number and length information of the smallest module of the QR code data graphic based on the length of the data to be encoded, the version information of the QR code to be encoded, and the error correction level. S2, calculate RS error-corrected data based on the data to be encoded, version number, length information, and error correction level; including: S21, select either variable-length RS encoding or block interleaved RS encoding method based on the data to be encoded, version number, and length information; S221, when selecting variable-length RS coding, select an appropriate Galois field (GF) space operation according to the data length, perform error correction coding, and calculate RS error correction data; S222, when selecting group interleaved RS coding, performs error correction coding in the 8-bit GF field and calculates RS error correction data; S223, the length information, the data to be encoded, and the RS error correction data are concatenated to form the data to be filled; S23, Based on the version information of the QR code to be encoded, draw the functional graphic of the QR code, and fill the data to be filled into the data graphic of the QR code.
[0131] Preferably, the method further includes step S32, which involves performing an XOR operation on the binary representation of the data to be filled and the mask pattern data to obtain new data to be filled.
[0132] Preferably, the functional graphic further includes at least one header information graphic block, and at least one of the header information graphic blocks is located adjacent to the central image-finding and positioning graphic block above, below, or simultaneously adjacent to both above and below; the header information graphic block includes version information, error correction level, and code size level information; It also includes the following steps: S401, Generate header padding data based on the version information, error correction level, and code size level information; S402, Draw the header information graphic block according to the header filling data.
[0133] Preferably, it also includes the following steps: S101, the data to be processed is divided into multiple data blocks; S102, the multiple data blocks are added to multiple redundant blocks through an erasure algorithm to obtain multiple single-code data, each single-code data including one of the data to be encoded; S103, generate multiple single-code QR codes from the data to be encoded according to steps S1 to S4; S104, the multiple single-code QR codes are combined into a multi-code QR code according to the preset aspect ratio and splicing order.
[0134] Step S221 includes: Calculate the number of bits in the data to be encoded and the number of bits occupied by the error correction data, and add them together to get the total number of data bits. Based on the total number of bits, find the smallest number of bits B in the Galois field; Based on the number of bits B in the Galois field, the original data is concatenated into a new dataset P by B bits; The new dataset P is used to obtain the error-corrected data E through the RS algorithm with a bit depth of B. Step S223 includes: concatenating P and E to form the data O to be written.
[0135] Step S222 includes: Based on the original data length and error correction level, the optimal GF space N and error correction number E are selected from 200 to 255 according to the principle of optimal capacity. The effective capacity of each block is K = N - 2 * E. The original data is divided into data blocks of K bytes each, resulting in a total of U data blocks; XOR each block of data by bytes to obtain a check block X; The error correction data is obtained by performing RS(N,K) calculation on both the U block data and the check block X. Step 223 includes: After the error-corrected data is concatenated to the original data block, a new data block F (U+1) is obtained. The data is cyclically mixed and interleaved from F to form a block of data O, which is the data to be written and filled.
[0136] The present invention also provides an error correction and decoding system for the above-mentioned QR codes, comprising the following steps: S10, Obtain the error correction encoding mode of the QR code; S201, when the error correction coding mode of the QR code is variable-length RS coding: Calculate the maximum data capacity bits based on the code version, and find the minimum GF space bit size B. Based on the error correction level and maximum capacity, calculate the maximum length K of the original data and the length E of the redundant data; Divide the data O into B-bit segments and concatenate them to form the data N; Perform RS decoding on the data N. After successful decoding, the original data is obtained. S202, when the error correction coding mode of the QR code is block interleaved RS coding: The maximum data capacity in bytes is calculated based on the code version, and the number of error correction bytes is calculated based on the error correction level. Calculate the original number of blocks U based on the capacity; The data O to be decoded is grouped into U+1 groups to restore the data F of each group; Perform RS decoding on each data block; When all data blocks can be successfully decoded, the data block bytes are concatenated to obtain the original data bytes, and the data is directly restored. When any group of data blocks fails to decode, and the last group of check blocks X is successfully decoded, the successfully decoded group and the check group can be XORed by bytes to restore the failed data block. The data block bytes are then concatenated to obtain the original data bytes, and the data is restored.
[0137] Figure 14 This is a schematic diagram of the hardware structure for an encoding / decoding method for running QR codes, provided in an embodiment of the present invention. Figure 14 As shown, this embodiment / computer 6 includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a program for running a QR code decoding method. When the processor 60 executes the computer program 62, it implements the steps in the various method embodiments described above. Alternatively, when the processor 60 executes the computer program 62, it implements the functions of each module / unit in the various device embodiments described above.
[0138] For example, the computer program 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program 62 in the computer 6.
[0139] The computer 6 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. The computer 6 may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will understand that... Figure 14 This is merely an example of computer 6 and does not constitute a limitation on computer 6. It may include more or fewer components than shown, or combine certain components, or different components. For example, computer 6 may also include input / output devices, network access devices, buses, etc.
[0140] The processor 60 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0141] The memory 61 can be an internal storage unit of the computer 6, such as a hard drive or memory. The memory 61 can also be an external storage device of the computer 6, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card (FC) equipped on the computer 6. Furthermore, the memory 61 can include both internal and external storage units of the computer 6. The memory 61 is used to store the computer program 62 and other programs and data required by the computer 6. The memory 61 can also be used to temporarily store data that has been output or will be output.
[0142] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0143] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0144] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0145] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / terminal devices and methods can be implemented in other ways. For example, the apparatus / terminal device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0146] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0147] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0148] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0149] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included within the protection scope of the present invention.
Claims
1. A method for error correction encoding of QR codes, characterized in that, The QR code includes a functional graphic and a data graphic. The functional graphic includes a center finder positioning graphic block of size N*N, and the data graphic includes data blocks surrounding the center finder positioning graphic block, where N=8*n1+1, M=N+8*n2, n1 is a positive integer, and n2 is a positive integer greater than or equal to 2. The central image-finding graphic block includes: a central module composed of graphics of size N1*N1 with a first brightness, the center of which coincides with the center of the QR code; a central rectangular border module of size 3N1*3N1 composed of graphics of size N1*N1 with a second brightness, concentrically arranged around the central module; a rectangular outer border module of size N*N composed of graphics of size N1*N1 with a second brightness, concentrically arranged around the central module; a rectangular corner module composed of graphics of size aN1*bN1 with a second brightness, located at one inner corner of the rectangular outer border module; and a large square of first brightness, filled with graphics of size N1*N1 with a first brightness, surrounding the rectangular outer border module; wherein, N1+aN1+N1≤(N-1) / 2, N1+bN1+N1≤N / 2, a and b are integers greater than or equal to 1, and a≠b; The data graphic includes multiple codewords arranged in the region of the data graphic according to the arrangement order corresponding to the version information. Each codeword includes 8*n3 characters, where n3 is a positive integer. The characters are arranged in the codeword according to a preset compilation order. Including the following steps: S1, Obtain the data to be encoded, and calculate the version number and length information of the smallest module of the QR code data graphic based on the length of the data to be encoded, the version information of the QR code to be encoded, and the error correction level. S2, calculate RS error-corrected data based on the data to be encoded, version number, length information, and error correction level; including: S21, select either variable-length RS encoding or block interleaved RS encoding method based on the data to be encoded, version number, and length information; S221, when selecting variable-length RS coding, select an appropriate Galois field (GF) space operation according to the data length, perform error correction coding, and calculate RS error correction data; S222, when selecting group interleaved RS coding, performs error correction coding in the 8-bit GF field and calculates RS error correction data; S223, the length information, the data to be encoded, and the RS error correction data are concatenated to form the data to be filled; S23, Based on the QR code version information to be encoded, draw the functional graphic of the QR code, and fill the data to be filled into the data graphic of the QR code.
2. The error correction encoding method for QR codes according to claim 1, characterized in that, It also includes step S32, which involves performing an XOR operation on the binary representation of the data to be filled and the mask pattern data to obtain new data to be filled.
3. The error correction coding method for QR codes according to claim 1, characterized in that, Step S221 includes: Calculate the number of bits in the data to be encoded and the number of bits occupied by the error correction data, and add them together to get the total number of data bits; Based on the total number of bits, find the smallest number of bits B in the Galois field; Based on the number of bits B in the Galois field, the original data is concatenated into a new dataset P by B bits; The new dataset P is used to obtain the error-corrected data E through the RS algorithm with a bit depth of B. Step S223 includes: concatenating P and E to form the data O to be written.
4. The error correction encoding method for QR codes according to claim 1, characterized in that, Step S222 includes: Based on the original data length and error correction level, the optimal GF space N and error correction number E are selected from 200 to 255 according to the principle of optimal capacity. The effective capacity of each block is K = N - 2 * E. The original data is divided into data blocks of K bytes each, resulting in a total of U data blocks; XOR each block of data by bytes to obtain a check block X; The error correction data is obtained by performing RS(N,K) calculation on both the U block data and the check block X. Step 223 includes: After the error-corrected data is concatenated to the original data block, a new data block F (U+1) is obtained. The data is cyclically mixed and interleaved from F to form a block of data O, which is the data to be written and filled.
5. The error correction encoding method for QR codes according to claim 1, characterized in that, It also includes the following steps: S101, the data to be processed is divided into multiple data blocks; S102, the multiple data blocks are added to multiple redundant blocks through an erasure algorithm to obtain multiple single-code data, each single-code data including one of the data to be encoded; S103, generate multiple single-code QR codes from the data to be encoded according to steps S1 to S4; S104, the multiple single-code QR codes are combined into a multi-code QR code according to the preset aspect ratio and splicing order.
6. A QR code, characterized in that, The QR code is generated using the error correction encoding method described in any one of claims 1-5.
7. The QR code according to claim 6, characterized in that, The first brightness is white or transparent, the second brightness is black, N1 is the smallest size unit of the QR code, and M is 25-529; n1 is 2, a=3, b=2.
8. An error correction and decoding system for QR codes according to any one of claims 6-7, characterized in that, Including the following steps: S10, Obtain the error correction encoding mode of the QR code; S201, when the error correction coding mode of the QR code is variable-length RS coding: Calculate the maximum data capacity bits based on the code version, and find the minimum GF space bit size B. Based on the error correction level and maximum capacity, calculate the maximum length K of the original data and the length E of the redundant data; Divide the data O into B-bit segments and concatenate them to form the data N; Perform RS decoding on the data N. After successful decoding, the original data is obtained. S202, when the error correction coding mode of the QR code is block interleaved RS coding: The maximum data capacity in bytes is calculated based on the code version, and the number of error correction bytes is calculated based on the error correction level. Calculate the original number of blocks U based on the capacity; The data O to be decoded is grouped into U+1 groups to restore the data F of each group; Perform RS decoding on each data block; When all data blocks can be successfully decoded, the data block bytes are concatenated to obtain the original data bytes, and the data is directly restored. When any group of data blocks fails to decode, and the last group of check blocks X is successfully decoded, the successfully decoded group and the check group can be XORed by bytes to restore the failed data block. The data block bytes are then concatenated to obtain the original data bytes, and the data is restored.
9. A QR code encoding and decoding system, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-5 or 8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-5 or 8.
