A method for encoding and decoding large-capacity QR codes that adapts to screen ratio

By adaptively adjusting the number of modules and the position of the graphic in the QR code, and combining RS and BCH encoding, the problem of low data storage and transmission efficiency of existing QR codes on the display screen is solved, achieving more efficient data transmission and larger storage capacity.

CN116070661BActive Publication Date: 2026-06-30DALIAN UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
DALIAN UNIV OF TECH
Filing Date
2022-11-24
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing QR codes are insufficient to meet the needs of large amounts of data storage and transmission, and when displayed on electronic screens, they often fail to fully utilize screen space, resulting in low transmission efficiency.

Method used

A high-capacity QR code encoding method with adaptive screen ratio is designed. By adjusting the number of QR code modules, the position detection graphic, the positioning graphic, and the correction graphic according to the aspect ratio of the display screen, the graphic layout is optimized, the data storage capacity is increased, and error correction is performed through RS encoding and BCH encoding to improve the communication bandwidth.

Benefits of technology

It enables more efficient storage and transmission of data on electronic displays, improves transmission efficiency, makes full use of screen space, and increases data storage capacity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116070661B_ABST
    Figure CN116070661B_ABST
Patent Text Reader

Abstract

This invention belongs to the field of automatic identification and proposes a high-capacity QR code encoding and decoding method that adapts to screen ratios. In a general environment, when a large amount of data needs to be transmitted, the data is encoded into a high-capacity QR code with an adaptive ratio according to the screen display ratio for data stream transmission, maximizing the use of screen display space. The QR code selects a graphic version based on the amount of encoded data and the aspect ratio of the display space, and calculates the number and coordinate positions of data codeword blocks, correction symbols, and positioning symbols based on the version and aspect ratio, expanding the version information data and generating the QR code. A corresponding adaptive-ratio QR code decoding method is also provided, which decodes and displays the QR code data information through scanning. Due to the increased screen utilization, higher data transmission efficiency than standard QR codes is achieved, increasing communication bandwidth.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of automatic identification, and in particular to a method for encoding and decoding large-capacity QR codes that adapts to screen ratios. Background Technology

[0002] With the rapid development of mobile internet, QR codes have become ubiquitous in people's daily lives. QR codes offer numerous advantages, including a wide encoding range, high degree of freedom, and strong fault tolerance. As a timely, accurate, and economical data transmission method, QR codes are widely used in commerce, transportation, healthcare, industry, and automated office systems. However, due to the expanding application areas of QR codes, ordinary QR codes are finding it difficult to meet the storage and transmission needs of large amounts of data.

[0003] Therefore, in order to meet the storage and transmission of large amounts of data, various direct or indirect QR code storage capacity expansion technologies have emerged, such as URL links (see Tiwari S. An introduction to QR code technology [C] / / 2016 international conference on information technology (ICIT). IEEE, 2016: 39-44.), data hiding (see Mathivanan P, Balaji Ganesh A. QR code based color image cryptography for the secured transmission of ECG signal [J]. Multimedia Tools and Applications, 2019, 78(6): 6763-6786.), dynamic QR codes (see Liu W, Wang B, Li Y, et al. Screen-camera communication system based on dynamic QR code [C] / / IOPConference Series: Materials Science and Engineering. IOP Publishing, 2020, 790(1): 012012.), and multi-level strength (see Tank AH, Unde MM, Patel BJ, et al. Storage and transmission). of information using gray level QR(quick-response)code structure[C] / / 2016Conference on Advances in Signal Processing(CASP).IEEE,2016:402-405.), color QR code (see Galiyawala HJ, Pandya K H.To increase data capacity of QRcode using multiplexing with color coding: An example of embedding speechsignal in QR code[C] / / 2014Annual IEEE India Conference(INDICON).IEEE,2014:1-6.) etc.However, there are also some limitations in the application environment. For example, network connectivity can affect the application efficiency and scope of QR codes due to network environment limitations. Data hiding requires the addition of hidden information. Dynamic QR codes need to be displayed on electronic screens. Multi-level intensity reduces the tolerance of QR codes to noise. Color QR codes require control of color differences in color printing, etc.

[0004] It has been observed that most common electronic display devices are rectangular, such as mobile phones, tablets, and electronic screens, while standard QR codes are square. When displaying a QR code on a screen, it usually fills the shortest side of the rectangular screen, leaving the remaining screen space unused for QR code data display. To fully utilize display space resources and acquire more data information with a single scan, this invention proposes a high-capacity QR code encoding and decoding method that adapts to screen ratios. Summary of the Invention

[0005] The purpose of this invention is to propose a high-capacity QR code encoding and decoding method that adapts to screen ratio, thereby increasing the data storage capacity of QR codes and improving communication bandwidth.

[0006] The technical solution of this invention: a method for encoding and decoding large-capacity QR codes that adapts to screen ratios, comprising the following steps:

[0007] Step 1: Encode as much information as possible into QR codes according to the aspect ratio of the display screen and display them; Designed QR code encoding method: Determine the number of QR code length and width modules, position detection graphic, positioning graphic, and correction graphic positions according to the known QR code version and the aspect ratio of the display screen, and arrange each graphic according to the encoding method to generate QR codes;

[0008] Step 1.1: Analyze the data type, determine the type of encoded characters, and convert the information into symbol characters according to the corresponding character set; segment the data according to the type, and add a 4-bit mode indicator and character count indicator to encode the data into a data bit stream; concatenate all data bit streams to generate data codewords, with a data codeword count of B;

