A two-dimensional code module attribute identification method, an electronic device and a storage medium
By identifying the grayscale relationship between the QR code module and adjacent modules and correcting for illumination, the problem of difficulty in identifying the grayscale attributes of the QR code module was solved, and accurate decoding under poor lighting conditions was achieved.
Patent Information
- Application Number
- CN202511237066.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-31
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2045-08-31
AI Technical Summary
QR code images are often blurry and have uneven grayscale distribution due to external interference such as uneven lighting and inaccurate focus, as well as issues such as ink overflow and unclear printing. This makes it difficult for reading algorithms to recognize the grayscale attributes of the code module and to decode it.
By obtaining the grayscale value relationship between the code module and its adjacent modules in the QR code image, the grayscale attributes of the code module are identified. The attributes of the code module are identified by peak-shaped or valley-shaped relationships, and corrections are made in combination with lighting conditions to improve recognition accuracy.
Even under blurry or uneven lighting conditions, it can still accurately identify the grayscale attributes of the QR code module, thus improving the success rate of QR code decoding.
Smart Images

Figure CN121598974B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of QR code technology, and in particular to a QR code module attribute recognition method, electronic device, and storage medium. Background Technology
[0002] With the rapid development of QR code technology, QR codes have been widely used in daily life and industrial production. Common QR codes, such as QR codes and DataMatrix codes, are matrix-type QR codes. Determining the grayscale attribute (e.g., black and white) of the code modules is a crucial step in the reading algorithm. Often, due to various reasons, such as uneven lighting, inaccurate focus, and other external interference, as well as inherent issues like ink overflow and unclear printing, QR code images suffer from blurriness, uneven grayscale distribution, and low contrast. This makes it difficult for the reading algorithm to identify the grayscale attribute of the code modules, leading to decoding difficulties. Summary of the Invention
[0003] The main technical problem addressed by this application is to provide a method, electronic device, and storage medium for identifying the attributes of QR code modules, which can improve the accuracy of identifying the attributes of QR code modules.
[0004] To address the aforementioned technical problems, the first aspect of this application provides a method for identifying the attributes of a QR code module. The method includes: acquiring a QR code image obtained by photographing the QR code; wherein the QR code includes a plurality of first code modules, each first code module being a data module carrying user data; acquiring at least one pair of adjacent modules corresponding to each first code module; wherein two first code modules in the adjacent module pair are adjacent to the first code module and are located in the same row or column as the first code module; and comparing the grayscale values of each first code module with its corresponding adjacent module pair to identify the grayscale attribute to which each first code module belongs.
[0005] To address the aforementioned technical problems, a second aspect of this application provides an electronic device comprising a memory and a processor. The memory stores program instructions, and the processor executes the program instructions to implement the aforementioned QR code module attribute recognition method.
[0006] To address the aforementioned technical problems, a third aspect of this application provides a computer-readable storage medium for storing program instructions that can be executed to implement the aforementioned QR code module attribute recognition method.
[0007] In the above technical solution, if there is a valley-like relationship (low gray value in the middle, high gray value on both sides) or a peak-like relationship (high gray value in the middle, low gray value on both sides) between the first code module and the two first code modules in the corresponding adjacent module pair, then even if the gray values of the first code module and the two first code modules in the corresponding adjacent module pair change due to ink overflow, blurring, camera focusing problems, etc., the valley-like or peak-like relationship between the first code module and the two first code modules in the corresponding adjacent module pair is preserved or still exists. Therefore, by comparing the gray values of the first code module and the corresponding adjacent module pair, it is possible to determine whether the relative gray value relationship between the first code module and the corresponding adjacent module pair is a peak-like or valley-like relationship, thereby determining the gray value attribute of the first code module and improving the accuracy of attribute recognition of the first code module. Attached Figure Description
[0008] Figure 1 This is a flowchart illustrating an embodiment of the QR code module attribute recognition method provided in this application;
[0009] Figure 2 This is a partial schematic diagram of the QR code provided in this application; Figure 3 This is a flowchart illustrating an embodiment of determining the grayscale attribute of a currently unknown module, as provided in this application. Figure 4 This is a flowchart illustrating another embodiment of the method for determining the grayscale attribute of an currently unknown module, as provided in this application. Figure 5 This is a schematic diagram of an embodiment of the transition module and the corresponding target neighborhood module group provided in this application; Figure 6 This is a flowchart illustrating another embodiment of the method for determining the grayscale attribute of an currently unknown module, as provided in this application. Figure 7 yes Figure 6 The flowchart of step S73 shown is a schematic diagram of one embodiment. Figure 8 This is a schematic diagram of the structure of an embodiment of the QR code module attribute recognition device provided in this application; Figure 9 This is a schematic diagram of the structure of an embodiment of the electronic device provided in this application; Figure 10 This is a schematic diagram of an embodiment of the computer-readable storage medium provided in this application. Detailed Implementation
[0010] The embodiments of this application will now be described in detail with reference to the accompanying drawings.
[0011] In the following description, specific details such as particular system architectures, interfaces, and technologies are presented for illustrative purposes rather than for limiting purposes, in order to provide a thorough understanding of this application.
[0012] In this document, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " generally indicates that the preceding and following related objects have an "or" relationship. Furthermore, "many" in this document means two or more. Moreover, the term "at least one" in this document means any combination of at least two of any one or more of a plurality of objects. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0013] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the QR code module attribute recognition method provided in this application. It should be noted that if substantially the same result is obtained, this embodiment is not necessarily identical. Figure 1 The illustrated process sequence is limited. For example... Figure 1 As shown, this embodiment includes: Step S11: Obtain the QR code image obtained by taking a picture of the QR code.
[0014] In this embodiment, a QR code image obtained by capturing a QR code is acquired; wherein, the QR code includes several first code modules, and the first code module is a data module carrying user data.
[0015] Taking a QR code image where the grayscale attributes of the code modules include black and white as an example, the QR code image is a matrix QR code image. Due to ink overflow, blurring, and unclear camera focus, the black code modules (code modules with a black grayscale attribute) of the QR code "intrude" into the white code modules (code modules with a white grayscale attribute). This causes the grayscale of the white code modules "intruded" into the black code modules to be significantly darker than other white code modules that are not "intruded" into the black code modules, and even darker than some black code modules, and vice versa. The three white code modules A, B, and C in the QR code image are affected by the adjacent black code modules, and their grayscale is significantly darkened.
[0016] Step S12: Obtain at least one pair of adjacent modules corresponding to each first code module.
[0017] In this embodiment, at least one pair of adjacent modules corresponding to each first code module is obtained; wherein, the two first code modules in the adjacent module pair are adjacent to the first code module and are located in the same row or column as the first code module.
[0018] Due to ink overflow, blurring, and camera focusing issues, the black code module of a QR code "intrudes" into the white code module. This causes the grayscale of the white code module that has been "intruded" into the black code module to be significantly darker (lower grayscale value) than other white code modules that have not been "intruded" into the black code module, and even darker than some black code modules, and vice versa. However, although the absolute grayscale value of the code module changes, the relative grayscale relationship between the code modules is preserved.
[0019] For example, such as Figure 2 As shown, Figure 2 This is a partial schematic diagram of the QR code provided in this application, and it is related to the white code module A ( Figure 2 Two adjacent code modules (black code module B and black code module C) located in the same row (with a grayscale value of 36) may "intrude" into the white code module A due to ink overflow, blurring, or camera focusing issues, causing the white code module A to darken. However, even when the white code module A darkens, it is usually still brighter than the black code modules B and C, meaning it is still usually brighter than the black code modules on either side of it. In other words, a white code module is sandwiched between two black code modules, and there is a peak-shaped relationship among the three: a high grayscale value in the middle and low grayscale values on both sides. Even if the grayscale values of the three code modules change due to ink overflow, blurring, or camera focusing issues, the peak-shaped relationship among them is preserved, or rather, the relative grayscale relationship among them is preserved, or rather, it still exists.
[0020] For example, such as Figure 2 As shown, with black code module A ( Figure 2 Two adjacent code modules (white code module B and white code module C) located in the same row (with a grayscale value of 19) may "intrude" into the black code module A due to ink overflow, blurring, or camera focusing issues, causing the black code module A to become brighter. However, even if the black code module A becomes brighter, it is usually still darker than the white code modules B and C, meaning it is usually still darker than the white code modules on either side of it. In other words, a black code module is sandwiched between two white code modules, and there is a valley-like relationship between the three of them: "low grayscale value in the middle, high grayscale value on both sides." Even if the grayscale values of the three code modules change due to ink overflow, blurring, or camera focusing issues, the valley-like relationship between them is preserved or still exists; that is, the relative grayscale relationship between the three is preserved or still exists.
[0021] Therefore, by obtaining at least one pair of adjacent modules corresponding to each first code module, the grayscale attribute of the first code module can be determined by comparing the grayscale of the first code module with its corresponding pair of adjacent modules.
[0022] The adjacent module pairs corresponding to each first code module can be one group or two groups, and no specific limitation is made here.
[0023] Step S13: Compare the gray values of each first code module with the corresponding adjacent module pair to identify the gray value attribute of each first code module.
[0024] In this embodiment, the grayscale values of each first code module are compared with those of its corresponding adjacent module pairs to identify the grayscale attribute of each first code module. If there is a valley-like relationship (low grayscale value in the middle, high grayscale values on both sides) or a peak-like relationship (high grayscale value in the middle, low grayscale values on both sides) between the first code module and the two first code modules in its corresponding adjacent module pair, then even if the grayscale values of the first code module and the two first code modules in its corresponding adjacent module pair change due to ink overflow, blurring, camera focusing issues, etc., the valley-like or peak-like relationship between the first code module and the two first code modules in its corresponding adjacent module pair is preserved or still exists. Therefore, by comparing the grayscale values of the first code module and its corresponding adjacent module pair, it can be determined whether the relative grayscale relationship between the first code module and its corresponding adjacent module pair is a peak-like or valley-like relationship, thereby determining the grayscale attribute of the first code module.
[0025] In one embodiment, the adjacent module pairs corresponding to each first code module are obtained in two groups; the grayscale values of each first code module and its corresponding adjacent module pairs are compared to identify the grayscale attribute to which each first code module belongs. Specifically, for each first code module, in response to the first code module and at least one corresponding adjacent module pair satisfying a first size relationship, the first code module is determined to be a first preset grayscale attribute, wherein the first size relationship is that the grayscale value of the first code module is less than the grayscale values of the two first code modules in the corresponding adjacent module pair; in response to the first code module and at least one corresponding adjacent module pair satisfying a second size relationship, the first code module is determined to be a second preset grayscale attribute, wherein the second size relationship is that the grayscale value of the first code module is greater than the grayscale values of the two first code modules in the corresponding adjacent module pair; in response to the first code module and each corresponding adjacent module pair not satisfying the first size relationship and the second size relationship, the first code module is determined to be an unknown grayscale attribute.
[0026] It should be noted that since there are two sets of adjacent module pairs corresponding to each first code module, the two first code modules in one set of adjacent module pairs corresponding to the first code module are adjacent to the first code module and are located in the same row as the first code module; the two first code modules in the other set of adjacent module pairs corresponding to the first code module are adjacent to the first code module and are located in the same column as the first code module.
[0027] If the grayscale values of the first code module and at least one pair of adjacent modules satisfy a first size relationship, then the grayscale value of the first code module is less than the grayscale values of the two first code modules in the corresponding pair of adjacent modules. Therefore, this indicates that there is a valley-like relationship of "low grayscale value in the middle and high grayscale values on both sides" between the first code module and at least one pair of adjacent modules. This valley-like relationship exists between the three first code modules: the first code module with the second preset grayscale attribute, the first code module with the first preset grayscale attribute, and the first code module with the second preset grayscale attribute. Therefore, the first code module can be determined to have the first preset grayscale attribute.
[0028] The formula for determining whether the first size relationship is satisfied is as follows:
[0029] In the formula, g represents the grayscale value of the first code module; g left This represents the grayscale value of the leftmost code module in the first pair of adjacent modules; g right This represents the grayscale value of the first code module located on the right in the first pair of adjacent modules; g up This represents the grayscale value of the uppermost code module in the second group of adjacent module pairs; g down This represents the grayscale value of the first code module located at the bottom in the second group of adjacent module pairs. It should be noted that the first group of adjacent module pairs corresponding to the first code module are adjacent module pairs located in the same row as the first code module, and the second group of adjacent module pairs corresponding to the first code module are adjacent module pairs located in the same column as the first code module.
[0030] If the grayscale values of the first code module and at least one pair of adjacent modules satisfy a second size relationship, then the grayscale value of the first code module is greater than the grayscale values of the two first code modules in the corresponding pair of adjacent modules. Therefore, this indicates that there is a peak-shaped relationship of "high grayscale value in the middle and low grayscale values on both sides" between the first code module and at least one pair of adjacent modules. This peak-shaped relationship exists among the three first code modules: the first code module with the first preset grayscale attribute, the first code module with the second preset grayscale attribute, and the first code module with the first preset grayscale attribute. Therefore, the first code module can be determined to have the second preset grayscale attribute.
[0031] The formula for determining whether the second size relationship is satisfied is as follows:
[0032] In the formula, g represents the grayscale value of the first code module; g left This represents the grayscale value of the leftmost code module in the first pair of adjacent modules; g right This represents the grayscale value of the first code module located on the right in the first pair of adjacent modules; g up This represents the grayscale value of the uppermost code module in the second group of adjacent module pairs; g down This represents the grayscale value of the first code module located at the bottom in the second group of adjacent module pairs. It should be noted that the first group of adjacent module pairs corresponding to the first code module are adjacent module pairs located in the same row as the first code module, and the second group of adjacent module pairs corresponding to the first code module are adjacent module pairs located in the same column as the first code module.
[0033] The grayscale values of the first code module and its corresponding adjacent module pairs do not satisfy the first and second size relationships. Therefore, it indicates that there is neither a peak-shaped relationship of "high grayscale value in the middle and low grayscale value on both sides" nor a valley-shaped relationship of "low grayscale value in the middle and high grayscale value on both sides" between the first code module and its corresponding adjacent module pairs. Thus, the grayscale attribute of the first code module cannot be determined by the relative grayscale relationship between the first code module and its corresponding adjacent module pairs. In other words, the grayscale attribute of the first code module is unknown.
[0034] In one specific implementation, the first preset grayscale attribute is black, and the second preset grayscale attribute is white.
[0035] In one embodiment, the grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes. Furthermore, the grayscale attribute of the currently unknown module is determined by utilizing the grayscale attributes of currently known modules in the first target neighborhood of the currently unknown module. Here, the currently unknown module is the first code module currently identified as having an unknown grayscale attribute, and the currently known module is the first code module currently identified as having any preset grayscale attribute. Since some first code modules cannot have their grayscale attribute determined through the relative grayscale relationship between them and their corresponding adjacent module pairs, there will be first code modules with unknown grayscale attributes. Therefore, the grayscale attribute of the first code module currently identified as having any preset grayscale attribute is further determined by utilizing the first code modules currently identified as having an unknown grayscale attribute.
[0036] In one specific implementation, the preset grayscale attributes include a first preset grayscale attribute and a second preset grayscale attribute.
[0037] In one specific implementation, such as Figure 3 As shown, Figure 3 This is a flowchart illustrating an embodiment of determining the grayscale attribute of a currently unknown module provided in this application. The method utilizes the grayscale attributes of currently known modules in the first target neighborhood of the currently unknown module to determine the grayscale attribute of the currently unknown module. Specifically, it includes the following sub-steps: Step S41: Take the current unknown module and the first code module in the first target neighborhood of the current unknown module as the first associated module group of the current unknown module.
[0038] In this embodiment, the currently unknown module and the first code module in the first target neighborhood of the currently unknown module are regarded as the first associated module group of the currently unknown module.
[0039] If a terminal device takes a picture of a QR code to obtain a QR code image, and the light shines from the upper left corner, the QR code module in the upper left corner will be very bright. The black QR code module in the upper left corner may appear as "dark gray," and the white QR code module may appear as "bright white." On the other hand, the QR code module in the lower right corner will be darker. The black QR code module in the lower right corner will appear as "pure black," and the white QR code module may appear as "light gray."
[0040] The first code module in the first associated module group corresponding to the currently unknown module is a module within the neighborhood of the currently unknown module. This indicates that the spatial position of the currently unknown module and the first code module in the corresponding first associated module group are close. Therefore, the light intensity conditions experienced by the currently unknown module and the first code module in the corresponding first associated module group are quite similar. Thus, using the first code module within the first target neighborhood of the currently unknown module as the first associated module group ensures that the illumination conditions of the currently unknown module and the first code module in the corresponding first associated module group are basically the same or basically uniform. This can, to some extent, eliminate the impact of illumination differences on the grayscale attribute recognition of the code module and improve the accuracy of attribute recognition for the code module.
[0041] In one implementation, the first target neighborhood of the currently unknown module is N centered on the currently unknown module. A neighborhood consisting of N first-code modules. The size of N is not limited and can be set according to actual needs; for example, N can be 5.
[0042] Step S42: Statistically analyze the gray values of the first code modules with the first preset gray value attribute in the first associated module group to obtain the first attribute threshold; and statistically analyze the gray values of the first code modules with the second preset gray value attribute in the first associated module group to obtain the second attribute threshold.
[0043] In this embodiment, the grayscale values of the first code modules with the first preset grayscale attribute in the first associated module group are statistically analyzed to obtain a first attribute threshold. The first attribute threshold is obtained by statistically analyzing the grayscale values of the first code modules with the first preset grayscale attribute in the first associated module group. Therefore, the first attribute threshold represents the grayscale reference of the first code module with the "typical first preset grayscale attribute" in the current imaging environment.
[0044] In one embodiment, the grayscale values of the first code modules with a first preset grayscale attribute in the first associated module group are statistically analyzed to obtain a first attribute threshold. Specifically, this includes: obtaining a first central tendency representation value of the grayscale values of the first code modules with the first preset grayscale attribute in the first associated module group; obtaining the product of the first central tendency representation value and a first coefficient as the first attribute threshold, wherein the first coefficient is a positive number and is the difference between a first preset value and a second preset value. The first central tendency representation value can be the mean, median, etc., the first preset value can be 1, and the second preset value can be any value between 0 and 0.5.
[0045] Given that the trend representation value in the first episode is the mean and the first preset value is 1, the specific calculation formula for the first attribute threshold is as follows:
[0046]
[0047]
[0048] In the formula: T high Indicates the threshold value of the first attribute; G sum1 This represents the sum of grayscale values of the first code modules with the first preset grayscale attribute in the first associated module group; Num1 represents the number of first code modules with the first preset grayscale attribute in the first associated module group; 1 represents the first preset value; k represents the second preset value. g ij This represents the grayscale value of the first code module located in the i-th row and j-th column of the first associated module group.
[0049] It should be noted that the first attribute threshold is the product of the first central tendency representation value of the gray value of the first code module with the first preset gray value attribute in the first association module group and the first coefficient, and the first coefficient is a positive number less than 1; therefore, the first attribute threshold is reduced compared to the first central tendency representation value of the gray value of the first code module with the first preset gray value attribute in the first association module group, so as to improve the gray value reference of the first code module with the "typical first preset gray value attribute" in the current imaging environment, thereby improving the accuracy of attribute recognition of the code module.
[0050] In other embodiments, the first central tendency representation value of the grayscale value of the first code module with the first preset grayscale attribute in the first associated module group can also be used as the first attribute threshold, which is not limited here.
[0051] In addition, in this embodiment, the grayscale values of the first code modules with the second preset grayscale attribute in the first associated module group are statistically analyzed to obtain a second attribute threshold. The second attribute threshold is obtained by statistically analyzing the grayscale values of the first code modules with the second preset grayscale attribute in the first associated module group. Therefore, the second attribute threshold represents the grayscale reference of the first code module with the "typical second preset grayscale attribute" in the current imaging environment.
[0052] In one embodiment, the grayscale values of the first code module with the second preset grayscale attribute in the first associated module group are statistically analyzed to obtain the second attribute threshold. Specifically, this includes: obtaining a first central tendency representation value of the grayscale values of the first code module with the second preset grayscale attribute in the first associated module group; obtaining the product of the first central tendency representation value and a first coefficient as the second attribute threshold, wherein the first coefficient is a positive number and is the sum of a first preset value and a second preset value. The first central tendency representation value can be the mean, median, etc., the first preset value can be 1, and the second preset value can be any value between 0 and 0.5.
[0053] Given that the trend representation value in the first episode is the mean and the first preset value is 1, the specific calculation formula for the second attribute threshold is as follows:
[0054]
[0055]
[0056] In the formula: T low Indicates the threshold value of the second attribute; G sum0 This represents the sum of grayscale values of the first code modules with the second preset grayscale attribute in the first associated module group; Num0 represents the number of first code modules with the second preset grayscale attribute in the first associated module group; 1 represents the first preset value; k represents the second preset value. g ij This represents the grayscale value of the first code module located in the i-th row and j-th column of the first associated module group.
[0057] It should be noted that the second attribute threshold is the product of the first central tendency representation value of the gray value of the first code module with the second preset gray value attribute in the first association module group and the first coefficient, and the first coefficient is a positive number greater than 1; therefore, the second attribute threshold is increased compared to the first central tendency representation value of the gray value of the first code module with the second preset gray value attribute in the first association module group, so as to improve the gray value benchmark of the first code module with the "typical second preset gray value attribute" in the current imaging environment, thereby improving the accuracy of attribute recognition of the code module.
[0058] In other embodiments, the first central tendency representation value of the grayscale value of the first code module with the second preset grayscale attribute in the first associated module group can also be used as the second attribute threshold, which is not limited here.
[0059] Step S43: In response to the fact that the grayscale value of the current unknown module is less than the first attribute threshold, determine that the current unknown module is the first preset grayscale attribute.
[0060] In this embodiment, in response to the grayscale value of the currently unknown module being less than the first attribute threshold, the currently unknown module is determined to have the first preset grayscale attribute. The first attribute threshold is obtained by statistically analyzing the grayscale values of the first code modules in the first associated module group that have the first preset grayscale attribute. Therefore, the first attribute threshold represents the grayscale reference of the first code module with the "typical first preset grayscale attribute" in the current imaging environment. When the grayscale value of the currently unknown module is less than the first attribute threshold, it meets the grayscale reference of the code module that is determined to have the first preset grayscale attribute; therefore, when the grayscale value of the currently unknown module is less than the first attribute threshold, the currently unknown module can be determined to have the first preset grayscale attribute.
[0061] Step S44: In response to the grayscale value of the current unknown module being greater than the second attribute threshold, determine the current unknown module as the second preset grayscale attribute.
[0062] In this embodiment, in response to the grayscale value of the currently unknown module being greater than the second attribute threshold, the currently unknown module is determined to have the second preset grayscale attribute. The second attribute threshold is obtained by statistically analyzing the grayscale values of the first code modules in the first associated module group that have the second preset grayscale attribute. Therefore, the second attribute threshold represents the grayscale reference of the first code module with the "typical second preset grayscale attribute" in the current imaging environment. When the grayscale value of the currently unknown module is less than the second attribute threshold, it meets the grayscale reference of the code module that is determined to have the second preset grayscale attribute; therefore, when the grayscale value of the currently unknown module is less than the second attribute threshold, the currently unknown module can be determined to have the second preset grayscale attribute.
[0063] Step S45: In response to the fact that the grayscale value of the current unknown module is less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold, determine that the current unknown module is an unknown grayscale attribute.
[0064] In this embodiment, in response to the grayscale value of the current unknown module being less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold, the current unknown module is determined to have an unknown grayscale attribute. If the grayscale value of the current unknown module is less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold, it indicates that the current unknown module does not meet the grayscale reference of either the code module determined to have the second preset grayscale attribute or the code module determined to have the first preset grayscale attribute. Therefore, if the grayscale value of the current unknown module is less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold, the current unknown module is determined to have an unknown grayscale attribute.
[0065] In one implementation, the first code module currently identified as having an unknown grayscale attribute is taken as the current unknown module, and the grayscale attribute of the current unknown module is determined by using the grayscale attribute of the currently known module in the first target neighborhood of the current unknown module. In other words, steps S41-S45 are executed.
[0066] In other specific implementations, such as Figure 4 As shown, Figure 4 This is a flowchart illustrating another embodiment of the method for determining the grayscale attribute of a currently unknown module, provided in this application. The method utilizes the grayscale attributes of currently known modules in the first target neighborhood of the currently unknown module to determine the grayscale attribute of the currently unknown module. Specifically, it includes the following sub-steps: Step S51: Use each currently unknown module that meets the position requirements as a transition module.
[0067] In the field of QR codes, the black-and-white boundary, or module transition boundary, refers to a gray transition area between two adjacent code modules with different preset grayscale attributes, caused by physical or optical effects. Furthermore, the black-and-white boundary, or module transition boundary, tends to be closer to the lighter-colored code module.
[0068] Therefore, in this embodiment, each currently unknown module that meets the location requirements is used as a transition module. The location requirements include the existence of a target neighboring module group for the transition module, the target neighboring module group being a pair of adjacent modules, and the two first code modules contained within each pair having two different preset grayscale attributes. Since a currently unknown module that meets the location requirements is a pair of adjacent modules containing two first code modules with different preset grayscale attributes, its grayscale attribute can be determined by locating its corresponding black-and-white boundary or module transition boundary.
[0069] Step S52: Determine the module transition boundary between each transition module and the corresponding target neighborhood module group.
[0070] In this embodiment, the module transition boundary between each transition module and the corresponding target neighboring module group is determined.
[0071] In one embodiment, the module transition boundary between each transition module and the corresponding target neighboring module group is determined as follows: For each transition module, the grayscale change rate of all pixels between the first center pixel of the transition module and the second center pixel of the target neighboring module is obtained, and each first code module in the target neighboring module group is the target neighboring module; the pixel point whose grayscale change rate meets the change rate requirement is selected as the module transition boundary corresponding to the transition module.
[0072] In one specific implementation, the rate of change is required to be the maximum grayscale change rate. That is, the pixel with the maximum grayscale change rate is used as the module transition boundary corresponding to the transition module.
[0073] Step S53: For each transition module, obtain the distance between the module transition boundary corresponding to the transition module and each first code module in the corresponding target neighborhood module group.
[0074] In this implementation method, for each transition module, the distance between the module transition boundary corresponding to the transition module and each first code module in the corresponding target neighborhood module group is obtained.
[0075] In one embodiment, the module transition boundary corresponding to the transition module is the pixel where the grayscale change rate between the first center pixel and the second center pixel meets the change rate requirement. The first center pixel is the center point of the transition module, the second center pixel is the center point corresponding to the target neighboring module, and each first code module in the target neighboring module group is a target neighboring module. The distance between the module transition boundary corresponding to the transition module and the first code module in the corresponding target neighboring module group is the distance between the center point of the transition module and the center point of the first code module in the corresponding target neighboring module group.
[0076] Step S54: Determine the grayscale attribute of the transition module based on the distance.
[0077] In this embodiment, the grayscale attribute of the transition module is determined based on distance.
[0078] In one embodiment, the distance between the module transition boundary corresponding to the transition module and the two first code modules in the corresponding target neighborhood module group are respectively used as the first distance and the second distance. In response to the first distance being greater than the second distance, the grayscale attribute of the first code module corresponding to the first distance is used as the grayscale attribute of the transition module.
[0079] For example, such as Figure 5 As shown, Figure 5 This is a schematic diagram of an embodiment of the transition module and the corresponding target neighborhood module group provided in this application. The transition module is a first code module B, and the two code modules in the target neighborhood module group corresponding to the transition module are the first code module A and the first code module C, respectively. The pixel with the maximum grayscale change rate is found between the first center pixel of the first code module B and the second center pixel of the first code module A, and is used as the module transition boundary α. The distances between the module transition boundary α and the centers of the first code module A and the first code module C are calculated to obtain the first distance. Second distance Due to the first distance Greater than the second distance Therefore, the grayscale attribute of the first code module B is the same as that of the first code module A.
[0080] To avoid misjudgment caused by the two being too close, in one specific implementation, if the absolute value of the difference between the first distance and the second distance is less than a preset distance threshold, and the target neighborhood module group corresponding to the transition module is an adjacent module pair in the column direction of the transition module, then it is determined whether the two first code modules in the adjacent module pair in the row direction of the transition module know the preset grayscale attribute and have different preset grayscale attributes; if the two first code modules in the adjacent module pair in the row direction of the transition module know the preset grayscale attribute and have different preset grayscale attributes, then the adjacent module pair in the row direction of the transition module is taken as the new target neighborhood module group of the transition module, and Repeat steps S52-S54. If the absolute value of the difference between the new first distance and the new second distance obtained based on this is still less than the preset distance threshold, then the transition module is determined to be an unknown grayscale attribute. Conversely, if the absolute value of the difference between the new first distance and the new second distance obtained based on this is greater than or equal to the preset distance threshold, then the grayscale attribute of the first code module corresponding to the larger distance is taken as the grayscale attribute of the transition module. If at least one of the two first code modules in the adjacent module pair in the row direction of the transition module is an unknown grayscale attribute, or both are the same preset grayscale attribute, then the transition module is determined to be an unknown grayscale attribute.
[0081] The preset distance threshold is not limited and can be set according to actual usage needs.
[0082] To avoid misjudgment caused by the two being too close, in one specific implementation, if the absolute value of the difference between the first distance and the second distance is less than a preset distance threshold, and the target neighborhood module group corresponding to the transition module is an adjacent module pair in the row direction of the transition module, then it is determined whether the two first code modules in the adjacent module pair in the column direction of the transition module have known preset grayscale attributes and are different preset grayscale attributes; if the two first code modules in the adjacent module pair in the column direction of the transition module have known preset grayscale attributes and are different preset grayscale attributes, then the adjacent module pair in the column direction of the transition module is taken as the new target neighborhood module group of the transition module, and Repeat steps S52-S54. If the absolute value of the difference between the new first distance and the new second distance obtained based on this is still less than the preset distance threshold, then the transition module is determined to be an unknown grayscale attribute. Conversely, if the absolute value of the difference between the new first distance and the new second distance obtained based on this is greater than or equal to the preset distance threshold, then the grayscale attribute of the first code module corresponding to the larger distance is taken as the grayscale attribute of the transition module. If at least one of the two first code modules in the adjacent module pair in the column direction of the transition module is an unknown grayscale attribute, or both are the same preset grayscale attribute, then the transition module is determined to be an unknown grayscale attribute.
[0083] It should be noted that when both steps S41-S45 and steps S51-54 are used to determine the grayscale attribute of the currently unknown module, steps S41-S45 can be executed first and then steps S51-54, or steps S51-54 can be executed first and then steps S41-S45. No limitation is made here.
[0084] In one implementation, such as Figure 6 As shown, Figure 6 This is a flowchart illustrating another embodiment of determining the grayscale attribute of a currently unknown module provided in this application. The grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes. After comparing the grayscale values of each first code module with the corresponding adjacent module pair to identify the grayscale attribute of each first code module, or after determining the grayscale attribute of the currently unknown module using the grayscale attributes of currently known modules in the first target neighborhood of the currently unknown module, the following sub-steps are further included: Step S71: Determine the currently unknown modules and currently known modules in the QR code.
[0085] Because some first code modules cannot determine their grayscale attribute through the relative grayscale relationship between themselves and their corresponding neighboring module pairs, or because some first code modules cannot determine their grayscale attribute through the first code modules currently identified as having any preset grayscale attribute in their neighborhood, there will still be first code modules with unknown grayscale attributes. Therefore, after comparing the grayscale values of each first code module with its corresponding neighboring module pairs to identify the grayscale attribute of each first code module, or after determining the grayscale attribute of the currently unknown module by using the grayscale attribute of the currently known modules in the first target neighborhood of the currently unknown module, this embodiment will determine the currently unknown module and the currently known module in the QR code to determine the grayscale attribute of the currently unknown module.
[0086] Step S72: Take the current unknown module and the first code module in the second target neighborhood of the current unknown module as the second associated module group of the current unknown module.
[0087] In this embodiment, the currently unknown module and the first code modules within the second target neighborhood of the currently unknown module are considered as the second associated module group of the currently unknown module; wherein, the second target neighborhood is larger than the first target neighborhood. The fact that the second target neighborhood is larger than the first target neighborhood indicates that the second target neighborhood corresponding to the currently unknown module is relatively large. Therefore, within the second target neighborhood corresponding to the currently unknown module, the distribution of the first code modules with preset grayscale attributes is relatively balanced.
[0088] In one implementation, the second target neighborhood of the currently unknown module is M centered on the currently unknown module. A neighborhood consisting of M first-code modules, where M is greater than N. The sizes of M and N are not limited; for example, M is 7 and N is 5.
[0089] Step S73: Use the grayscale attribute of the currently known module in the second associated module group to determine the grayscale attribute of the currently unknown module.
[0090] In this embodiment, the grayscale attribute of the currently known module in the second associated module group is used to determine the grayscale attribute of the currently unknown module.
[0091] In one implementation, such as Figure 7 As shown, Figure 7 yes Figure 6 The flowchart of step S73 shown is a schematic diagram of an embodiment. It utilizes the grayscale attribute of the currently known module in the second associated module group to determine the grayscale attribute of the currently unknown module. Specifically, it includes the following sub-steps: Step S81: Statistically analyze the grayscale values of the currently known modules in the second associated module group to obtain the third attribute threshold.
[0092] In this embodiment, the grayscale values of the currently known modules in the second associated module group are statistically analyzed to obtain a third attribute threshold. Since the distribution of the first code modules with preset grayscale attributes within the second associated module group corresponding to the currently unknown module is relatively balanced, statistically analyzing the grayscale values of the currently known modules in the second associated module group to obtain the third attribute threshold can effectively represent the boundary for distinguishing first code modules with different preset grayscale attributes, making the grayscale attribute of the currently unknown module determined based on the third attribute threshold more accurate.
[0093] In one embodiment, the grayscale values of the currently known modules in the second associated module group are statistically analyzed to obtain a third attribute threshold. Specifically, the second central tendency value of the grayscale values of the currently known modules in the second associated module group is obtained and used as the third attribute threshold. That is, the second central tendency value of the grayscale values of the currently known modules in the second associated module group is used as the third attribute threshold. The second central tendency value can be the mean, median, etc.
[0094] Where the trend representation value in the second set can be the mean, the specific calculation formula for the threshold of the third attribute is as follows:
[0095]
[0096]
[0097]
[0098]
[0099] Where: G sum0 This represents the sum of the grayscale values of the first code module with the second preset grayscale attribute in the second associated module group; g ij This represents the grayscale value of the first code module located in the i-th row and j-th column of the second associated module group; Num0 represents the number of first code modules with the second preset grayscale attribute in the second associated module group; G sum0 / Num0 represents the average grayscale value of the first code module with the second preset grayscale attribute in the second associated module group; G sum1 This represents the sum of the grayscale values of the first code modules with the first preset grayscale attribute in the second associated module group; Num1 represents the number of first code modules with the first preset grayscale attribute in the second associated module group; G sum1 / Num1 represents the average grayscale value of the first code module with the first preset grayscale attribute in the second associated module group; T represents the threshold of the third attribute.
[0100] Step S82: In response to the fact that the grayscale value of the current unknown module is less than the third attribute threshold, determine that the current unknown module is the first preset grayscale attribute.
[0101] In this embodiment, in response to the grayscale value of the currently unknown module being less than the third attribute threshold, the currently unknown module is determined to have the first preset grayscale attribute. Since the third attribute threshold is obtained by statistically analyzing the grayscale values of currently known modules in the second associated module group, it can represent the boundary for distinguishing first code modules with different preset grayscale attributes. Therefore, when the grayscale value of the currently unknown module is less than the third attribute threshold, the currently unknown module can be determined to have the first preset grayscale attribute.
[0102] Step S83: In response to the grayscale value of the current unknown module being greater than the third attribute threshold, determine the current unknown module as the second preset grayscale attribute.
[0103] In this embodiment, in response to the grayscale value of the currently unknown module being less than the third attribute threshold, the currently unknown module is determined to have the first preset grayscale attribute. Since the third attribute threshold is obtained by statistically analyzing the grayscale values of the currently known modules in the second associated module group, it can represent the boundary for distinguishing first code modules with different preset grayscale attributes. Therefore, when the grayscale value of the currently unknown module is greater than the third attribute threshold, the currently unknown module can be determined to have the second preset grayscale attribute.
[0104] It should be noted that after comparing the gray values of each first code module with its corresponding adjacent module pair to identify the gray attribute of each first code module, or after using the gray attributes of the currently known modules in the first target neighborhood of the currently unknown module to determine the gray attribute of the currently unknown module, steps S71-S73 are executed. This can be considered as a last resort after all the previous complex local analysis methods have determined the gray attributes of the code modules, there are still some stubborn code modules whose gray attributes cannot be determined. For these stubborn code modules, a simpler and more global statistical method is used to calculate a uniform threshold in a slightly larger area to make a final, one-size-fits-all judgment. In other words, the gray attribute identification method of the code modules corresponding to steps S71-S73 can be considered as the final and more global fallback method when the gray attribute of the code module still cannot be determined after all the previous complex local analysis methods have determined the gray attribute of the code module.
[0105] In one implementation, each currently unknown module needs to execute steps S71-S73 respectively.
[0106] In one embodiment, the QR code further includes several second code modules, which are inherent code modules within the QR code. These inherent code modules are code modules in the QR code that do not carry user data. Since these inherent code modules have fixed preset grayscale attributes, the grayscale attribute of each inherent code module can be determined in advance based on the QR code type and version information.
[0107] For example, QR codes include inherent modules such as locators and silent areas. The grayscale attribute of the second code module, which belongs to these inherent modules, can be determined in advance based on the QR code type and version information.
[0108] In one specific implementation, the determination of the grayscale attributes of a number of second code modules can be performed before step S12.
[0109] In one embodiment, the grayscale value of each first code module can be determined using the mean method, wherein the calculation formula corresponding to the mean method is as follows:
[0110] In the formula: G represents the grayscale value of the first code module; g ij This represents the grayscale value of the pixel in the i-th row and j-th column of the module region corresponding to the first code module; N represents the number of rows of pixels in the module region corresponding to the first code module; and M represents the number of columns of pixels in the module region corresponding to the first code module. It should be noted that the size of the module region can be set according to actual usage needs. A larger module region will introduce more interference but can tolerate more module position deviations.
[0111] In other implementations, a weighted method can also be used to determine the grayscale value of each first code module. The calculation formula for the weighted method is as follows:
[0112] In the formula: G represents the grayscale value of the first code module; g ij This represents the grayscale value of the pixel in the i-th row and j-th column of the module region corresponding to the first code module; q ij This represents the weight of the pixel in the i-th row and j-th column of the module region corresponding to the first code module; N represents the number of rows of pixels in the module region corresponding to the first code module; and M represents the number of columns of pixels in the module region corresponding to the first code module. It should be noted that pixels closer to the center of the first code module have a higher weight; furthermore, the size of the module region can be set according to actual usage needs.
[0113] In one embodiment, when multiple methods exist to determine the grayscale value of each first code module of the QR code, the steps are as follows: Step 1: Determine the grayscale value of each first code module using one of the methods; Step 2: Determine the grayscale attribute of each first code module using the methods described in the above embodiment; Step 3: Decode the QR code based on the determined grayscale attribute of each first code module. If decoding fails, another grayscale value determination method is used, and steps 1 to 3 are re-executed until the QR code is successfully decoded, or until all grayscale value determination methods have been used and decoding of the QR code still fails, at which point execution stops. By traversing multiple grayscale value determination methods, the QR code decoding rate can be improved.
[0114] In one embodiment, the steps for acquiring a QR code image obtained by capturing a QR code are as follows: Step 1: Acquire the original image obtained by capturing the QR code; Step 2: Find the center points of three positioning patterns in the original image, and calculate the coordinates of the four vertices (four corner points) of the QR code area image based on the center points of the three positioning patterns; Step 3: Perform distortion adjustment on the QR code area image based on the four vertices; Step 4: Determine the version number of the QR code by analyzing the relationship between the positioning patterns, and then determine the number of code modules contained in the QR code based on the version number of the QR code; Step 5: Divide the distorted QR code area image into a grid according to the number of code modules contained in the QR code, thereby obtaining the QR code image obtained by capturing the QR code, where each grid represents one code module.
[0115] Please see Figure 8 , Figure 8 This is a schematic diagram of an embodiment of the QR code module attribute recognition device provided in this application. The QR code module attribute recognition device 90 includes a first acquisition module 91, a second acquisition module 92, and an recognition module 93; the first acquisition module 91 is used to acquire a QR code image obtained by taking a picture of the QR code; wherein, the QR code includes a plurality of first code modules, and the first code module is a data module carrying user data; the second acquisition module 92 is used to acquire at least one pair of adjacent modules corresponding to each first code module; wherein, the two first code modules in the adjacent module pair are adjacent to the first code module and are located in the same row or column as the first code module; the recognition module 93 is used to compare the gray value of each first code module with the corresponding adjacent module pair to identify the gray value attribute to which each first code module belongs.
[0116] Among them, the adjacent module pairs corresponding to each first code module obtained above are two groups; the identification module 93 is used to compare the gray values of each first code module with the corresponding adjacent module pairs to identify the gray value attribute to which each first code module belongs, including: for each first code module, in response to the first code module and at least one group of adjacent module pairs satisfying a first size relationship, the first code module is determined to be a first preset gray value attribute; wherein, the first size relationship is that the gray value of the first code module is less than the gray values of the two first code modules in the corresponding adjacent module pair; in response to the first code module and at least one group of adjacent module pairs satisfying a second size relationship, the first code module is determined to be a second preset gray value attribute; wherein, the second size relationship is that the gray value of the first code module is greater than the gray values of the two first code modules in the corresponding adjacent module pair; in response to the first code module and each group of adjacent module pairs not satisfying the first size relationship and the second size relationship, the first code module is determined to be an unknown gray value attribute.
[0117] The grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes; the identification module 93 is also used to determine the grayscale attribute of the current unknown module by using the grayscale attribute of the currently known module in the first target neighborhood of the current unknown module; wherein the current unknown module is the first code module currently identified as having an unknown grayscale attribute, and the current known module is the first code module currently identified as having any preset grayscale attribute.
[0118] The identification module 93 is used to determine the grayscale attribute of the current unknown module by utilizing the grayscale attribute of the currently known module in the first target neighborhood of the current unknown module. This includes: classifying the current unknown module and the first code module within the first target neighborhood of the current unknown module as a first associated module group of the current unknown module; statistically analyzing the grayscale values of the first code modules in the first associated module group that have a first preset grayscale attribute to obtain a first attribute threshold; and statistically analyzing the grayscale values of the first code modules in the first associated module group that have a second preset grayscale attribute to obtain a second attribute threshold; determining the current unknown module as having a first preset grayscale attribute in response to the grayscale value of the current unknown module being less than the first attribute threshold; determining the current unknown module as having a second preset grayscale attribute in response to the grayscale value of the current unknown module being greater than the second attribute threshold; and determining the current unknown module as having an unknown grayscale attribute in response to the grayscale value of the current unknown module being less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold.
[0119] Wherein, the first target neighborhood of the aforementioned currently unknown module is N centered on the currently unknown module. A neighborhood composed of N first code modules; and / or, the identification module 93 is used to statistically analyze the gray values of the first code modules with a first preset gray value attribute in the first associated module group to obtain a first attribute threshold, or to statistically analyze the gray values of the first code modules with a second preset gray value attribute in the first associated module group to obtain a second attribute threshold, including: obtaining a first central tendency representation value of the gray values of the first code modules with a target preset gray value attribute in the first target associated module group; wherein the target preset gray value attribute is either the first preset gray value attribute or the second preset gray value attribute; obtaining the product of the first central tendency representation value and a first coefficient as the target attribute threshold; wherein the target attribute threshold is either the first attribute threshold or the second attribute threshold, the first coefficient is a positive number, and when the target preset gray value attribute is the first preset gray value attribute, the first coefficient is the difference between the first preset value and the second preset value, and when the target preset gray value attribute is the second preset gray value, the first coefficient is the sum of the first preset value and the second preset value.
[0120] The identification module 93 is used to determine the grayscale attribute of the currently unknown module by utilizing the grayscale attribute of the currently known module in the first target neighborhood of the currently unknown module. This includes: designating each currently unknown module that meets the location requirements as a transition module; wherein the location requirements include that the transition module exists in a target neighborhood module group, the target neighborhood module group consists of adjacent module pairs, and the two first code modules contained therein have two different preset grayscale attributes; determining the module transition boundary between each transition module and the corresponding target neighborhood module group; for each transition module, obtaining the distance between the module transition boundary corresponding to the transition module and each first code module in the corresponding target neighborhood module group; and determining the grayscale attribute of the transition module based on the distance.
[0121] The identification module 93 is used to determine the module transition boundary between each transition module and the corresponding target neighboring module group, including: for each transition module, obtaining the grayscale change rate of all pixels between the first center pixel of the transition module and the second center pixel of the target neighboring module, and each first code module in the target neighboring module group is the target neighboring module; selecting the pixel whose grayscale change rate meets the change rate requirement as the module transition boundary corresponding to the transition module.
[0122] Wherein, the module transition boundary corresponding to the aforementioned transition module is the pixel point where the grayscale change rate between the first center pixel point and the second center pixel point meets the change rate requirement, the first center pixel point is the center point of the transition module, the second center pixel point is the center point corresponding to the target adjacent module, each first code module in the target neighborhood module group is the target adjacent module, and the distance between the module transition boundary corresponding to the transition module and the first code module in the corresponding target neighborhood module group is the distance between the center point of the transition module and the center point of the first code module in the corresponding target neighborhood module group; and / or, the identification module 93 is used to determine the grayscale attribute to which the transition module belongs based on the distance, including: taking the distance between the module transition boundary corresponding to the transition module and the two first code modules in the corresponding target neighborhood module group as the first distance and the second distance respectively, and in response to the first distance being greater than the second distance, taking the grayscale attribute to which the first code module corresponding to the first distance belongs as the grayscale attribute to which the transition module belongs.
[0123] The grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes. The identification module 93 is further configured to, after comparing the grayscale values of each first code module with the corresponding adjacent module pair to identify the grayscale attribute of each first code module, or, after determining the grayscale attribute of the currently unknown module by using the grayscale attribute of the currently known module in the first target neighborhood of the currently unknown module, include: determining the currently unknown module and the currently known module in the QR code; taking the currently unknown module and the first code modules in the second target neighborhood of the currently unknown module as the second associated module group of the currently unknown module; wherein the second target neighborhood is larger than the first target neighborhood; and using the grayscale attribute of the currently known module in the second associated module group to determine the grayscale attribute of the currently unknown module.
[0124] The identification module 93 is used to determine the grayscale attribute of the currently unknown module by utilizing the grayscale attribute of the currently known module in the second associated module group, including: statistically analyzing the grayscale values of the currently known modules in the second associated module group to obtain a third attribute threshold; determining the currently unknown module as a first preset grayscale attribute in response to the grayscale value of the currently unknown module being less than the third attribute threshold; and determining the currently unknown module as a second preset grayscale attribute in response to the grayscale value of the currently unknown module being greater than the third attribute threshold.
[0125] The identification module 93 is used to statistically analyze the grayscale values of the currently known modules in the second associated module group to obtain the third attribute threshold, including: obtaining the second central tendency representation value of the grayscale values of the currently known modules in the second associated module group as the third attribute threshold.
[0126] Wherein, the second target neighborhood of the aforementioned currently unknown module is M centered on the currently unknown module. A neighborhood consisting of M first-code modules, where M is greater than N.
[0127] Please see Figure 9 , Figure 9 This is a schematic diagram of an embodiment of the electronic device provided in this application. The electronic device 100 includes a memory 101 and a processor 102 coupled to each other. The processor 102 is used to execute program instructions stored in the memory 101 to implement the steps of any of the above-described embodiments of the QR code module attribute recognition method. In a specific implementation scenario, the electronic device 100 may include, but is not limited to, a microcomputer or a server. In addition, the electronic device 100 may also include mobile devices such as laptops and tablets, which are not limited here.
[0128] Specifically, processor 102 controls itself and memory 101 to implement the steps of any of the QR code module attribute recognition method embodiments described above. Processor 102 can also be referred to as a CPU (Central Processing Unit). Processor 102 may be an integrated circuit chip with signal processing capabilities. Processor 102 can also be a general-purpose processor, digital signal processor (DSP), application-specific integrated circuit (ASIC), field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor. Furthermore, processor 102 can be implemented using integrated circuit chips.
[0129] Please see Figure 10 , Figure 10This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present application. The computer-readable storage medium 110 of this embodiment stores program instructions 111. When executed, these program instructions 111 implement the method provided by any embodiment of the QR code module attribute recognition method and any non-conflicting combination thereof. The program instructions 111 can form a program file and be stored in the aforementioned computer-readable storage medium 110 in the form of a software product, so that a computer device (which may be a personal computer, server, or network device, etc.) can execute all or part of the steps of the methods of various embodiments of the present application. The aforementioned computer-readable storage medium 110 includes various media capable of storing program code, such as a USB flash drive, mobile hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, or terminal devices such as computers, servers, mobile phones, and tablets.
[0130] If the technical solution of this application involves personal information, the product using this technical solution has clearly informed the user of the personal information processing rules and obtained the user's voluntary consent before processing the personal information. If the technical solution of this application involves sensitive personal information, the product using this technical solution has obtained the user's separate consent before processing the sensitive personal information, and also meets the requirement of "express consent". For example, at personal information collection devices such as cameras, clear and prominent signs are set up to inform users that they have entered the scope of personal information collection and that personal information will be collected. If an individual voluntarily enters the collection scope, it is deemed that they have agreed to the collection of their personal information; or on the personal information processing device, with clear signs / information informing users of the personal information processing rules, authorization is obtained from the individual through pop-up information or by asking the individual to upload their personal information; wherein, the personal information processing rules may include information such as the personal information processor, the purpose of personal information processing, the processing method, and the types of personal information processed.
[0131] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A method for recognizing the attributes of a QR code module, characterized in that, The method includes: Obtain a QR code image obtained by taking a picture of the QR code; wherein the QR code includes several first code modules, and the first code module is a data module carrying user data; Obtain at least one pair of adjacent modules corresponding to each of the first code modules; wherein, two code modules in the adjacent module pair are adjacent to the first code module and are located in the same row or column as the first code module; Compare the gray values of each first code module with the corresponding adjacent module pair to identify the gray value attribute of each first code module. The grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes; the method further includes: The grayscale attribute of the currently unknown module is determined by using the grayscale attribute of the currently known module in the first target neighborhood of the currently unknown module; wherein, the currently unknown module is the first code module currently identified as the unknown grayscale attribute, and the currently known module is the first code module currently identified as any of the preset grayscale attributes; The step of determining the grayscale attribute of the currently unknown module by utilizing the grayscale attribute of the currently known module in the first target neighborhood of the currently unknown module includes: Each of the currently unknown modules that meets the location requirements is used as a transition module; wherein, the location requirements include that the transition module has a target neighborhood module group, the target neighborhood module group is the adjacent module pair, and the two first code modules contained therein are two different preset grayscale attributes; Determine the module transition boundary between each of the transition modules and the corresponding target neighborhood module group; For each of the transition modules, the distance between the module transition boundary corresponding to the transition module and each first code module in the corresponding target neighborhood module group is obtained; Based on the distance, the grayscale attribute to which the transition module belongs is determined.
2. The method according to claim 1, characterized in that, The acquired adjacent module pairs corresponding to each first code module are divided into two groups; the comparison of the grayscale values of each first code module with its corresponding adjacent module pair to identify the grayscale attribute to which each first code module belongs includes: For each of the first code modules, in response to the first code module and at least one pair of adjacent modules satisfying a first size relationship, the first code module is determined to be a first preset grayscale attribute; wherein, the first size relationship is that the grayscale value of the first code module is less than the grayscale values of the two first code modules in the corresponding pair of adjacent modules. In response to the fact that the gray values of the first code module and at least one pair of adjacent modules satisfy a second size relationship, the first code module is determined to be a second preset gray value attribute; wherein, the second size relationship is that the gray value of the first code module is greater than the gray values of the two first code modules in the corresponding pair of adjacent modules. In response to the fact that the first code module and its corresponding adjacent module pairs do not satisfy the first size relationship and the second size relationship, the first code module is determined to be an unknown grayscale attribute.
3. The method according to claim 1, characterized in that, The step of determining the grayscale attribute of the currently unknown module by utilizing the grayscale attribute of the currently known module in the first target neighborhood of the currently unknown module includes: The currently unknown module and the first code module in the first target neighborhood of the currently unknown module are regarded as the first associated module group of the currently unknown module; The grayscale values of the first code modules with the first preset grayscale attribute in the first associated module group are statistically analyzed to obtain a first attribute threshold; and the grayscale values of the first code modules with the second preset grayscale attribute in the first associated module group are statistically analyzed to obtain a second attribute threshold. In response to the grayscale value of the currently unknown module being less than the first attribute threshold, the currently unknown module is determined to be a first preset grayscale attribute; In response to the grayscale value of the currently unknown module being greater than the second attribute threshold, the currently unknown module is determined to be a second preset grayscale attribute; In response to the grayscale value of the currently unknown module being less than or equal to the second attribute threshold and greater than or equal to the first attribute threshold, the currently unknown module is determined to be an unknown grayscale attribute.
4. The method according to claim 3, characterized in that, The first target neighborhood of the currently unknown module is a neighborhood composed of N*N first code modules centered on the currently unknown module; And / or, the step of statistically analyzing the grayscale values of the first code modules with a first preset grayscale attribute in the first associated module group to obtain a first attribute threshold, or statistically analyzing the grayscale values of the first code modules with a second preset grayscale attribute in the first associated module group to obtain a second attribute threshold, includes: Obtain the first central tendency representation value of the grayscale value of the first code module with a preset grayscale attribute for the target in the first target association module group; wherein, the preset grayscale attribute of the target is the first preset grayscale attribute or the second preset grayscale attribute; The product of the first central trend representation value and the first coefficient is obtained as the target attribute threshold; wherein, the target attribute threshold is either the first attribute threshold or the second attribute threshold, the first coefficient is a positive number, and when the target preset grayscale attribute is the first preset grayscale attribute, the first coefficient is the difference between the first preset value and the second preset value, and when the target preset grayscale attribute is the second preset grayscale attribute, the first coefficient is the sum of the first preset value and the second preset value.
5. The method according to claim 1, characterized in that, The step of determining the module transition boundary between each transition module and the corresponding target neighborhood module group includes: For each of the transition modules, the grayscale change rate of all pixels between the first center pixel of the transition module and the second center pixel of the target neighboring module is obtained, and each first code module in the target neighboring module group is the target neighboring module. Pixels whose grayscale change rate meets the change rate requirement are selected as the module transition boundary corresponding to the transition module.
6. The method according to claim 5, characterized in that, The transition boundary of the transition module is the pixel whose grayscale change rate between the first center pixel and the second center pixel meets the change rate requirement. The first center pixel is the center point of the transition module, and the second center pixel is the center point corresponding to the target neighboring module. Each first code module in the target neighboring module group is the target neighboring module. The distance between the transition boundary of the transition module and the first code module in the corresponding target neighboring module group is the distance between the center point of the transition module and the center point of the first code module in the corresponding target neighboring module group. And / or, determining the grayscale attribute to which the transition module belongs based on the distance includes: The distance between the module transition boundary corresponding to the transition module and the two first code modules in the corresponding target neighborhood module group is taken as the first distance and the second distance, respectively. In response to the first distance being greater than the second distance, the grayscale attribute of the first code module corresponding to the first distance is taken as the grayscale attribute of the transition module.
7. The method according to claim 1, characterized in that, The grayscale attribute of the first code module includes several preset grayscale attributes and unknown grayscale attributes; after comparing the grayscale values of each first code module with its corresponding adjacent module pair to identify the grayscale attribute of each first code module, or after determining the grayscale attribute of the currently unknown module by utilizing the grayscale attributes of currently known modules in the first target neighborhood of the currently unknown module, the method further includes: Determine the currently unknown modules and currently known modules in the QR code; The currently unknown module and the first code module within the second target neighborhood of the currently unknown module are taken as the second associated module group of the currently unknown module; wherein, the second target neighborhood is larger than the first target neighborhood; The grayscale attribute of the currently known module in the second associated module group is used to determine the grayscale attribute of the currently unknown module.
8. The method according to claim 7, characterized in that, The step of determining the grayscale attribute of the currently unknown module by utilizing the grayscale attribute of the currently known module in the second associated module group includes: The grayscale values of the currently known modules in the second associated module group are statistically analyzed to obtain the third attribute threshold. In response to the fact that the grayscale value of the currently unknown module is less than the third attribute threshold, the currently unknown module is determined to be a first preset grayscale attribute; In response to the grayscale value of the currently unknown module being greater than the third attribute threshold, the currently unknown module is determined to be a second preset grayscale attribute.
9. The method according to claim 8, characterized in that, The step of statistically analyzing the grayscale values of the currently known modules in the second associated module group to obtain the third attribute threshold includes: The second central trend representation value of the grayscale value of the currently known module in the second associated module group is obtained as the third attribute threshold.
10. The method according to claim 7, characterized in that, The second target neighborhood of the currently unknown module is a neighborhood composed of M*M first code modules centered on the currently unknown module, where M is greater than N.
11. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory being used to store program instructions, and the processor being used to execute the program instructions to implement the QR code module attribute recognition method as described in any one of claims 1-10.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program instructions that can be executed to implement the QR code module attribute recognition method as described in any one of claims 1-10.
Citation Information
Patent Citations
Binarization method and system of two-dimensional code image
CN104517110A
Lane line recognition method and device
CN111046741A
Method and apparatus for recognizing code
US20050194445A1
