Encoding strategy optimization method for two-dimensional code generation
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHENGDU JIUZHOU ELECTRONIC INFORMATION SYSTEM CO LTD
- Filing Date
- 2025-04-10
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]1、编码效率低下:对于特定类型或内容特征的数据,固定的通用编码策略可能并非最优选择,导致编码后的数据长度过长
Smart Images

Figure CN120337963B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of information processing technology, and in particular to an optimization method for encoding strategies used in QR code generation. Background Technology
[0002] QR codes (Quick Response Codes), as a type of matrix barcode capable of quickly storing and retrieving information, have been widely used in numerous scenarios such as logistics tracking, mobile payment, identity verification, and information transmission. One of the core steps in generating a QR code is to convert raw data (such as text, URLs, contact information, binary data, etc.) into a data stream suitable for QR code storage using specific encoding rules.
[0003] However, existing QR code generation technologies often have limitations in their choice of encoding strategies. These technologies typically employ preset, relatively fixed encoding strategies (e.g., using UTF-8 encoding for all text data by default, or using a certain general binary encoding for all binary data by default). This "one-size-fits-all" or simple rule-based (e.g., only judging whether it is a number or a letter) encoding method may perform reasonably well when processing simple, single-type data, but its shortcomings become apparent when faced with diverse and complex data.
[0004] 1. Low encoding efficiency: For data of specific types or content characteristics, a fixed general encoding strategy may not be the optimal choice, resulting in excessively long encoded data. For example, when processing text or structured data containing a large number of repeated characters, failing to adopt a more compact representation method leads to low encoding efficiency.
[0005] 2. Wasted storage space (high redundancy): Low encoding efficiency directly leads to the generated QR code data stream containing a lot of redundant information, resulting in an increase in the size of the final generated QR code or an increase in the data capacity occupied. This not only wastes the effective storage space of the QR code, but may also increase the processing burden of scanning and recognition.
[0006] 3. Poor adaptability and decoding reliability issues in complex data scenarios: When the input data has high information entropy (such as text with strong randomness), complex data structures (such as deeply nested JSON / XML), or contains special character sets, fixed encoding strategies may be difficult to handle effectively, and may even increase the risk of data errors due to improper strategy selection, resulting in a decrease in the decoding success rate of the generated QR codes in some complex scenarios. Summary of the Invention
[0007] To address the shortcomings of the existing technologies, this invention aims to provide a method for adaptively selecting encoding strategies based on the actual characteristics of the data content (such as data type, content size, information entropy, structural complexity, character diversity, etc.), thereby improving the efficiency of QR code generation, reducing storage redundancy, and ensuring the reliability of decoding.
[0008] To achieve the above-mentioned objectives, the technical solution provided by this invention includes:
[0009] An optimization method for encoding strategies used in QR code generation includes the following steps:
[0010] Receive the raw data to be encoded;
[0011] The raw data is analyzed to determine the data type and at least one complexity index, including information entropy, structural depth, and character diversity.
[0012] Based on preset dynamic matching rules, at least one matching encoding strategy is selected from the encoding strategy library according to the data type and complexity index of the original data. The encoding strategy library contains a variety of encoding strategies for different data characteristics.
[0013] The matching encoding strategy is applied to the original data to generate QR code data and a QR code image.
[0014] Preferably, the method for determining the data type includes: using regular expressions to match predefined structured data formats; and using a neural network model to classify the raw data to identify image data and / or text data.
[0015] Preferably, after receiving the raw data to be encoded, format standardization is performed, and the format standardization method includes at least one of the following:
[0016] If the data type is image data, then the image data is converted into a Base64 encoded string;
[0017] If the data type is binary data, then a metadata header with a preset format is added to the binary data.
[0018] Preferably, the method for determining the complexity index includes:
[0019] Calculate the content size of the original data and compare the content size with a preset content size threshold;
[0020] Calculate the information entropy of the original data: Where, x i For the i-th original data, p(x) i) represents the probability of character occurrence, n represents the original data length, and the information entropy is compared with a preset information entropy threshold;
[0021] The percentage of ASCII and / or Unicode characters in the original data is calculated and compared with a preset percentage threshold.
[0022] Preferably, the method for determining the complexity index further includes:
[0023] If the data type is structured data, then the nesting level of the structured data is parsed, and the nesting level is compared with a preset level threshold.
[0024] If the data type is image data, then the resolution of the image data is obtained, and the resolution is compared with a preset resolution threshold.
[0025] Preferably, the method for updating the encoding strategy library includes: periodically obtaining candidate encoding algorithms from the encoding standard library or open source projects, and adding the encoding algorithms that meet the test requirements to the encoding strategy library after automated testing.
[0026] Preferably, the method for selecting an encoding strategy based on preset dynamic matching rules includes: using a preset decision tree model, wherein the decision tree model determines the matching encoding strategy based on the data type of the original data and a comprehensive complexity value calculated according to preset weights.
[0027] Preferably, the matching encoding strategy includes a combination of multiple encoding strategies, and the combination conditions for the multiple encoding strategies include: no execution conflict between the encoding strategies, and the expected total execution time T of the combination of multiple encoding strategies. total Satisfy: T total ≤α×min(T1,T2,…,T m ), where α is a preset constant, T m The expected execution time for each coding strategy when executed individually.
[0028] Beneficial effects
[0029] 1. Significantly Improved Encoding Efficiency: This invention performs multi-dimensional and quantitative analysis of the input raw data (including data type identification, information entropy calculation, structural depth analysis, character diversity statistics, etc.), enabling precise understanding of the data's content characteristics and complexity. Based on these analysis results, it dynamically selects the most suitable encoding strategy or strategy combination from a strategy library containing multiple optimization strategies. This avoids the inefficiency of fixed strategies in existing technologies, especially when processing mixed-type data or data with specific structural characteristics, enabling the adoption of targeted and efficient encoding methods, thereby significantly improving encoding efficiency.
[0030] 2. Effectively reduces storage redundancy and achieves more compact data representation: By intelligently matching the optimal encoding strategy for different data, this invention can generate more concise and compact QR code data streams. For example, using more space-saving encoding for short text and applying key-value compression to structured data effectively reduces unnecessary redundant information. This allows for the generation of smaller QR codes or QR codes with lower data capacity requirements while storing the same amount of information, saving storage media and transmission bandwidth.
[0031] 3. Enhanced decoding reliability in complex data scenarios: For data with high complexity, high randomness, or containing special formats, this invention can select an encoding strategy that better guarantees data integrity, has a better fault tolerance, or is more suitable for the complexity based on quantitative analysis results. This avoids decoding difficulties or error risks introduced by inappropriate strategies, significantly improving the decoding success rate and stability of QR codes in complex application scenarios.
[0032] 4. Improved automation and intelligence of the coding process: This invention automates the data analysis, complexity assessment and strategy selection process, and makes decisions based on quantitative data indicators and preset dynamic matching rules (such as decision tree models), reducing the need for manual intervention and subjective judgment, and improving the intelligence of the QR code generation process and its universality and robustness to diverse input data. Attached Figure Description
[0033] Figure 1 This is a schematic diagram of a method for optimizing encoding strategies for QR code generation provided in a preferred embodiment of the present invention. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described below with reference to the accompanying drawings. In the description of this invention, it should be understood that the terms "upper," "lower," "front," "rear," "left," "right," "top," "bottom," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention.
[0035] like Figure 1 As shown, this invention provides an encoding strategy optimization method for QR code generation, including the following steps:
[0036] S1. Receive the raw data to be encoded.
[0037] The raw data is the information carrier that will eventually be encoded and presented as a QR code image. Its specific content determines the basis for subsequent analysis and strategy selection. It includes, but is not limited to, text strings (containing different character sets such as ASCII and Unicode), URLs, structured data (such as JSON, XML, and other data with hierarchical and key-value pair characteristics), and even image data (which can be raw pixel information, compressed format, or text representation such as Base64 encoded text) and any binary data stream.
[0038] S2. Analyze the raw data to determine the data type and at least one complexity index, the complexity index including information entropy, structural depth and character diversity.
[0039] Determining the data type refers to identifying whether the data belongs to a predefined category such as text, image, binary stream, or structured data (e.g., JSON, XML). This lays the foundation for subsequent selection of appropriate analysis methods and encoding strategies. For example, image data and text data may require drastically different processing logics and complexity evaluation dimensions. Existing technologies typically rely on encoding modes defined in the QR code standard to indirectly infer or restrict data types. In some preferred embodiments, a deeper, more accurate, and finer-grained type identification method is provided, offering a solid and reliable foundation for subsequent targeted complexity analysis and encoding strategy optimization. Specifically, this includes:
[0040] The method for determining the data type includes:
[0041] S21. Use regular expressions to match predefined structured data formats. For example, JSON data has its own rules for using parentheses, quotation marks, colons, and commas, while XML has tag pairs and attribute definitions. By designing matching regular expressions, you can efficiently and accurately determine whether the input data belongs to these specific structured types.
[0042] S22. A neural network model is used to classify the raw data to identify image data and / or text data. The neural network, by learning the features of a large number of samples, can capture subtle statistical differences between different data types, and can perform effective classification even when the data is complex or contains noise. The specific implementation can be flexibly selected by those skilled in the art based on existing technology, and this invention does not impose further limitations.
[0043] The above steps combine rule-driven and data-driven strategies, enabling the present invention to have high flexibility, accuracy, and adaptability to diverse data inputs in the key step of data type determination, laying a solid foundation for subsequent differentiated complexity analysis and coding strategy selection.
[0044] Determining the data type and complexity metrics constitutes a multi-layered understanding of the characteristics of the original data, ensuring that the selected encoding strategy truly matches the data's characteristics. Complexity metrics are a series of calculable measures used to quantify the inherent characteristics, structure, or information content complexity of the original data. Existing technologies often neglect the characteristics of these metrics, relying solely on basic data type judgments or employing fixed, pre-defined encoding strategies to apply the same standard encoding to a particular type of data without considering its actual internal characteristics. This is one of the reasons for low encoding efficiency, high redundancy, and poor adaptability to complex data.
[0045] Information entropy, in information theory, is an indicator that measures the randomness or uncertainty of an information source. It is used to quantify the degree of randomness or compressibility of the original data content. High information entropy means that the data tends to be random, contains fewer predictable patterns or repetitions, and has little compression potential (e.g., encrypted data, random number sequences). Low information entropy indicates that the data has more regularity, repetition, or patterns, and is easier to compress (e.g., repetitive text strings, simple text structures).
[0046] Structure depth refers to the maximum depth of nesting levels in structured data (such as JSON and XML). For example, a simple JSON object {"a":1,"b":2} has a shallow structure depth, while a complex JSON object such as {"a":{"b":{"c":[1,2]}}} has a deep structure depth. A greater structure depth generally indicates more complex data relationships, which may require more resources for parsing and processing, and may also affect the efficiency or applicability of certain encoding strategies (such as path-based compression).
[0047] Character diversity measures the richness of different character types that make up raw data (especially text data). It can be expressed as the total number of different characters, or the proportion of characters from a specific character set (such as different blocks in ASCII or Unicode). High character diversity means that the data contains a mixture of various character types (such as uppercase and lowercase letters, numbers, multiple symbols, and scripts from multiple languages). Low character diversity indicates that the data is mainly composed of a limited number of characters (such as pure numbers or pure lowercase letters).
[0048] In some preferred embodiments, a specific computational process for quantifying the complexity of the original data is provided, including:
[0049] The size of the original data is calculated and compared with a preset content size threshold. This step determines the volume of the original data.
[0050] Calculate the information entropy of the original data: Where, x i For the i-th original data, p(x) i ) represents the probability of character occurrence, n represents the original data length, and the information entropy is compared with a preset information entropy threshold to determine whether the data is highly structured and highly repetitive (low entropy), or close to random and difficult to compress (high entropy).
[0051] The proportion of ASCII and / or Unicode characters in the original data is statistically analyzed, and the proportion is compared with a preset proportion threshold to evaluate the complexity of the original data in terms of character composition.
[0052] The aforementioned preset thresholds (content size threshold, information entropy threshold, character ratio threshold) are boundary points for subsequent decision-making, designed to distinguish different data characteristic ranges so that the optimal strategy can be selected based on these distinctions. Specifically, they can be set or adjusted by those skilled in the art based on their professional knowledge and practical experience in this field, or the optimal results can be obtained through experiments. This part is not the focus of this invention and will not be elaborated here.
[0053] This embodiment compares the calculated complexity index with a preset threshold. The comparison result (e.g., "greater than / equal to the threshold" or "less than the threshold") directly determines the qualitative judgment of the characteristics of the current original data. Its specific significance lies in transforming quantitative data analysis into specific and actionable decision signals. It is a key bridge connecting data understanding (S2) and strategy selection (S3), ensuring that the selection of encoding strategy is based on an objective assessment of the inherent complexity of the data, thereby achieving the final optimization goal.
[0054] In other preferred embodiments, in order to dynamically select a specific indicator that best reflects the core complexity of the identified data type, the method for determining the complexity indicator further includes:
[0055] If the data type is structured data, the nesting level of the structured data is parsed, and the nesting level is compared with a preset level threshold. By calculating this level number and comparing it with the preset level threshold, it is determined whether the structured data is flat and simple or deeply nested and complex in relationship.
[0056] If the data type is image data, the resolution of the image data is obtained and compared with a preset resolution threshold to evaluate the size and detail of the image data. This is directly related to the size after converting it into a byte stream suitable for QR code storage (such as through Base64 encoding), and whether preprocessing is needed before encoding (such as adjusting the size or changing the compression rate) to adapt to the capacity limitations of QR codes or optimize the final scanning experience.
[0057] S3. Based on preset dynamic matching rules, according to the data type of the original data and the complexity index, select at least one matching encoding strategy from the encoding strategy library, which contains a variety of encoding strategies for different data characteristics.
[0058] The dynamic matching rule determines the decision result (i.e., which encoding strategy to choose) based on the characteristics (data type and complexity index) of the real-time input and changing raw data. Specifically, a preset decision tree model can be used. This decision tree model determines the matching encoding strategy based on the data type of the raw data and a comprehensive complexity value calculated according to preset weights. A decision tree is a supervised learning algorithm widely used in classification and regression tasks. Its structure is similar to a flowchart, where each internal node represents a test of an attribute (or feature), each branch represents the test result, and each leaf node represents the final decision result or classification label. In the context of this invention, this decision tree is specifically designed and trained to perform the task of selecting encoding strategies. Its specific design and training methods can be implemented by those skilled in the art as needed, and this invention does not further limit them.
[0059] The encoding strategy library refers to a pre-built collection containing various encoding strategies (algorithms or methods). It includes various technical solutions for converting raw data into a data stream suitable for QR code generation, including but not limited to: basic encoding modes of the QR code standard, data compression algorithms, data representation optimization, format conversion strategies, and error correction level selection strategies. In some preferred embodiments, to ensure the encoding strategy library has the ability to continuously evolve and self-improve, and to ensure that it always contains the currently optimal or effective encoding strategies, a programmatic and sustainable encoding strategy library update method is provided. This includes: periodically obtaining candidate encoding algorithms from the encoding standard library or open-source projects, and adding encoding algorithms that meet the test requirements to the encoding strategy library after automated testing. The automated testing includes, but is not limited to, multiple dimensions such as encoding efficiency (compression ratio), execution speed, resource consumption (CPU, memory), correctness (lossless encoding and decoding), robustness (ability to handle abnormal data), and compatibility with other strategies in the existing library. Only encoding algorithms that successfully pass all tests and meet the preset performance and reliability requirements will be finally confirmed as effective and officially added to the encoding strategy library.
[0060] It should be understood that this invention can not only select a single optimal strategy from the strategy library, but also construct and select strategy combinations or strategy chains composed of multiple different strategies, in order to achieve better coding effects that a single strategy cannot achieve. In some preferred embodiments, the selection of strategies must at least meet the following conditions: there are no execution conflicts between the coding strategies, and the expected total execution time Ttotal of the combination of multiple coding strategies satisfies: Ttotal ≤ α × min(T1, T2, ..., Tm), where α is a preset constant, and Tm is the expected execution time of each coding strategy when executed individually. The absence of execution conflicts between coding strategies means that the multiple strategies combined must be compatible with each other, able to execute smoothly in a predetermined order (either in parallel or sequentially), and the subsequent strategy must correctly process the output of the previous strategy, without logical contradictions, data format mismatches, or mutual interference leading to execution failure. The expected total execution time of the strategy combination is limited to the expected execution time of the strategy with the shortest (i.e., fastest) execution time among all the individual strategies considered for combination. The preset constant α is typically greater than or equal to 1, setting a performance tolerance relative to the fastest single strategy. For example, if α = 1.2, it means the total execution time of the combined strategies can be up to 20% slower than the fastest single strategy. This time constraint ensures that even when using multiple strategies to pursue better coding quality, the coding process will not become excessively slow, thus achieving a reasonable balance between optimization effectiveness and execution efficiency. Therefore, this mechanism allows the invention to explore more complex optimization paths while ensuring that the selected strategy combinations are both powerful and practical through rigorous compatibility and performance threshold screening.
[0061] S4. Perform the matching encoding strategy on the original data to generate QR code data and generate a QR code image.
[0062] The QR code data refers to a binary data stream or byte sequence that has been processed by the selected encoding strategy and conforms to the QR code standard. It typically contains encoded user data, necessary mode indicators, length indicators, and crucial error correction codes (ECC). These ECC codes are generated according to the selected error correction level to ensure the QR code can still be read correctly even when partially damaged. Then, according to the QR code layout rules (including version information, format information, positioning patterns, correction patterns, timing patterns, and other fixed elements), it is filled into a two-dimensional matrix, and an optimal mask pattern is applied to optimize the image's scannability. Finally, the rendered output is the square QR code graphic composed of black and white squares (modules) that can be directly recognized by scanning devices.
[0063] 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 optimizing encoding strategies for QR code generation, characterized in that, Including the following steps: Receive the raw data to be encoded; The raw data is analyzed to determine the data type and at least one complexity index, including information entropy, structural depth, and character diversity. Based on preset dynamic matching rules, at least one matching encoding strategy is selected from the encoding strategy library according to the data type and complexity index of the original data. The encoding strategy library contains a variety of encoding strategies for different data characteristics. The matching encoding strategy is applied to the original data to generate QR code data and a QR code image; The methods for determining the complexity index include: Calculate the information entropy of the original data: ;in, For the i-th original data, The probability of character occurrence is given, n is the original data length, and the information entropy is compared with a preset information entropy threshold. The proportion of ASCII and / or Unicode characters in the original data is calculated and compared with a preset proportion threshold. The method for determining the complexity index also includes: If the data type is structured data, then the nesting level of the structured data is parsed, and the nesting level is compared with a preset level threshold. If the data type is image data, then the resolution of the image data is obtained, and the resolution is compared with a preset resolution threshold; The method for selecting an encoding strategy based on preset dynamic matching rules includes: using a preset decision tree model, wherein the decision tree model determines the matching encoding strategy based on the data type of the original data and a comprehensive complexity value calculated according to preset weights.
2. The encoding strategy optimization method for QR code generation as described in claim 1, characterized in that, The method for determining the data type includes: using regular expressions to match predefined structured data formats; and using a neural network model to classify the raw data to identify image data and / or text data.
3. The encoding strategy optimization method for QR code generation as described in claim 1, characterized in that, After receiving the raw data to be encoded, format standardization is performed. The format standardization method includes at least one of the following: If the data type is image data, then the image data is converted into a Base64 encoded string; If the data type is binary data, then a metadata header with a preset format is added to the binary data.
4. The encoding strategy optimization method for QR code generation as described in claim 1, characterized in that, The method for updating the encoding strategy library includes: periodically obtaining candidate encoding algorithms from the encoding standard library or open source projects, and adding the encoding algorithms that meet the test requirements to the encoding strategy library after automated testing.
5. The encoding strategy optimization method for QR code generation as described in claim 1, characterized in that, The matching encoding strategy includes a combination of multiple encoding strategies. The combination conditions for the multiple encoding strategies include: there is no execution conflict between the encoding strategies, and the expected total execution time T of the combination of multiple encoding strategies is [not specified]. total Satisfy: T total ≤α×min(T1,T2,...,T m ), where α is a preset constant, T m The expected execution time for each coding strategy when executed individually.
Citation Information
Patent Citations
Data storage method based on lossless compression algorithm
CN119543957A