A topological coding-based stylable anti-deformation two-dimensional code encoding and recognition method

By generating stylized, deformation-resistant QR codes based on topological coding, the problems of insufficient visual design and deformation resistance of traditional QR codes are solved, achieving high recognition rate and flexible application in complex environments.

CN122366486APending Publication Date: 2026-07-10NANJING TECH UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NANJING TECH UNIV
Filing Date
2026-03-27
Publication Date
2026-07-10

Smart Images

  • Figure CN122366486A_ABST
    Figure CN122366486A_ABST
Patent Text Reader

Abstract

This invention provides a stylizable and deformation-resistant QR code encoding and recognition method based on topological coding, comprising: converting the binary string to be encoded into natural numbers using a bijective function and recursively decomposing it to generate a topological tree structure; determining the spatial allocation ratio based on the tile traces of each node in the topological tree; performing inward shrinking processing on the polygonal region carrying the QR code, recursively dividing it into non-overlapping closed sub-regions according to the ratio, mapping the hierarchical structure of the topological tree to a QR code with a nested structure and stylizing it; scanning the QR code image and performing preprocessing, extracting the boundary contours of the closed regions and constructing a global topological tree, enumerating multiple candidate topological trees and decoding them one by one, and filtering out the valid binary information as the recognition result after CRC verification. This invention achieves the deformation resistance of the QR code through the mapping of the topological tree structure and nested regions, and improves its visual effect and application flexibility through stylization processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the technical field of computer graphics and artificial intelligence, and in particular relates to a stylizable and deformation-resistant QR code encoding and recognition method based on topological coding, which can be used in scenarios such as information storage, item identification, security monitoring and commercial promotion. Background Technology

[0002] QR codes, as a graphic encoding technology integrating high-density information storage and rapid machine recognition, are widely used in commercial retail, logistics warehousing, and public services due to their advantages such as strong information carrying capacity, low generation cost, and convenient recognition. From electronic vouchers for daily payments to traceability labels on product packaging, from unlocking mediums for shared transportation to health authentication for epidemic prevention and control, QR codes have become a crucial information exchange and identity authentication portal in modern society. Currently, the mainstream QR code on the market encodes binary information by arranging black and white square modules within a rectangular matrix, and relies on standardized positioning patterns and other structures to ensure universal readability.

[0003] However, traditional QR codes have limitations in terms of visual design flexibility. Firstly, their visual presentation is highly homogenized, with a core form being a densely packed array of black and white squares. Artistic modifications for brand image, aesthetics, or cultural and creative needs—such as adjusting module shapes, incorporating brand logos, or changing color schemes—easily disrupt their core identification structure, leading to a significant drop in scanning success rate. Relevant market research data shows that when the visual modification of a QR code exceeds 15%, the recognition success rate of mainstream mobile scanning software can plummet from 99% to less than 50%; when the modification reaches 30% to adapt to packaging design, the recognition success rate is essentially zero. This severely limits the application of traditional QR codes in scenarios such as product packaging, cultural derivatives, and art advertising, where high visual design is required.

[0004] Secondly, traditional QR codes have weak resistance to deformation and interference. Their decoding mechanism is highly dependent on the absolute geometric position and grayscale contrast of the modules in the encoded image. When the QR code carrier undergoes physical deformation such as bending, wrinkling, or stretching, or is in an environment with uneven lighting, tilted viewing angle, or partial occlusion, the geometric shape and spatial relationship of the modules are easily disrupted, leading to decoding failure. For example, in the field of flexible electronics, when QR codes are printed on fabric carriers, even slight stretching (deformation amplitude of about 10%) can reduce the recognition success rate by more than 60%; on curved products such as ceramic cups and metal cans, the recognition failure rate of QR codes due to perspective distortion is as high as 75%. According to industry statistics, more than 40% of QR code application failures are due to carrier deformation or environmental interference, and this problem is particularly prominent in emerging application scenarios such as flexible packaging, smart wearable devices, and curved industrial products.

[0005] While existing technologies attempt to optimize the aforementioned shortcomings, none have broken through the fundamental constraints of traditional encoding mechanisms. For example, artistic QR code generation methods based on image fusion essentially overlay visual effects or modify non-critical modules on top of the QR code, without changing its reliance on fixed module array encoding, still requiring a trade-off between visual performance and recognition reliability. Schemes based on specific topological markers (such as Seedmarkers) have a certain resistance to deformation, but their marker unit shapes are fixed, design adaptability is poor, and information capacity is usually less than 100 bits, making it difficult to meet general encoding needs. Style transfer methods based on deep learning (such as QRCode Art) mainly optimize visual appearance, but their recognition performance is not fundamentally improved compared to traditional QR codes when dealing with physical deformation. While information hiding techniques (such as StegaStamp) can avoid the interference of QR code graphics on the design, they require dedicated decoding equipment, have poor versatility, and are difficult to adapt to mass consumer scenarios.