[0009] Step 1.2: Using the screen width (short side) as the standard, divide the width into square units using the number of modules N of version C (2≤C≤40). Divide the length into M units based on the size of these units, subtracting one if M is even, while maintaining an odd number of modules in the horizontal direction (screen aspect ratio is m:n). In the QR code image, module row and column numbers start from 0, numbered from left to right and top to bottom, with coordinates represented as (row number, column number).

[0010] Based on the aspect ratio of the display screen, the length and width modules are divided by the graphic version number C; the number and coordinates of each functional graphic are calculated; the functional graphics include position detection graphics, position detection graphic separators, positioning graphics, and calibration graphics;

[0011] Number of modules in the horizontal direction:

[0012]

[0013] Number of modules in the vertical direction:

[0014] N = 4(C-1) + 21

[0015] in, This indicates the aspect ratio of the display screen, C represents the graphics version number, and 2 ≤ C ≤ 40;

[0016] The position detection pattern consists of three 7×7 module-sized graphics located at the top left, bottom left, and top right corners of the graphic, each composed of a 7×7 black frame containing a 3×3 black square. The center coordinates of the position detection patterns are (3, 3), (N-4, 3), and (3, M-4), respectively. Each position detection pattern is separated from the coding area by a position detection pattern separator with a width of one module; this area is entirely blank. The number of modules occupied by the position detection patterns is W = 3 × 7 × 7 = 147.

[0017] The positioning graphics are composed of a row and a column, each 1 module wide, with alternating light and dark modules. The head and tail of each column are dark modules. The positioning graphics in the first row and the first column are merged with the position detection graphics.

[0018] Number of vertically positioned graphics:

[0019] Number of horizontally positioned graphics: ;

[0020] QR codes with graphic version number C all have a correction graphic, with a fixed correction graphic at the lower right corner (N-7, M-7); this ensures that the three position detection graphics and the correction graphic form a rectangle. A correction graphic consists of a 5×5 black frame containing a 1×1 black block. The correction graphic should divide the QR code's encoding area as evenly as possible. The number of correction graphics is g. sum = (g1+2)(g2+2)-3, where g1 is the number of horizontal correction modules and g2 is the number of vertical correction modules.

[0021] Calculate the correction pattern on the positioning pattern line. When r < 15, no correction pattern is set in the vertical direction, and when w < 15, no correction pattern is set in the horizontal direction.

[0022] o represents the number of dark-colored positioning graphic modules in the horizontal or vertical direction. When o ≥ 15, take integer g = 1, 2, 3..., where g is the number of correction graphics in the horizontal or vertical direction. Calculate the number d (5 ≤ d ≤ 12) of dark-colored positioning graphic modules in the horizontal or vertical direction separated by the correction graphics.

[0023] Therefore, when the number of dark modules in the horizontal and vertical positioning graphics exceeds the set value, additional correction graphics are set; the number of dark positioning graphics separated by the correction graphics:

[0024] d = (o - 3g) / (g + 1)

[0025] Where o represents the number of dark-colored modules of the positioning graphic in the horizontal or vertical direction, and g represents the number of correction graphics in the horizontal or vertical direction, satisfying 5≤d≤12;

[0026] If d is an integer, the dark-colored positioning graphics in the horizontal or vertical direction are divided equally according to this division; if d is a decimal, then we get d1 rounded up and d2 rounded down. Take integers dn1 = 1, 2, 3... and calculate d3 = w - 3g - dn1 × d1 until dn2 = d3 / d2 is an integer. Then the dark-colored positioning graphics in the horizontal direction are divided into dn1 divisions containing d1 dark modules and dn2 divisions containing d2 dark modules.

[0027] The dark positioning graphic segment d, calculated separately in the horizontal and vertical directions, is represented as d. w and d r The horizontal correction point is located at coordinates (6, 10+2d). w ), (6, 10+2d w +4+2d w ..., where d w When the value is a decimal, it is rounded up to the nearest integer d. w1 Or round down to the nearest integer d w2 The column coordinates of each subsequent correction plot in the horizontal direction are increased by 4 + 2d based on the column coordinates of the previous correction plot. w The vertical coordinates of the corrected graphic center are (10+2d). r ,6),(10+2d r +4+2d r ,6)...,where d r When the value is a decimal, it is rounded up to the nearest integer d. r1 Or round down to the nearest integer d r2 The row coordinates of each subsequent correction plot in the vertical direction are increased by 4 + 2d based on the row coordinates of the previous correction plot. r The coordinates of other correction patterns distributed within the coding area are a combination of the calculated horizontal and vertical coordinates of the correction patterns and the coordinates of the fixed correction pattern in the lower right corner.

[0028] Step 1.3: Calculate the total number of image data bits.

[0029] The formula for calculating the cell G occupied by functional graphics, formatting information, and version information is:

[0030] G = W + D + J + F + V

[0031] Where W represents the number of cells occupied by the location detection graphic, D represents the number of cells occupied by the location detection graphic separator, J represents the number of cells occupied by the positioning and correction graphics, F represents the number of cells occupied by the formatting information, and V represents the number of cells occupied by the version information; W = 3 × 7 × 7; D = 3 × 15; J = 2(r + w) - 1 + 5(5g) sum -g1-g2); F=2×15; V=2×46.

[0032] After determining the total number of cells G occupied by the functional graphics, format information, and version information, calculate the total number of data bits S and the total number of codewords Z; the total number of data bits is S = N × MG, and the total number of codewords is... ;

[0033] Step 1.4: Calculate the number of error correction code words.