[0006] With the rapid development of industries such as flexible electronics, smart packaging, and cultural and creative industries, the market demand for QR codes has evolved from simply carrying information to a complex technological requirement that integrates stylized design, stable reading capabilities, and broad media compatibility. Traditional QR codes and their existing optimization solutions cannot fully meet this demand. Summary of the Invention

[0007] The purpose of this invention is to address the inherent contradiction between visual customization and reliable machine reading in QR code technology, as well as its technical bottlenecks in carrier adaptability and environmental robustness. It proposes a stylizable, deformation-resistant QR code encoding and recognition method based on topological coding. This method directly encodes information into a topological tree structure and combines polygon partitioning and recursive geometric encapsulation to achieve QR encoding under conditions of strong deformation, complex embedding, and high stylization. Compared to traditional QR codes and barcodes, it significantly improves the robustness and reliability of recognition in complex environments such as bending, stretching, occlusion, and projection distortion, balancing visual freedom and information carrying capacity, and possessing stronger engineering applicability and promotional value.

[0008] The technical solution of this invention is: This invention provides a stylizable and deformation-resistant QR code encoding and recognition method based on topological coding, comprising: Step 1: Convert the binary string to be encoded into a natural number using a bijective function, and recursively decompose the natural number based on the four-square sum theorem to generate a topological tree structure; Step 2: Determine the spatial allocation ratio based on the tile traces of each node in the topology tree; perform inward shrinking processing on the polygonal region carrying the QR code, recursively divide it into non-overlapping closed sub-regions according to the ratio, map the hierarchical structure of the topology tree to a QR code with a nested structure, and perform stylization processing to generate a stylized QR code graphic. Step 3: Scan the stylized QR code image and preprocess it, extract the boundary contour of the closed area and construct a global topology tree, enumerate multiple candidate topology trees and decode them one by one to obtain binary information, and after CRC verification, select the valid binary information as the recognition result.

[0009] Further, step 1 includes: Step 1.1: Preprocess the input binary string to be encoded, remove invalid characters through format validation, and if the length of the string after format validation does not reach the preset minimum threshold, pad the end of the string with 0 to the preset minimum threshold length. Step 1.2: Perform a high-order bit-major conversion on the preprocessed binary string using the following bijective function to obtain the natural number N. ; in, b The input binary string, L The length of the binary string. i This is the number of digits representing the length of the string. b i For the string number i The binary value of a bit, either 0 or 1; N for na The natural number output by the function; Step 1.3: Convert the natural numbers obtained in Step 1.2 N As the value corresponding to the root node of the topological tree, the natural number is decomposed into squares, that is... N It is represented as the sum of several square numbers, with each square number corresponding to a node. The node is hierarchically associated with the root node. The square number decomposition is repeated for each node, and the child nodes of the node are generated layer by layer until the corresponding value can no longer be decomposed into a non-zero square number. The binary information is encoded through the above decomposition process to obtain the topological tree structure representing the binary information.

[0010] Further, step 2 includes: Step 2.1: Calculate the tile trace F of each node in the topology tree, and determine the spatial allocation ratio R of each child node accordingly; Step 2.2: Determine the original two-dimensional region that carries the topology and define it as a polygonal region. Its boundary is formed by a sequence of vertices P arranged in sequence. Perform shrinkage processing on the polygonal region and generate a shrinkage region according to the shrinkage function while keeping the original topological relationship unchanged. Step 2.3: Within the shrinking region, based on the tile traces and spatial allocation ratio R corresponding to each node in the topology tree obtained in Step 2.1, the shrinking region is divided into several non-overlapping closed sub-regions; the closed sub-regions are assigned to the corresponding child nodes for subsequent recursive geometric generation of the child nodes and their lower-level topology. Step 2.4: Using the closed sub-region generated in Step 2.3 as the new parent region, recursively execute Step 2.2 and Step 2.3 to map the hierarchical structure in the topology tree to a nested structure layer by layer until all nodes have completed their geometric construction, generating a QR code with a nested structure. Step 2.5: For each closed sub-region in the nested structure, the user customizes the stylized form of each node or sub-node corresponding to the closed sub-region to obtain a stylized QR code graphic.