[0034] Based on the accuracy requirements of the transmitted information and the conditions of the usage environment, balance transmission capacity and information quality, and select the error correction level (L: 7%, M: 15%, Q: 25%, H: 30%). If no error correction level has been determined, use the minimum version that is suitable for the data.

[0035] The error correction capacity E and the number of error correction codewords R are calculated based on the error correction capacity percentage b (%) of the error correction code version and the total number of codewords Z;

[0036]

[0037] R = 2E

[0038] Step 1.5, Image Version Selection

[0039] The number of stored data codewords is calculated based on the graphic version number C, the total number of codewords Z, and the number of error correction codewords R.

[0040] A = ZR

[0041] If the number of data codewords that this version of the graphic can store is A≥B, then this version of the graphic is used for encoding; if A<B, then the graphic version number is increased, and steps 1.2-1.4 are repeated to calculate and compare the capacity of larger versions of the graphic one by one until A≥B; the empty codewords that are not filled are alternately filled with 11101100 and 00010001 until all codewords are filled.

[0042] Step 1.6: Divide data codewords and error correction codewords into blocks.

[0043] The data codewords are divided into blocks to form data blocks, and each data block is subjected to error correction operations to generate error correction data codewords.

[0044] The error correction codewords and data codewords are evenly distributed across the data blocks. The error correction capacity E is divided by the integer e, and the first divisible number is taken as the error correction capacity of a single data block. The quotient is the number of data blocks p. When p ≤ 15 and e < p, the values ​​of e and p are swapped. The number of error correction codewords in a data block is 2e, and the number of data codewords in each data block is an integer k, calculated as follows:

[0045] A÷p=k......d

[0046] Where A is the total number of codewords; when dividing into blocks, there can be at most two blocks with different numbers of data codewords, and the difference in the number of data codewords does not exceed 1. When the remainder d = 0, it is divided into p data blocks containing k data codewords; when d ≠ 0, it is divided into pd data blocks containing k data codewords and s data blocks containing k+1 data codewords; the number of data codewords in each data block is represented by K.

[0047] Step 1.7: Generate error correction codewords

[0048] Based on the number of data blocks p obtained in step 1.6 and the total number of codewords, data codewords and error correction capacity data (K+2e, K, e) in each data block, the data codewords are divided into p blocks, each data block includes K data codewords, and each data block is encoded using RS (Reed-Solomon) to generate error correction codewords;

[0049] Step 1.8: Arrange the graphic elements

[0050] The functional graphics, data codeword blocks, error correction codeword blocks, and the minimum blank area 4X are arranged in the graph. The functional graphics are placed in fixed positions for calculation, while the data codeword blocks and error correction codeword blocks are interspersed according to the block division. The codeword sequence starts from the lower right corner of the QR code symbol and is arranged in two vertical columns, alternating between right and left, bottom and top. The arrangement direction of the sign bits inside the codeword is the same as the arrangement direction of the codeword sequence. The highest bit of the codeword is placed in the first module position (represented by 7). If a functional graphic or boundary is encountered, it can be arranged continuously above or below the graphic, or the arrangement direction can be changed for continuous arrangement.

[0051] Step 1.9: Set the mask graphic

[0052] Use one of the eight mask patterns used in standard QR codes; select the best one using evaluation criteria.

[0053] Step 1.10: Generate format and version information.

[0054] The format information is set to 15 bits, including 5 data bits and 10 error correction bits;

[0055] Data bits: Bits 1-2 indicate the error correction level, and bits 3-5 indicate the mask pattern encoding used.

[0056] Error correction bit: The error correction bit is calculated using BCH(15,5) encoding, where the BCH code generation code is 10100110111 (0x537).

[0057] After the data bits and error correction bits form a 15-bit format information, a mask processing is performed. The 15-bit format information is XORed with the mask pattern 101010000010010 (0x5412) to obtain the final format information.

[0058] Set 46-bit version information, including 16 data bits and 30 error correction bits;

[0059] Data bits: bits 1-6 are the version number, bits 7-16 are the number of long side cells.

[0060] Error correction bits: The data bits are segmented. Bits 1-5 are calculated using BCH(15,5) encoding to obtain the error correction bits, where the BCH generation code is 10100110111 (0x537); bits 6-16 are calculated using BCH(31,11) encoding to obtain the error correction bits, where the BCH generation code is 101100010011011010101 (0x1626d5).

[0061] The final version information is 46 bits, and the version information is not masked.

[0062] Step 2: Decode the QR code into data information according to the decoding method;

[0063] The decoding method is as follows: after recognizing the position detection pattern, use BCH(15,5) and BCH(31,11) to correct and decode the version information; calculate the center coordinates of each correction pattern and position detection pattern of the version based on the version information and the number of long side modules.

[0064] Step 2 specifically involves:

[0065] Step 2.1: Obtain the symbol image;

[0066] The image is divided into dark and light modules by using the median value between the maximum and minimum values ​​of the image reflectance as the threshold.

[0067] Determine the location detection pattern; identify the rotation angle of the QR code symbol by analyzing the coordinates of the location detection pattern, and determine the original orientation of the QR code symbol;

[0068] Step 2.2: Identify and read the version information;

[0069] Use the top right corner to detect the width W of the graphic.UR Divide by 7 to calculate the module size CP. UR ; Determine the center of each module in the version information area in the upper right corner; If the data check is error-free, directly obtain the version information; If the data check is error-free, use BCH code to correct the error; If the reading fails, identify and read the version information data in the lower left corner;

[0070] Step 2.3, Correct graphic positioning

[0071] The center coordinates of the correction pattern in the QR code graphic are calculated based on the version data and length data obtained from the version information, and the sampling network is determined.