[0011] Further, in step 2.1, the tile trace F of each node in the topology tree is calculated using the following formula. The tile trace value is the sum of the number of the node itself and all its child nodes, and the spatial allocation ratio R of each child node is determined accordingly. ; in, n Indicates the node number. Nod n For its first n 1 node m For the current node n The total number of child nodes, a This is the child node number of the current node. Nod a For its first a Number of child nodes F ( Nod n ) is for nodes Nod n The trace of the subtree rooted at the root; R ( Nod a ) indicates the first a Each child node is in its parent node Nod n The area proportion of a region is such that nodes with larger map traces are allocated a larger area. In step 2.2, the contraction function uses the following formula: ; in, d This is the inward shrinkage distance, with a default value of d=1 pixel. p Let be the coordinates of the polygon's vertices. for p The point points to the unit normal vector inside the polygon.

[0012] Furthermore, in step 2.5, the stylized form includes color, fill texture, and carrier shape, and the carrier shape includes concave and convex shapes.

[0013] Further, in step 3, the scanning of the stylized QR code image and preprocessing it to extract closed contours and establish hierarchical relationships includes: Step 3.1: Perform grayscale conversion, noise reduction, and binarization on the stylized QR code input image obtained by scanning; Identify the boundary contours of all closed regions in all binarized images, and construct a global region hierarchy, i.e., a global topology tree, based on the spatial inclusion relationships between regions.

[0014] Further, in step 3, the process of enumerating multiple candidate topology trees and decoding them one by one to obtain binary information includes: Step 3.2: Traverse all nodes of the global topology tree, and select nodes whose number of descendant nodes exceeds a preset threshold, for example, a threshold of 10, as candidate root nodes; extract the corresponding subtrees of each candidate root node to construct a set of candidate topology trees; where the candidate topology tree represents the topological structure dependency between nested regions and is used as the input for decoding. Step 3.3: For each candidate topology tree obtained in Step 3.2, perform reverse decoding according to the recursive decomposition rules adopted in Step 1 to obtain the binary information of each candidate topology tree as the decoding result.

[0015] Further, in step 3.3, the reverse decoding includes: The hierarchical relationship of the candidate topology tree nodes is mapped to the square number during encoding. Starting from the root node, the child nodes are decoded from top to bottom, and the corresponding values ​​of the nodes are restored. The natural numbers of the candidate topology tree are obtained by combining the values ​​of the nodes at each level. According to the bijective function used in the encoding stage, natural numbers are converted into corresponding binary information, which is used as the decoding result of the candidate topology tree.

[0016] Furthermore, in step 3, the step of filtering out valid binary information as the identification result after CRC verification includes: Step 3.4: Perform Cyclic Redundancy Check (CRC) on the decoded binary information of each candidate topology tree; ; in, da This is the decoded binary byte stream. x This indicates the position of the binary bit; if the check value is 0, the binary information is considered valid. Step 3.5: When the verification is passed, the candidate topology tree is determined to be a valid code, and its corresponding binary information is used as the final recognition result; when the verification result fails, the candidate topology tree is determined to be invalid noise, and its decoded binary information is discarded.

[0017] Furthermore, the method also includes step 4: constructing an optimization function that integrates multiple types of losses, generating different types of QR codes and verifying the effectiveness of decoding, and iteratively optimizing the parameters until the convergence condition is met; wherein, the optimization function is based on the footprint relative error. L fp Absolute error in area ratio L area Log loss of decoding probability L rec The following formula is used; ; in: , The loss weights are used to balance the losses of each component; the relative error of the footprint is used to constrain the spatial occupancy of the topology tree, i.e., the fit between the tile trace F and the length of the binary string to be encoded; the absolute error of the area ratio... L area Used to constrain the consistency between the spatial allocation ratio of child nodes and the corresponding node's graph trace ratio, decoding probabilistic logarithmic loss. L rec Used to constrain deviations in encoding and reverse decoding.

[0018] The beneficial effects of this invention are: This invention maps data into QR code graphics of nested regions by constructing a topology tree structure and introduces stylization processing to improve the visual effect. At the same time, it uses multi-candidate topology tree decoding and cyclic redundancy check mechanism to ensure a high recognition rate under deformation or interference.

[0019] This invention integrates multiple types of losses through an optimization function and iteratively adjusts parameters to adapt to different scenario requirements. For example, in complex environments, it increases the indentation distance and the thickness of boundary lines to enhance anti-interference capabilities.

[0020] This invention achieves highly robust QR code recognition and personalized presentation in diverse scenarios, significantly improving its practicality and application flexibility.