[0072] Step 2.4: Identify and read format information

[0073] The format information around the probe image at the top left corner is XORed with 101010000010010 to remove the mask; if there are no errors in the data detection, the format information is directly decoded; if there are errors in the data detection, BCH code is used to correct the errors before decoding to obtain the format information; if the detection error exceeds the error correction capacity, the format information around the probe images at the top right and bottom left corners is identified and read.

[0074] Step 2.5: Remove mask pattern

[0075] After obtaining the mask graphic information from the format information, the symbol encoding area is XORed with the mask graphic to remove the mask and restore the data codewords and error correction codewords.

[0076] Step 2.6: Identify and read data and error correction codewords.

[0077] Calculate the number and arrangement of data codewords and error correction codewords for the graphic based on the graphic size and error correction level in the version information and format information; restore the original arrangement of data codewords and error correction codewords based on the alternating permutation process used during encoding;

[0078] Step 2.7: Error correction code detection and correction.

[0079] Use RS codes for detection, verification, and error correction;

[0080] Step 2.8: Restore the information bitstream

[0081] Read the bit stream after error correction and divide the bit stream into segments according to the mode indicator and the character count indicator; a bit stream segment starts with the mode indicator and the length is determined by the character count indicator.

[0082] Step 2.9, Data Bit Stream Decoding

[0083] The data is decoded according to the pattern rules in each data bit stream to obtain the data characters and output them.

[0084] The initial selection of the graphic version number in step 1.2 is the minimum version, and it is increased sequentially according to step 1.5.

[0085] In step 1.6, when the graphics version is 2-6, the error correction capacity E is divided by the integer e (7≤e≤15), and the first divisible number is taken as the error correction capacity of a single block, with the quotient being the number of blocks n. If p≤15 and e<p, then the values ​​of e and p are swapped.

[0086] When the graphics version is 7 or above, divide the error correction capacity E by the integer e (9 ≤ e ≤ 15), and take the first divisible number as the error correction capacity of a single block. The quotient is the number of blocks. If n ≤ 15 and e < n, then swap the values ​​of e and n.

[0087] The beneficial effects of this invention are as follows: This invention proposes a high-capacity QR code encoding and decoding method that adapts to screen ratios. When a large amount of data needs to be transmitted, the data is encoded into high-capacity QR codes in stages for data stream transmission, maximizing the use of a certain screen ratio for display. The QR code encodes data according to the screen's aspect ratio, calculating the number and placement of data codeword blocks, correction symbols, and positioning symbols. Due to the high screen utilization, higher transmission efficiency than standard QR codes can be achieved after scanning. Attached Figure Description

[0088] Figure 1 This is a flowchart of the high-capacity QR code encoding and decoding process that adapts to screen ratios;

[0089] Figure 2 It features a large-capacity QR code graphic arrangement that adapts to the screen ratio (version 2-Q, screen aspect ratio 16:9);

[0090] Figure 3 It is a large-capacity QR code codeword module arrangement that adapts to the screen ratio; (a) codeword sequence arranged from bottom to top; (b) codeword sequence arranged from top to bottom; (c) codeword sequence arranged from bottom to top with adjacent functional graphics, format information or version information; (d) codeword sequence arranged from top to bottom with adjacent functional graphics, format information or version information; (e) codeword sequence changed from upward to downward arrangement; (f) codeword sequence changed from downward to upward arrangement;

[0091] Figure 4 It is a module arrangement of large-capacity QR code format information that adapts to the screen ratio;

[0092] Figure 5 The module layout is a large-capacity QR code version information that adapts to the screen ratio; (a) version information 1 is arranged in the lower left corner; (b) version information 2 is arranged in the upper right corner. Detailed Implementation

[0093] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail and completely below with reference to embodiments. It should be understood that the embodiments described herein are only some, not all, of the embodiments of this invention, and the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0094] Figure 1 Here is a flowchart of a high-capacity QR code encoding and decoding method that adapts to screen ratios, such as... Figure 1 As shown, this invention provides a method for encoding data information into a large-capacity QR code that adapts to screen ratios. The specific steps are as follows:

[0095] Step 101: Analyze the data type. Segment the data according to its type and add a 4-bit pattern indicator and a character count indicator to encode the data into a data bitstream. Concatenate all bitstreams to generate data codewords. Each codeword is 8 bits long. If there are fewer than 8 bits remaining in the data, padded with 0s. In this example, a total of B = 36 data codewords are generated.

[0096] Step 102: Obtain the aspect ratio m:n = 16:9 for the displayed portion, and divide the module using version 2, i.e., the minimum version. The number of vertical modules N = 4(C-1) + 21 = 25, and the number of horizontal modules...

[0097] Calculate the number and location of functional graphics; the center coordinates of the location detection graphics are calculated based on (3, 3), (N, 4, 3), (3, M-4) as (3, 3), (21, 3), (3, 39), and the number is W = 3 × 7 × 7; the number of positioning graphics is calculated in the vertical direction (dark color). Horizontal direction (dark color)

[0098] Calculation of horizontal direction d for correcting the figure w = (w-3g1) / (g1+1), where g1 takes positive integer values ​​such that d w (5≤d w ≤12), otherwise take g1=g1+1 and continue calculation. The calculation yields g1=1, d w Round up and down to d w1 =6,d w2 =5. Further calculation: d3 = w - 3g1 - dn1 × d w1 Where dn1 takes positive integer values, up to dn2 = d3 / d w2 If the result is an integer, otherwise take dn1 = dn1 + 1 and continue the calculation.

[0099] In this example, we calculate dn1 = 1 and dn2 = 1, meaning there is one segment with 6 dark positioning graphic modules spaced apart and one segment with 5 dark positioning graphic modules spaced apart. The center coordinates of the horizontally corrected graphic are (6, 10+2d). w The coordinates are calculated as (6, 22). Using the same method, the number and distribution of correction patterns in the vertical direction are calculated, yielding n² = 0, so no correction patterns are set in the vertical direction. The center coordinates of the correction pattern diagonally opposite the position detection pattern are (N-7, M-7), calculated as (18, 36). By combining the known center coordinates of the correction patterns, the center coordinates of the third correction pattern are obtained as (18, 22). The total number of correction patterns in the QR code pattern is calculated as g. sum = (g1+2)(g2+2)-3=3, and the center coordinates of the corrected figures are (6, 22), (18, 22), (18, 36).

[0100] The number of modules occupied by the positioning graphic, correction graphic, and fixed black module is calculated as J = 2(r + w) - 1 + 5(5g). sum -g1-g2)=107. The total number of modules occupied by functional graphics G=W+D+J+F+V=421.

[0101] Step 103: Calculate the total number of QR graphic modules S = N × MG = 654 and the total number of codewords for this version.

[0102] Step 104: Calculate the number of error correction codewords for this version and check the error correction level setting. If there are no specific requirements, calculate according to level L. In this example, the error correction level requirement is Q, so b = 25%, and the error correction capacity is calculated as follows: The number of error correction code words is R = 2E = 42.

[0103] Step 105: Select the graphic version. The number of data codewords for this version of the graphic is A = ZR = 39. Compare A and B. If A ≥ B, then use this version of the graphic for encoding; if A < B, it is unusable, and a new graphic version needs to be added. Repeat steps 102, 103, and 104, calculating and comparing the capacity of each larger version until A ≥ B. In this example, the condition A ≥ B is met, so version 2-Q can be used. Also, AB = 39 - 36 = 3, and the remaining 3 empty codewords are alternately filled with 11101100 and 00010001.

[0104] Step 106: Calculate the data codeword and error correction codeword blocks to obtain the number of blocks p and the number of codewords, data codewords and error correction capacity contained in each block, i.e. (K+2e, K, e).

[0105] Graphical versions 2-6 use the error correction capacity E divided by the integer e (7 ≤ e ≤ 15), taking the first divisible number as the error correction capacity of a single block, and the quotient as the number of blocks p. If p ≤ 15 and e < p, then the values ​​of e and p are swapped. Graphical versions 7 and above use the same method: E divided by the integer e (9 ≤ e ≤ 15), taking the first divisible number as the error correction capacity of a single block, and the quotient as the number of blocks. If p ≤ 15 and e < p, then the values ​​of e and p are swapped. E ÷ e = p, and the number of error correction codewords in the block is 2e.

[0106] The integer k is calculated using A÷p=k......d. When d=0, the data is divided into p blocks containing k data codewords; when d≠0, it is divided into pd blocks containing k data codewords and d blocks containing k+1 data codewords.

[0107] In this example, version 2-Q-16-9 calculates the number of data blocks p = 3, and the number of codewords, the number of data codewords, and the error correction capacity of each block are (27, 13, 7).

[0108] Step 107: Generate error correction codewords. Each block is encoded using Reed-Solomon (RS) codewords. The polynomial algorithm uses bitwise modulo-2 and bytewise modulo-100011101 algorithms, employing the Galois field GF(2^3)... 8 The error correction codeword generated for each block is placed after the data codeword.

[0109] Step 108: Arrange the graphic symbols, interspersing the data codewords and error correction codewords in the encoding area, and filling the remaining bits of the graphic symbol with 0s where there are fewer than 8 bits. The codeword sequence starts from the lower right corner of the QR code symbol and is arranged in vertical columns of 2 modules wide, alternating between right to left, bottom to top, and top to bottom.

[0110] The arrangement direction of the sign bit within the codeword is the same as the arrangement direction of the codeword sequence. The highest bit of the codeword is placed in the first module position (represented by 7), such as... Figure 4 Module layout within the codeword. If encountering functional graphics such as positioning or correction graphics, they can be arranged continuously, either around the graphics or above or below them. If encountering position detection graphics, upper or lower boundaries, the arrangement direction can be changed to upward or downward for continuous arrangement, such as... Figure 3 As shown.

[0111] The final codeword sequence of the version 2-Q-16-9 symbol is: D1,D14,D27,D2,D15,D28,D3,D16,D29,...D12,D25,D38,D13,D26,D39,E1,E15,E29,E2,E16,E30,E3,E17,E31,...E13,E27,E41,E14,E28,E42.

[0112] Table 1. Character arrangement in Version 2-Q-16-9 symbols

[0113]

[0114] Step 109: Set the mask pattern. Place the 8 mask patterns in the encoding area in sequence, and invert the color of the dark module corresponding to the mask pattern. Score the mask patterns that do not meet the conditions, and obtain the mask pattern with the lowest score.

[0115] Table 2 Mask Pattern Scoring

[0116]

[0117]

[0118] In the table, i represents the number of adjacent modules of the same color greater than 5, l and t represent the length and width of the block composed of modules of the same color, q represents the difference between the proportion of dark modules in the entire symbol and 50%, and the penalty weights are N1=3, N2=3, N a =40, N4=10.

[0119] In the example, the mask pattern with the lowest score, 110, is selected.