[0021] Other features and advantages of the present invention will be described in detail in the following detailed description section. Attached Figure Description

[0022] The above and other objects, features and advantages of the present invention will become more apparent from the more detailed description of exemplary embodiments of the invention in conjunction with the accompanying drawings, wherein the same reference numerals generally represent the same components in the exemplary embodiments of the invention.

[0023] Figure 1 The diagram shows the architecture of the stylizable and deformation-resistant QR code encoding and recognition method based on topological coding of the present invention.

[0024] Figure 2 A flowchart of the stylizable and deformation-resistant QR code encoding and recognition method based on topological coding of the present invention is shown.

[0025] Figure 3 The diagram shows the framework of the topology tree structure generated in step 1 of the present invention.

[0026] Figure 4 The diagram shows the framework of generating stylized QR code graphics in step 2 of the present invention.

[0027] Figure 5 The diagram shows the architecture of the scanning and recognition in step 3 of the present invention.

[0028] Figure 6 A stylized QR code graphic schematic diagram is shown according to an embodiment of the present invention. Detailed Implementation

[0029] Preferred embodiments of the invention will now be described in more detail with reference to the accompanying drawings. While preferred embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be limited to the embodiments set forth herein.

[0030] like Figure 1 , 2 As shown, this invention provides a stylizable, deformation-resistant QR code encoding and recognition method based on topological coding. This method achieves QR code deformation resistance through mapping of topological tree structures and nested regions, and enhances its visual effect and application flexibility through stylization processing. The following will describe the complete process from encoding, mapping, stylization to recognition, covering various possible implementation methods and application scenarios.

[0031] Step 1: Convert the binary string to be encoded into a natural number using a bijective function, and recursively decompose the natural number based on the four-square theorem to generate a topological tree structure.

[0032] like Figure 3As shown, this step is the starting point of the entire encoding process, transforming the raw data into a hierarchical, structured representation in a mathematical way, laying the foundation for subsequent spatial mapping and stylization processing. It should be noted that binary strings typically originate from user-input data, such as product numbers, website links, or identification information. Encoding this information in the form of a topological tree makes it easy to recognize.

[0033] Step 1.1: Preprocess the input binary string to be encoded, remove invalid characters through format validation, and if the length of the string after format validation does not reach the preset minimum threshold, pad the end of the string with 0 to the preset minimum threshold length.

[0034] In one embodiment, assuming the user inputs a binary string of 101101, but the system requires a minimum length of 8 bits, zeros will be added to the end of the string, resulting in 10110100. Format validation mainly screens for non-binary characters that may exist in the input. If illegal characters such as letters or symbols are found, they will be removed or the user will be prompted to re-enter the string, ensuring the smooth progress of subsequent conversion processes and also providing a guarantee for data standardization.

[0035] Step 1.2: Perform a high-order bit-first conversion on the preprocessed binary string using a specific bijective function to obtain natural numbers.

[0036] ; in, b The input binary string, L The length of the binary string. i This is the number of digits representing the length of the string. b i For the string number i The binary value of a bit, either 0 or 1; N for na The natural number output by the function.

[0037] A bijective function is a reversible mapping method that ensures a one-to-one correspondence between binary strings and natural numbers, thus preventing information loss during encoding and decoding. In one embodiment, assuming the preprocessed binary string is 11010110 with a length of 8 bits, each bit's binary value is multiplied by its corresponding bit weight and summed to obtain a unique natural number. This natural number will serve as the root node value for subsequent topological tree construction. This conversion method is not only simple and efficient but also guarantees the uniqueness and reversibility of the data, providing a reliable foundation for subsequent decomposition and encoding.

[0038] Step 1.3: Take the natural numbers obtained in Step 1.2. NAs the value corresponding to the root node of the topological tree, the natural number is decomposed into squares, that is... N It is represented as the sum of several square numbers, with each square number corresponding to a node. The node is hierarchically associated with the root node. The square number decomposition is repeated for each node, and the child nodes of the node are generated layer by layer until the corresponding value can no longer be decomposed into a non-zero square number. The binary information is encoded through the above decomposition process to obtain the topological tree structure representing the binary information.

[0039] Specifically, square number decomposition is a recursive decomposition method based on the four-square sum theorem. Its purpose is to progressively break down a large natural number into multiple smaller values ​​and represent the hierarchical relationship between these values ​​using a tree structure. In one embodiment, assuming the root node is the natural number 30, it can be decomposed into 25 + 4 + 1, where 25, 4, and 1 each correspond to three child nodes. The value 25 can be further decomposed into 16 + 9, and so on, until it cannot be decomposed further. In this way, a topological tree structure is formed from the root node to the leaf nodes, where each node represents a value, and the connections between nodes reflect the hierarchical order of the decomposition. This structure allows the hierarchical relationship of the topological tree to be preserved even when the QR code image undergoes a certain degree of deformation, thanks to the nested region relationships.