[0120] Step 1010: Generate 15-bit format information and 46-bit version information, and place them in fixed positions within the QR code symbol. The error correction level Q of the format information data is encoded as 11 in binary, and the mask pattern is encoded as 110. The error correction bits are calculated using BCH(15,5) encoding, where the BCH code generation code is 10100110111 (0x537).

[0121] Binary string: 11110

[0122] Generating polynomial: x 4 +x 3 +x 2 +x

[0123] The number of times increased to (15-5): x 14 +x 13 +x 12 +x 11

[0124] After being divided by G(x):

[0125] =(x 10 +x 8 +x 5 +x 4 +x 2 +x+1)(x 4 +x 3 )+(x9 +x 7 +x 6 +x 3 )

[0126] The formatted data string is formed by adding the coefficient characters of the residual polynomial to the 5-digit data: 111101011001000

[0127] After the data bits and error correction bits form a 15-bit format information, a mask processing is performed. The 15-bit format information is XORed with the mask pattern 101010000010010 (0x5412) to obtain the final format information 010111011011010.

[0128] Version information data version 2 is encoded as 000010, the number of long-side modules 43 is encoded as 0000101011, and the error correction bits are calculated using BCH(15,5) encoding, where the BCH generation code is 10100110111 (0x537); and the error correction bits are calculated using BCH(31,11) encoding, where the BCH generation code is 101100010011011010101 (0x1626d5). The calculation method for the version information error correction bits is the same as that for the format information. The first part yields 10 error correction bits, which is 00100110111, and the second part yields 20 error correction bits, which is 00000100110001011110. The first 16 bits are used for data encoding and the last 30 bits are used for error correction encoding, resulting in the version information 00001000001010110010011011100000100110001011110.

[0129] Step 1011: Generate a QR code and display it.

[0130] Figure 1 The bottom-up process is an adaptive proportional large-capacity QR code decoding process, such as... Figure 1 The present invention provides a method for decoding adaptive proportional large-capacity QR codes into data, the specific steps of which are as follows:

[0131] Step 201: Obtain the symbol image. Use the median value between the maximum and minimum values ​​of the image reflectance as a threshold to separate the dark and light modules of the image.

[0132] Determine the position detection pattern. The position detection pattern located at the three corners of the image consists of dark-light-dark-light-dark modules with a relative width ratio of 1:1:3:1:1. A deviation of more or less than 0.5 may occur during scanning and recognition. (a) Repeatedly detect adjacent pixel rows in the horizontal and vertical directions of the image until all pixel rows passing through the central square of the position detection pattern in both directions are identified. (b) Determine the center of the position detection pattern by finding the intersection of the midline of the outermost pixel line of the central square in both the horizontal and vertical directions. (c) Repeat steps (a) and (b) to determine the centers of the three position detection patterns. Analyze the coordinates of the position detection patterns to identify the rotation angle of the QR code symbol, thus determining the original orientation of the QR code symbol.

[0133] Step 202: Identify and read the version information.

[0134] (a) Use the top right corner to detect the width W of the graphic. UR Calculate the size CP of a single module by dividing by the number of position detection graphics modules. UR .

[0135] CP UR =W UR / 7

[0136] (b) Based on the center coordinates of the location detection graphic and the module size CP UR Determine the center of each module in the version information area in the upper right corner, and identify the dark and light modules of the image as arrays of "1" and "0".

[0137] (c) Perform data inspection. If no errors are found, directly obtain the version information; if errors are found, use BCH code to correct them.

[0138] (d) If the detection error exceeds the error correction capacity, obtain the width W of the detection pattern at the lower left corner. DL Perform steps (a), (b), and (c) to obtain the version information data in the lower left corner.

[0139] Step 203, Correction graphic positioning. Based on the version data and length data obtained from the version information, calculate the center coordinates (6, 22), (18, 22), and (18, 36) of the correction graphic in the QR code graphic, and determine the sampling network.

[0140] (a) Connecting straight lines and module size CP based on the center coordinates of the graphic detected from the top left, bottom left, and top right corners. UL The coordinates of the center of the correction figure at the top and left edges of the figure were initially determined.

[0141] (b) If a correction pattern exists on the top and left edges, start scanning the blank square outline of the correction pattern on the top and left edges from the initially determined center coordinate pixels to determine the actual center coordinates, and then proceed to step (d); if no correction pattern exists, proceed to step (c).

[0142] (c) Based on the center coordinates of the detected graphic at the top left, bottom left and top right positions, estimate the center coordinates of the corrected graphic at the diagonal position of the graphic at the top left position.

[0143] (d) Estimate the center coordinates of the nearest diagonal correction graphic of the top-left corner position graphic based on the center coordinates of the top-left corner position probe graphic (or the center coordinates of the correction graphic), the center coordinates of the top edge correction graphic obtained in (b), and the center coordinates of the left edge correction graphic (or the center coordinates of the bottom-left corner probe graphic if they do not exist).

[0144] (e) After obtaining the center coordinates of the diagonal correction pattern, the actual side length of the rectangle enclosed by the four correction patterns (or including the position detection pattern) can be known. The module size value in the grid is obtained by dividing the actual side length by the defined margin.

[0145] (f) Repeat steps (b), (d), and (e) to calculate the center coordinates of all correction figures from top left to bottom right, and calculate the module size in the grid divided by every 4 figures.

[0146] (g) Sample the image pixels in the grid, use the median between the maximum and minimum values ​​of the image reflectance as a threshold, and use the threshold to represent the dark and light modules of the image as "1" and the light modules as "0" as a binary array.

[0147] Step 204: Identify and read the format information.