[0040] Step 2: Determine the spatial allocation ratio based on the tile traces of each node in the topology tree; perform inward shrinking processing on the polygonal region carrying the QR code, recursively divide it into non-overlapping closed sub-regions according to the ratio, map the hierarchical structure of the topology tree to a QR code with a nested structure, and perform stylization processing to generate a stylized QR code graphic.

[0041] like Figure 4 As shown, this step is the core part of the encoding process, which is used to transform the mathematical topological tree structure into a visual QR code graphic, while improving its aesthetics and application adaptability through stylization.

[0042] Step 2.1: Calculate the tile trace of each node in the topology tree. F Based on this, the space allocation ratio R of each child node is determined.

[0043] ; in, n Indicates the node number. Nod n For its first n 1 node m For the current node n The total number of child nodes, a This is the child node number of the current node. Nod a For its first a Number of child nodesF ( Nod n ) is for nodes Nod n The trace of the subtree rooted at the root; R ( Nod a ) indicates the first a Each child node is in its parent node Nod n The area percentage of the region.

[0044] Specifically, the tile trace is an indicator reflecting the size of a node and its subtree, defined as the sum of the number of the node itself and all its child nodes. By calculating the tile trace, a corresponding space proportion can be allocated to each node; the larger the tile trace, the larger the area allocated to the node. In one embodiment, assuming the tile trace of the root node of the topology tree is 10, one child node has a tile trace of 6, and another child node has a tile trace of 3, then the space allocation proportions for these two child nodes are 6:10 and 3:10, respectively, i.e., 60% and 30%. This allocation ensures that the space partitioning matches the importance distribution of the topology tree structure, avoiding the problem of small-scale nodes occupying too much space or large-scale nodes having insufficient space.

[0045] Step 2.2: Determine the original two-dimensional region that carries the topology and define it as a polygonal region. Its boundary is formed by a sequence of vertices P arranged in sequence. Perform shrinkage processing on the polygonal region and generate a shrinkage region according to the shrinkage function while keeping the original topological relationship unchanged. ; in, d This is the inward contraction distance. p Let be the coordinates of the polygon's vertices. for p The point points to the unit normal vector inside the polygon.

[0046] In one embodiment, assuming the original region is a square with a side length of 100 pixels, the boundary is shrunk inward by 1 pixel through shrinking processing, resulting in a square shrinking region with a side length of 98 pixels.

[0047] Step 2.3: Within the contracted region, based on the graph traces and spatial allocation ratio R corresponding to each node in the topology tree obtained in Step 2.1, the contracted region is divided into several non-overlapping closed sub-regions; the closed sub-regions are assigned to the corresponding child nodes for subsequent recursive geometric generation of the child nodes and their lower-level topology.

[0048] In one embodiment, assuming the contracted region is a square with a side length of 50 pixels, and the root node has three child nodes with space allocation ratios of 50%, 30%, and 20%, the square is divided into three non-overlapping closed sub-regions with areas of 1250 square pixels, 750 square pixels, and 500 square pixels, respectively. The division can be done by cutting along a horizontal or vertical direction, or by radiating outwards from a center point. The specific division method is chosen according to actual needs, adapting to different shaped carrying areas while ensuring the independence and integrity of each sub-region, thus providing a foundation for the subsequent generation of nested structures.

[0049] Step 2.4: Using the closed sub-region generated in Step 2.3 as the new parent region, recursively execute Step 2.2 and Step 2.3 to map the hierarchical structure in the topology tree to a nested structure layer by layer until all nodes have completed their geometric construction, generating a QR code with a nested structure.

[0050] In one embodiment, the three sub-regions of 1250, 750, and 500 square pixels are further shrunk and divided until all nodes of the topology tree are mapped to their corresponding regions. The QR code graphic generated recursively exhibits a clear nested structure, with each closed region corresponding to a node or subtree in the topology tree.

[0051] Step 2.5: For each closed sub-region in the nested structure, the user customizes the stylized form of each node or sub-node corresponding to these closed sub-regions to obtain a stylized QR code graphic.

[0052] The stylization includes color, fill texture, and carrier shape, and the carrier shape includes concave and convex stylization.

[0053] In one embodiment, the user can fill the area corresponding to the root node with dark blue and the child node areas with light blue, adding a grid texture to each area to enhance visual hierarchy. The carrier shape can be selected with a concave or convex effect, for example, designing certain areas with a raised effect to highlight their importance. Through this stylization, the generated QR code not only has data storage capabilities but can also be integrated with a specific design style or brand image.

[0054] In one embodiment, such as Figure 6As shown, users can fill the area corresponding to the root node with red to simulate the tomato sauce base of a pizza crust, and alternately fill the child node areas with dark green and light green to correspond to the vegetable toppings and cheese layers of the pizza, respectively. Circular light green dots are added to each leaf node area to simulate the topping particles on the pizza surface, enhancing the visual depth. The carrier shape is chosen as a circular polygon as the outer contour, making the overall QR code appear as a top-down view of a pizza. The outer edge area is filled with warm yellow and has an irregular raised texture to simulate the texture of the crust after baking, further strengthening the visual effect. Through this stylized processing, the generated QR code not only has data storage capabilities but also is highly integrated with the specific image of a pizza, allowing users to intuitively perceive the content it points to before scanning.

[0055] Step 3: Scan the stylized QR code image and preprocess it. Extract the boundary contour of the closed area and construct a global topology tree. Enumerate multiple candidate topology trees and decode them one by one to obtain binary information. After verification, select the valid binary information as the recognition result.

[0056] like Figure 5 As shown, this step is the core of the recognition process. It reverse-engineers the original data from the stylized QR code image and improves the accuracy and robustness of the recognition through a multi-candidate decoding and verification mechanism. In this embodiment, by constructing a global topology tree and enumerating candidate topology trees, the correct topology structure is restored as much as possible to ensure correct data decoding.

[0057] Step 3.1: Perform grayscale, denoising, and binarization processing on the stylized QR code input image obtained by scanning; identify the boundary contours of all closed regions in all binarized images, and construct a global region hierarchy structure, i.e., a global topology tree, based on the spatial inclusion relationship between regions.

[0058] In one embodiment, the scanned image is first converted to grayscale to eliminate color interference; then, noise points are removed through filtering; finally, binarization is performed to convert the image to black and white to clearly distinguish foreground and background regions. After preprocessing, the contour of each closed region is extracted using a boundary detection algorithm, and a hierarchical structure is constructed based on the containment relationship between regions. For example, if a region is completely contained within another region, it is marked as a sub-region. In this way, a global topology tree reflecting the hierarchical relationship of all regions in the image can be generated, providing a basis for subsequent candidate selection.

[0059] Step 3.2: Traverse all nodes of the global topology tree and select nodes whose number of descendant nodes exceeds a preset threshold as candidate root nodes; extract the corresponding subtrees of each candidate root node to construct a set of candidate topology trees; where the candidate topology tree represents the topological structure dependency between nested regions and is used as the input for decoding.

[0060] It should be noted that, since noisy or pseudo-regions may exist in the scanned image, directly using the root node of the global topology tree as the decoding starting point may lead to errors. Therefore, it is necessary to enumerate multiple candidate topology trees and select the most likely correct structure. In one embodiment, assuming a preset threshold of 10, nodes with more than 10 descendant nodes are considered candidate root nodes. After traversing the global topology tree, if three nodes meet the condition, these three nodes are used as roots, and their corresponding subtrees are extracted to form three candidate topology trees. These candidate topology trees represent different topological dependencies between nested regions and serve as input for subsequent decoding.

[0061] Step 3.3: For each candidate topology tree obtained in step 3.2, perform reverse decoding according to the recursive decomposition rule adopted in step 1 to obtain the binary information of each candidate topology tree as the decoding result.

[0062] In one embodiment, assuming the root node of a candidate topology tree has three child nodes corresponding to the values ​​9, 4, and 1, these values ​​are added together to obtain the root node value 14. Then, the upper-level nodes are processed recursively until the natural number corresponding to the entire topology tree is recovered. After the value recovery is complete, the natural number is converted into a binary string using the same bijective function as in the encoding stage, serving as the decoding result of the candidate topology tree. This step decodes each candidate topology tree, obtaining multiple possible binary information to provide alternative results for subsequent verification.

[0063] Step 3.4: Perform Cyclic Redundancy Check (CRC) on the decoded binary information of each candidate topology tree; ; in, da This is the decoded binary byte stream. x This indicates the position of the binary bit. If the check value is 0, the binary information is considered valid.

[0064] Step 3.5: When the verification is passed, the candidate topology tree is determined to be a valid code, and its corresponding binary information is used as the final recognition result; when the verification result fails, the candidate topology tree is determined to be invalid noise, and its decoded binary information is discarded.