[0148] (a) Perform an XOR operation on the format information around the top-left corner probe image using 101010000010010 to remove the mask.

[0149] (b) Perform format data detection. If no errors are detected, decode directly to obtain the format information; if errors are detected, use BCH code to correct errors and then decode to obtain the format information.

[0150] (c) If the detection error exceeds the error correction capacity, repeat step (b) to decode the format information around the probe graphics at the top right and bottom left corners.

[0151] Step 205: Remove the mask pattern.

[0152] After obtaining the mask graphic information from the format information, the symbol encoding area is XORed with the mask graphic to remove the mask and restore the data codewords and error correction codewords.

[0153] Step 206: Calculate data blocks, identify and read data and error correction codewords.

[0154] Based on the graphic version 2, the number of long-side modules 43, and the error correction level Q in the format information, the number and arrangement of the graphic's data codewords and error correction codewords are calculated as 3 blocks (27, 13, 7). The original arrangement of the data codewords and error correction codewords is then restored according to the alternating permutation process used during encoding.

[0155] Step 207: Error correction codeword detection and correction. RS code is used to detect, verify, and correct the bitstream.

[0156] Step 208, restore the information bitstream. Read the bitstream of the corrected data block and divide the data bitstream into segments according to the mode indicator and the character count indicator. A segment of the data bitstream begins with the mode indicator and its length is determined by the character count indicator.

[0157] Step 209, Data Bit Stream Decoding. Decode each segment of the data bit stream according to the pattern rules to obtain the final data characters and output them.

[0158] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the invention. Various changes and modifications can be made to the invention without departing from its spirit and scope, and all such changes and modifications fall within the scope of the present invention as claimed. The scope of protection of this invention is defined by the appended claims and their equivalents.

Claims

1. A method for encoding and decoding large-capacity QR codes that adapts to screen ratios, characterized in that, The steps are as follows: Step 1: Determine the number of QR code modules, position detection graphic, positioning graphic, and correction graphic positions based on the known QR code version and the aspect ratio of the display screen. Arrange the graphics according to the encoding method and generate the QR code. Step 1.1: Analyze the data type. Segment the data according to its type and add a 4-bit mode indicator and a character count indicator to encode the data into a data bit stream. Concatenate all data bit streams to generate data codewords. The number of data codewords is B. Step 1.2: Based on the aspect ratio of the display screen, divide the length and width modules according to the graphic version number C; calculate the number and coordinates of each functional graphic; the functional graphics include position detection graphics, position detection graphic separators, positioning graphics, and calibration graphics; Number of modules in the horizontal direction: Number of modules in the vertical direction: N = 4(C-1) + 21 in, This indicates the aspect ratio of the display screen, C represents the graphics version number, and 2 ≤ C ≤ 40; The center coordinates of the position detection patterns are (3, 3), (N-4, 3), and (3, M-4), respectively; the position detection pattern separator between each position detection pattern and the encoding area is one module wide, and this area is completely blank; The positioning graphics are composed of a row and a column, each 1 module wide, with alternating light and dark modules. The head and tail of each column are dark modules. The positioning graphics in the first row and the first column are merged with the position detection graphics. Number of vertically positioned graphics: Number of horizontally positioned graphics: ; All QR codes with graphic version number C have a calibration graphic set, with a fixed calibration graphic at the lower right corner (N-7, M-7); When the number of dark-colored modules in the horizontal and vertical positioning graphics exceeds the set value, additional correction graphics are set; the number of dark-colored positioning graphics separated by the correction graphics: d = (o - 3g) / (g + 1) Where o represents the number of dark-colored modules in the horizontal or vertical positioning graphics, and g represents the number of correction graphics in the horizontal or vertical direction, satisfying 5≤d≤12; the dark positioning graphics separation d calculated for the horizontal and vertical directions is represented as d w and d r The horizontal correction point is located at coordinates (6, 10+2d). w ), (6, 10+2d w +4+2d w ..., where d w When the value is a decimal, take the integer part d. w1 Or round down to the nearest integer d w2 The column coordinates of each subsequent correction plot in the horizontal direction are increased by 4 + 2d based on the column coordinates of the previous correction plot. w The vertical coordinates of the corrected graphic center are (10+2d). r ,6),(10+2d r +4+2d r ,6)...,where d r When the value is a decimal, it is rounded up to the nearest integer d. r1 Or round down to the nearest integer d r2 The row coordinates of each subsequent correction plot in the vertical direction are increased by 4 + 2d based on the row coordinates of the previous correction plot. r The coordinates of other correction patterns distributed within the coding area are a combination of the calculated horizontal and vertical coordinates of the correction patterns and the coordinates of the fixed correction pattern in the lower right corner. Step 1.3: Calculate the total number of image data bits. The formula for calculating the cell G occupied by functional graphics, formatting information, and version information is: G = W + D + J + F + V Where W represents the number of cells occupied by the position detection graphic, D represents the number of cells occupied by the position detection graphic separator, J represents the number of cells occupied by the positioning graphic and correction graphic, F represents the number of cells occupied by the format information, and V represents the number of cells occupied by the version information; After determining the total number of cells G occupied by the functional graphics, format information, and version information, calculate the total number of data bits S and the total number of codewords Z; the total number of data bits is S = N × MG, and the total number of codewords is... Step 1.4: Calculate the number of error correction code words. The error correction capacity E and the number of error correction codewords R are calculated based on the error correction capacity percentage b (%) of the error correction code version and the total number of codewords Z; R = 2E Step 1.5, Image Version Selection The number of stored data codewords is calculated based on the graphic version number C, the total number of codewords Z, and the number of error correction codewords R. A = ZR If the number of data codewords that this version of the graphic can store is A≥B, then this version of the graphic is used for encoding; if A<B, then the graphic version number is increased, and steps 1.2-1.4 are repeated to calculate and compare the capacity of larger versions of the graphic one by one until A≥B; the empty codewords that are not filled are alternately filled with 11101100 and 00010001 until all codewords are filled. Step 1.6: Divide data codewords and error correction codewords into blocks. The data codewords are divided into blocks to form data blocks, and each data block is subjected to error correction operations to generate error correction data codewords. The error correction codewords and data codewords are evenly distributed across the data blocks. The error correction capacity E is divided by the integer e, and the first divisible number is taken as the error correction capacity of a single data block. The quotient is the number of data blocks p. When p ≤ 15 and e < p, the values ​​of e and p are swapped. The number of error correction codewords in a data block is 2e. The number of data codewords in each data block is an integer k, calculated as follows: A÷p=k……d Where A is the total number of codewords; when the remainder d = 0, it is divided into p data blocks containing k data codewords; when d ≠ 0, it is divided into pd data blocks containing k data codewords and d data blocks containing k+1 data codewords; the number of data codewords in each data block is represented by K. Step 1.7: Generate error correction codewords Based on the number of data blocks p obtained in step 1.6 and the total number of codewords, data codewords and error correction capacity data (K+2e, K, e) in each data block, the data codewords are divided into p blocks, each data block includes K data codewords, and each data block is encoded using RS to generate error correction codewords; Step 1.8: Arrange the graphic elements The functional graphics, data codeword blocks, error correction codeword blocks, and the minimum blank area 4X are arranged in the graphic. The functional graphics are placed in a fixed position for calculation, and the data codeword blocks and error correction codeword blocks are interspersed according to the block division. Step 1.9: Set the mask graphic One of the eight mask patterns used in standard QR codes is adopted; Step 1.10: Generate format and version information. The format information is set to 15 bits, including 5 data bits and 10 error correction bits; Set 46-bit version information, including 16 data bits and 30 error correction bits; format information uses BCH(15,5) to generate error correction bits; version information uses BCH(15,5) and BCH(31,11) to generate error correction bits. Step 2: Decode the QR code into data information according to the decoding method; The decoding method is as follows: after recognizing the position detection pattern, use BCH(15, 5) and BCH(31, 11) to correct and decode the version information; calculate the center coordinates of each correction pattern and position detection pattern of the version based on the version information and the number of long side modules.