[0065] In one possible implementation, suppose there are three candidate topology trees whose decoded binary information is 10101010, 11001100, and 10110110. After verification, it is found that only the first tree's binary information has a verification value of 0. Therefore, its corresponding binary information 10101010 is taken as the final recognition result, and the decoding results of the other two trees are discarded. This filtering mechanism can effectively avoid misidentification problems caused by noise or deformation, and improve the accuracy of recognition.

[0066] In this invention, step 4 is also included: constructing an optimization function that integrates multiple types of losses, generating different types of QR codes and verifying the effectiveness of decoding, and iteratively optimizing the parameters until the convergence condition is met.

[0067] The optimization function is based on the relative error of the footprint. L fp Absolute error in area ratio L area Log loss of decoding probability L rec The following formula is used; ; in: , Represents the loss weights, used to balance the losses of each component; footprint relative error L fp Used to constrain the space occupied by the topology tree, i.e., the fit between the graph tile trace F and the length of the binary string to be encoded, and the absolute error of the area ratio. L area Used to constrain the consistency between the spatial allocation ratio of child nodes and the corresponding node's graph trace ratio, decoding probabilistic logarithmic loss. L rec Used to constrain deviations in encoding and reverse decoding.

[0068] This step is the optimization stage of the entire method. It is used to continuously adjust the parameters in the encoding and recognition process through comprehensive evaluation of multi-dimensional losses, so that the generated QR code achieves a balance between anti-deformation ability, stylization effect and recognition accuracy.

[0069] Specifically, the footprint relative error is used to measure the fit between the spatial occupancy of the topology tree and the length of the binary string to be encoded, ensuring that the generated QR code graphic is reasonably distributed in space; the area ratio absolute error is used to constrain the consistency between the spatial allocation ratio of child nodes and the corresponding node tile trace ratio, avoiding regional imbalance; the decoding probability log loss is used to measure the deviation in the encoding and reverse decoding process, striving to reduce information loss or errors. After optimization, the final parameter configuration is saved.

[0070] The various embodiments of the present invention have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments.

Claims

1. A stylizable and deformation-resistant QR code encoding and recognition method based on topological coding, characterized in that, include: Step 1: Convert the binary string to be encoded into a natural number using a bijective function, and recursively decompose the natural number based on the four-square sum theorem to generate a topological tree structure; Step 2: Determine the space allocation ratio based on the tile traces of each node in the topology tree; The polygonal region carrying the QR code is shrunk and recursively divided into non-overlapping closed sub-regions. The hierarchical structure of the topology tree is mapped to a QR code with a nested structure, and stylized to generate a stylized QR code graphic. Step 3: Scan the stylized QR code image and preprocess it, extract the boundary contour of the closed area and construct a global topology tree, enumerate multiple candidate topology trees and decode them one by one to obtain binary information, and after CRC verification, select the valid binary information as the recognition result.

2. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... Step 1 includes: Step 1.1: Preprocess the input binary string to be encoded, remove invalid characters through format validation, and if the length of the string after format validation does not reach the preset minimum threshold, pad the end of the string with 0 to the preset minimum threshold length. Step 1.2: Perform a high-order bit-major conversion on the preprocessed binary string using the following bijective function to obtain the natural number N. ; in, b The input binary string, L The length of the binary string. i This is the number of digits representing the length of the string. b i For the string number i The binary value of a bit, either 0 or 1; N for na The natural number output by the function; Step 1.3: Convert the natural numbers obtained in Step 1.2 N As the value corresponding to the root node of the topological tree, the natural number is decomposed into squares, that is... N It is represented as the sum of several square numbers, with each square number corresponding to a node. The node is hierarchically associated with the root node. The square number decomposition is repeated for each node, and the child nodes of the node are generated layer by layer until the corresponding value can no longer be decomposed into a non-zero square number. The binary information is encoded through the above decomposition process to obtain the topological tree structure representing the binary information.

3. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... Step 2 includes: Step 2.1: Calculate the tile trace F of each node in the topology tree, and determine the spatial allocation ratio R of each child node accordingly; Step 2.2: Determine the original two-dimensional region that carries the topology and define it as a polygonal region. Its boundary is formed by a sequence of vertices P arranged in sequence. Perform shrinkage processing on the polygonal region and generate a shrinkage region according to the shrinkage function while keeping the original topological relationship unchanged. Step 2.3: Within the shrinking region, based on the tile traces and spatial allocation ratio R corresponding to each node in the topology tree obtained in Step 2.1, the shrinking region is divided into several non-overlapping closed sub-regions; the closed sub-regions are assigned to the corresponding child nodes for subsequent recursive geometric generation of the child nodes and their lower-level topology. Step 2.4: Using the closed sub-region generated in Step 2.3 as the new parent region, recursively execute Step 2.2 and Step 2.3 to map the hierarchical structure in the topology tree to a nested structure layer by layer until all nodes have completed their geometric construction, generating a QR code with a nested structure. Step 2.5: For each closed sub-region in the nested structure, the user customizes the stylized form of each node or sub-node corresponding to the closed sub-region to obtain a stylized QR code graphic.

4. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 3, characterized in that, In step 2.1, the tile trace of each node in the topology tree is calculated using the following formula. F The trace value of a node is the sum of the number of the node itself and all its child nodes, and the spatial allocation ratio R of each child node is determined accordingly. ; in, n Indicates the node number. Nod n For its first n 1 node m For the current node n The total number of child nodes, a This is the child node number of the current node. Nod a For its first a Number of child nodes F ( Nod n ) is for nodes Nod n The trace of the subtree rooted at the root; R ( Nod a ) indicates the first a Each child node is in its parent node Nod n The area percentage of the region; In step 2.2, the indentation function PAD ( P,d The following formula is used: ; in, d This is the inward contraction distance. p Let be the coordinates of the polygon's vertices. for p The point points to the unit normal vector inside the polygon.

5. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 3, characterized in that, In step 2.5, the stylized form includes color, fill texture, and carrier shape, and the carrier shape includes concave and convex shapes.

6. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... In step 3, the scanning of the stylized QR code image and preprocessing, extracting closed contours and establishing hierarchical relationships includes: Step 3.1: Perform grayscale conversion, noise reduction, and binarization on the stylized QR code input image obtained by scanning; Identify the boundary contours of all closed regions in all binarized images, and construct a global region hierarchy, i.e., a global topology tree, based on the spatial inclusion relationships between regions.

7. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... In step 3, the process of enumerating multiple candidate topology trees and decoding them one by one to obtain binary information includes: Step 3.2: Traverse all nodes of the global topology tree and select nodes whose number of descendant nodes exceeds a preset threshold as candidate root nodes; extract the corresponding subtrees of each candidate root node to construct a set of candidate topology trees; where the candidate topology tree represents the topological structure dependency between nested regions and is used as the input for decoding. Step 3.3: For each candidate topology tree obtained in Step 3.2, perform reverse decoding according to the recursive decomposition rules adopted in Step 1 to obtain the binary information of each candidate topology tree as the decoding result.

8. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 7, characterized in that... In step 3.3, the reverse decoding includes: The hierarchical relationship of the candidate topology tree nodes is mapped to the square number during encoding. Starting from the root node, the child nodes are decoded from top to bottom, and the corresponding values ​​of the nodes are restored. The natural numbers of the candidate topology tree are obtained by combining the values ​​of the nodes at each level. According to the bijective function used in the encoding stage, natural numbers are converted into corresponding binary information, which is used as the decoding result of the candidate topology tree.

9. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... In step 3, the step of filtering out valid binary information as the identification result after CRC verification includes: Step 3.4: Perform Cyclic Redundancy Check (CRC) on the decoded binary information of each candidate topology tree; ; in, da This is the decoded binary byte stream. x This indicates the position of the binary bit; if the check value is 0, the binary information is considered valid. Step 3.5: When the verification is passed, the candidate topology tree is determined to be a valid code, and its corresponding binary information is used as the final recognition result; when the verification result fails, the candidate topology tree is determined to be invalid noise, and its decoded binary information is discarded.

10. The stylizable and deformation-resistant QR code encoding and recognition method based on topological coding as described in claim 1, characterized in that... The method further includes step 4: constructing an optimization function that integrates multiple types of losses, generating different types of QR codes and verifying the effectiveness of decoding, and iteratively optimizing the parameters until the convergence condition is met; wherein, the optimization function is based on the footprint relative error. L fp Absolute error in area ratio L area Log loss of decoding probability L rec The following formula is used; ; Where: represents the loss weight, used to balance the losses of each component; and the relative error of the footprint. L fp Used to constrain the space occupied by the topology tree, i.e., the fit between the graph tile trace F and the length of the binary string to be encoded, and the absolute error of the area ratio. L area Used to constrain the consistency between the spatial allocation ratio of child nodes and the corresponding node's graph trace ratio, decoding probabilistic logarithmic loss. L rec Used to constrain deviations in encoding and reverse decoding.