2. The large-capacity QR code encoding and decoding method with adaptive screen ratio according to claim 1, characterized in that, Step 2 specifically involves: Step 2.1: Obtain the symbol image; The image is divided into dark and light modules by using the median value between the maximum and minimum values ​​of the image reflectance as the threshold. Determine the location detection pattern; identify the rotation angle of the QR code symbol by analyzing the coordinates of the location detection pattern, and determine the original orientation of the QR code symbol; Step 2.2: Identify and read the version information; Use the top right corner to detect the width W of the graphic. UR Divide by 7 to calculate the module size CP. UR ; Determine the center of each module in the version information area in the upper right corner; If the data check is error-free, directly obtain the version information; If the data check finds errors, use BCH codes to correct them; If reading fails, identify and read the version information data in the lower left corner; Step 2.3, Correct graphic positioning The center coordinates of the correction pattern in the QR code graphic are calculated based on the version data and length data obtained from the version information, and the sampling network is determined. Step 2.4: Identify and read format information The format information around the probe image at the top left corner is XORed with 101010000010010 to remove the mask; if there are no errors in the data detection, the format information is directly decoded; if there are errors in the data detection, BCH code is used to correct the errors before decoding to obtain the format information; if the detection error exceeds the error correction capacity, the format information around the probe images at the top right and bottom left corners is identified and read. Step 2.5: Remove mask pattern After obtaining the mask graphic information from the format information, the symbol encoding area is XORed with the mask graphic to remove the mask and restore the data codewords and error correction codewords. Step 2.6: Identify and read data and error correction codewords. Calculate the number and arrangement of data codewords and error correction codewords for the graphic based on the graphic size and error correction level in the version information and format information; restore the original arrangement of data codewords and error correction codewords based on the alternating permutation process used during encoding; Step 2.7: Error correction code detection and correction. Use RS codes for detection, verification, and error correction; Step 2.8: Restore the information bitstream Read the bit stream after error correction and divide the bit stream into segments according to the mode indicator and the character count indicator; a bit stream segment starts with the mode indicator and the length is determined by the character count indicator. Step 2.9, Data Bit Stream Decoding The data is decoded according to the pattern rules in each data bit stream to obtain the data characters and output them.

3. The adaptive screen ratio large-capacity QR code encoding and decoding method according to claim 1 or 2, characterized in that, The position detection graphic occupies the number of cells W = 3 × 7 × 7; the position detection graphic separator occupies the number of cells D = 3 × 15; the positioning graphic and correction graphic occupies the number of cells J = 2(r + w) - 1 + 5(5g) sum -g1-g2), g sum = (g1+2)(g2+2)-3, where g1 is the number of horizontally corrected figures, g2 is the number of vertically corrected figures, and g... sum The total number of correction graphics in the symbol; the number of cells occupied by format information F = 2 × 15; the number of cells occupied by version information V = 2 × 46.

4. The large-capacity QR code encoding and decoding method with adaptive screen ratio according to claim 3, characterized in that, In step 1.2, the graphic version number is selected as the minimum version, and then increased sequentially according to step 1.5.