QR code identification method based on statistical analysis
By proposing a QR code recognition method based on KL divergence statistical analysis and local region transformation correction, the problems of low recognition rate and poor robustness in complex environments are solved, achieving efficient and real-time QR code recognition and enhancing adaptability to changes in illumination, distortion and noise.
Patent Information
- Application Number
- CN202511409971.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-29
- Publication Date
- 2025-12-30
AI Technical Summary
Existing QR code recognition technologies suffer from low recognition rates and poor robustness in complex environments, high computational complexity, and are unable to meet real-time requirements. They are also sensitive to noise interference.
The KL divergence statistical analysis method is used to locate the "回" (hui) pattern and the alignment pattern. Distortion is corrected by local region transformation. Combined with the module color judgment strategy, the algorithm process is optimized to improve recognition accuracy and robustness.
In complex lighting, background interference, image distortion, and noise environments, it significantly improves the accuracy and stability of QR code recognition, reduces computational complexity, meets real-time requirements, and reduces device hardware dependence.
Smart Images

Figure CN121234967A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of fast response matrix code recognition technology, specifically to a QR code recognition method based on statistical analysis. Background Technology
[0002] Quick Response Codes (QR codes), as a convenient and efficient information carrier, have deeply penetrated every corner of modern society, including but not limited to mobile payments, product traceability, advertising, and information retrieval. They store data through a specific matrix pattern, allowing users to quickly access the information using smartphones or other photographic devices.
[0003] In the field of QR code recognition technology, although many statistical analysis methods have been proposed and applied, these existing technologies still have a series of problems that need to be solved and obvious shortcomings.
[0004] First, it performs poorly in adapting to complex environments. Existing statistical analysis methods typically achieve good recognition results under ideal lighting and background conditions. However, in real-world applications, uneven lighting, direct sunlight, or shadow coverage are extremely common. These factors cause significant changes in the pixel value distribution of QR code images, making it difficult for statistical analysis-based feature extraction algorithms to accurately capture the key features of QR codes, thus drastically reducing recognition accuracy.
[0005] Secondly, the ability to handle distortion in QR code images is limited. During actual scanning, due to factors such as shooting angle, distance, and deformation of the QR code carrier itself, images often exhibit perspective distortion and affine distortion. Existing statistical analysis methods often lack effective correction mechanisms when dealing with these distortions, failing to accurately restore the original shape and structure of the QR code, thus affecting the subsequent decoding process.
[0006] Furthermore, the computational complexity is high. Some statistical analysis-based recognition methods employ overly complex algorithms and models in pursuit of higher recognition accuracy, leading to a significant increase in computational load. This not only slows down the recognition process, making it unsuitable for applications with high real-time requirements, but also places higher demands on the hardware performance of the equipment, increasing application costs.
[0007] Finally, robustness to noise interference is insufficient. Various types of noise, such as Gaussian noise and salt-and-pepper noise, are inevitably introduced during image acquisition and transmission. Existing statistical analysis methods suffer significant performance degradation in feature extraction and classification under noise interference, easily leading to misidentification or failure to identify objects, thus limiting their application in noisy environments.
[0008] Therefore, how to overcome the defects of the above-mentioned prior art and provide a QR code recognition solution that can still maintain high robustness, high accuracy, and take into account the operation efficiency in a complex environment is a technical problem亟待解决 in this field. Summary of the Invention
[0009] To overcome the limitations of the prior art, according to one aspect of the present application, a QR code recognition method based on statistical analysis is provided, which includes: locating the positioning QR code in the initial image to obtain a preliminary positioning area containing the QR code area; performing view transformation on the preliminary positioning area to obtain a front view of the preliminary positioning area; unifying the background color of the QR code area in the front view of the preliminary positioning area to white and the color of the QR code to black to obtain a black-and-white unified color QR code map; locating the positions of the three "hui" characters in the unified color QR code map based on the KL divergence statistical analysis method; determining the basic information of the QR code based on the positions of the "hui" characters, where the basic information includes version information, module arrangement method, and module quantity information; obtaining a corrected matrix based on the basic information of the QR code; and decoding the corrected matrix to identify the QR code.
[0010] In an embodiment of the QR code recognition method based on statistical analysis according to the present application, locating the positions of the three "hui" characters in the unified color QR code map based on the KL divergence statistical analysis method includes: scanning the unified color QR code map to obtain multiple "hui" character candidate areas, each "hui" character candidate area including successively adjacent white areas, black areas, white areas, black areas, and white areas; calculating the first KL divergence of the width probability distribution of the successively adjacent white areas, black areas, white areas, black areas, and white areas in each "hui" character candidate area relative to the first preset probability distribution; and determining the positions of the "hui" characters based on the first KL divergence.
[0011] In an embodiment of the QR code recognition method based on statistical analysis according to the present application, verifying the positions of the "hui" characters in the "hui" character candidate areas based on the first KL divergence includes: taking the "hui" character candidate areas with the first KL divergence greater than or equal to 0 and lower than the first preset threshold as the final "hui" character pattern areas; and calculating the coordinates of the center points of the final "hui" character pattern areas as the coordinates of the center points of the "hui" characters.
[0012] In an embodiment of the QR code recognition method based on statistical analysis according to the present application, obtaining a corrected matrix based on the basic information of the QR code includes: judging whether the QR code contains alignment patterns based on the basic information of the QR code; in response to the QR code containing alignment patterns, obtaining a corrected matrix through the positions of the "hui" characters and the alignment patterns; or, in response to the QR code not containing alignment patterns, obtaining a corrected matrix through the "hui" characters in the unified color QR code map.
[0013] According to one embodiment of the statistical analysis-based QR code recognition method described in this application, a corrected matrix is obtained by using the positions of the back-shaped pattern and the alignment pattern, including: calculating the position of the alignment pattern in the uniform color QR code image based on the positions of at least two back-shaped patterns; and constructing the corrected matrix based on the positions of the back-shaped pattern and the alignment pattern.
[0014] According to one embodiment of the statistical analysis-based QR code recognition method described in this application, constructing a corrected matrix based on the positions of the back-shaped pattern and the alignment pattern includes: dividing a uniform-color QR code image into multiple local regions based on the positions of the back-shaped pattern and the alignment pattern; obtaining the matrix transformation relationship between the multiple local regions and the multiple local regions in the initial image; and determining the color of each module of the QR code in the initial image corresponding to each module in the multiple local regions of the uniform-color QR code image based on the matrix transformation relationship to obtain the corrected matrix.
[0015] According to one embodiment of the statistical analysis-based QR code recognition method described in this application, a uniform color QR code image is divided into multiple local regions based on the positions of the back-shaped pattern and the alignment pattern, including: selecting at least one point of the back-shaped pattern and at least one point of the alignment pattern in the uniform color QR code image as control points; and dividing the uniform color QR code image into multiple local regions based on the multiple control points.
[0016] According to one embodiment of the statistical analysis-based QR code recognition method described in this application, a uniform-color QR code image is divided into multiple local regions based on multiple control points, including: dividing the uniform-color QR code image into local regions containing only 3 control points, and / or dividing the uniform-color QR code image into local regions containing only 4 control points; obtaining the matrix transformation relationships between the multiple local regions and multiple local regions in the initial image, including: obtaining the affine transformation relationship between the local regions containing only 3 control points and the local regions in the initial image; obtaining the perspective transformation relationship between the local regions containing only 4 control points and the local regions in the initial image.
[0017] According to one embodiment of the statistical analysis-based QR code recognition method described in this application, the colors of each module of the QR code in the initial image corresponding to each module in multiple local regions of a unified color QR code image are determined based on matrix transformation relationships to obtain a corrected matrix. This includes: preprocessing the initial image; determining the color of each module of the QR code in the preprocessed initial image based on the basic information of the QR code; and forming a corrected matrix based on the colors of each module of the QR code in the preprocessed initial image. The module arrangement and number of modules in the corrected matrix are consistent with the module arrangement and number of modules determined by the basic information of the QR code, and the color of each module is consistent with the color of each module of the QR code in the initial image.
[0018] In an embodiment of the QR code recognition method based on statistical analysis according to the present application, determining the color of each module of the QR code in the preprocessed initial image based on the basic information of the QR code includes: determining the average pixel value of multiple modules in a local area with a preset size where each module of the QR code in the preprocessed initial image is located based on the module arrangement method and the number of modules of the QR code; comparing the number of modules with pixel values greater than the average pixel value and the number of modules with pixel values less than the average pixel value in the local area with a preset size where the module is located; in response to the number of modules with pixel values greater than the average pixel value in the local area with a preset size where the module is located being greater than the number of modules with pixel values less than the average pixel value, determining that the color of the module is white, otherwise black.
[0019] The main purpose of the QR code recognition method based on statistical analysis provided by the present application is to overcome the technical defects of low recognition rate and poor robustness of existing QR code recognition technologies in the face of complex environments (such as uneven illumination, image distortion, and noise interference), and to provide a more accurate, efficient, and anti-interference QR code recognition method based on statistical analysis.
[0020] Specifically, the core concept of the present application is to apply statistical principles more deeply to the key links of the recognition process to replace the rigid and easily interfered judgment logic in traditional methods.
[0021] First, when positioning the return character pattern and the alignment pattern, the present application conceives using the Kullback-Leibler divergence (KL divergence) to measure the similarity between the black and white bar width distribution of the candidate region and the ideal probability distribution (such as the 1:1:3:1:1 ratio of the return character pattern and the 1:1:1 ratio of the alignment pattern). This measurement method based on the difference in probability distribution can more robustly and accurately lock these key positioning features when there is noise and slight deformation in the image.
[0022] Secondly, for the problem of severe or irregular image distortion, the present application conceives a refined correction strategy of "divide and conquer". That is, after accurately positioning the return character pattern and the alignment pattern, the entire QR code image is divided into multiple smaller local regions based on this as a benchmark, and an affine or perspective transformation is calculated and applied independently for each local region. This localized processing can more effectively handle complex non-linear distortions than a single global transformation.
[0023] Finally, to fundamentally avoid the information loss caused by premature binarization (especially in the case of uneven illumination), the present application conceives an innovative sampling mechanism for directly performing module color interpretation on the preprocessed initial image. By performing statistical voting within the neighborhood corresponding to each module, it is determined whether the module should ultimately be black or white, thus significantly enhancing the adaptability to illumination changes.
[0024] By implementing the above technical concept, the present application finally achieves remarkable technical effects: it greatly improves the accuracy and stability of QR code recognition in complex illumination, background interference, image distortion, and noise environments; at the same time, through an optimized algorithm process, while ensuring high precision, it effectively controls the computational complexity and meets the real-time requirements of actual application scenarios, ultimately enabling a qualitative leap in the reliability and practicality of QR code recognition technology under various harsh conditions.
[0025] Specifically, in terms of adaptability to complex environments, the present application has outstanding performance. Whether facing complex illumination conditions such as direct strong light, shadow coverage, or uneven illumination, or scenes with complex background interference, it can accurately capture the key features of the QR code by virtue of the original statistical analysis strategy, effectively improve the recognition accuracy, and ensure stable operation in various actual application scenarios.
[0026] Regarding the distortion problem of QR code images, the present application innovatively introduces an advanced distortion correction algorithm. Whether it is perspective distortion or affine distortion, it can quickly and accurately restore the original shape and structure of the QR code, providing a reliable basis for subsequent decoding and greatly improving the recognition success rate.
[0027] In terms of computational complexity, the present application optimizes the algorithm process. On the premise of ensuring the recognition accuracy, it locates the return character pattern and alignment pattern through a relatively simplified statistical analysis method, significantly reducing the computational amount. This makes the recognition process more efficient, capable of meeting application scenarios with high real-time requirements, while reducing the dependence on the hardware performance of the device and reducing the application cost.
[0028] In addition, the present application has stronger anti-noise ability. The present application recognizes the QR code based on the module color of the initial image. Facing various noises introduced during image acquisition and transmission, such as Gaussian noise, salt-and-pepper noise, etc., it can still maintain stable recognition performance, effectively reducing misrecognition and unrecognizable situations, and enhancing the overall recognition reliability and practicality.
[0029] Through the understanding of the subsequent description and drawings, the further purposes and advantages of the present application will be fully reflected. Brief Description of the Drawings
[0030] The above and other objects, features, and advantages of this application will become more apparent from the more detailed description of the embodiments of this application in conjunction with the accompanying drawings. The drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the embodiments of this application to explain this application and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.
[0031] Figure 1 The illustration shows a flowchart of a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0032] Figure 2 The illustration shows a flowchart of a specific example of a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0033] Figure 3 The illustration shows a schematic diagram of the initial image in the statistical analysis-based QR code recognition method according to an embodiment of this application.
[0034] Figure 4 The illustration shows a schematic diagram of a QR code in an initial image in a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0035] Figure 5 The illustration shows a schematic diagram of the static region in the initial image of the QR code recognition method based on statistical analysis according to an embodiment of this application.
[0036] Figure 6 The illustration shows a front view of the preliminary positioning area in a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0037] Figure 7 The illustration shows a binarized image in a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0038] Figure 8 The illustration shows a schematic diagram of the sampling lines when sampling the static area in the binarized image in the QR code recognition method based on statistical analysis according to an embodiment of this application.
[0039] Figure 9 The illustration shows a uniform color QR code image in a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0040] Figure 10 The illustration shows a schematic diagram of the scanning method of a uniform color QR code image in a statistical analysis-based QR code recognition method according to an embodiment of this application.
[0041] Figure 11The figure illustrates a schematic diagram of a method for confirming the X coordinate of the center point of a square-within-a-square pattern in a QR code recognition method based on statistical analysis according to an embodiment of the present application.
[0042] Figure 12 The figure illustrates a schematic diagram of a method for confirming the position of an alignment pattern in a QR code recognition method based on statistical analysis according to an embodiment of the present application.
[0043] Figure 13 The figure illustrates a schematic diagram of control points in a QR code recognition method based on statistical analysis according to an embodiment of the present application.
[0044] Figure 14 The figure illustrates a schematic diagram of a local area division method in a QR code recognition method based on statistical analysis according to an embodiment of the present application. Detailed implementation manners
[0045] Next, exemplary embodiments according to the present application will be described in detail with reference to the accompanying drawings. Obviously, the described exemplary embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. It should be understood that the present application is not limited by the exemplary embodiments described herein.
[0046] It can be understood that the term "a" should be understood as "at least one" or "one or more". That is, in one embodiment, the number of an element can be one, while in other embodiments, the number of the element can be multiple. The term "a" should not be understood as a limitation on the number. "Multiple" means greater than or equal to two.
[0047] Although ordinal numbers such as "first", "second", etc. will be used to describe various components, those components are not limited herein. The term is only used to distinguish one component from another. For example, the first component can be called the second component, and similarly, the second component can also be called the first component without departing from the teachings of the concept of the present application. The term "and / or" used herein includes any and all combinations of one or more of the associated listed items.
[0048] The terms used herein are only for the purpose of describing various embodiments and are not intended to be limiting. As used herein, the singular form also includes the plural form unless the context clearly indicates otherwise. Additionally, it will be understood that the terms "comprising" and / or "having" when used in this specification specify the presence of the described features, numbers, operations, components, elements, or combinations thereof, without excluding the presence or addition of one or more other features, numbers, operations, components, elements, or combinations thereof.
[0049] In view of the technical deficiencies disclosed in the background art, the present application proposes a QR code recognition method based on statistical analysis. Figure 1This is a flowchart of a statistical analysis-based QR code recognition method according to an embodiment of this application. Figure 1 As shown, the QR code recognition method based on statistical analysis according to an embodiment of this application includes the following steps: S110, locating the QR code in the initial image to obtain a preliminary location area containing the QR code area; S120, performing a view transformation on the preliminary location area to obtain a front view of the preliminary location area; S130, unifying the background color of the QR code area in the front view of the preliminary location area to white and the color of the QR code to black to obtain a uniform color QR code image with alternating black and white; S140, locating the positions of the three back-shaped patterns in the uniform color QR code image based on the KL divergence statistical analysis method; S150, determining the basic information of the QR code based on the positions of the back-shaped patterns, wherein the basic information includes version information, module arrangement method, and module quantity information; S160, obtaining a corrected matrix based on the basic information of the QR code; S170, decoding the corrected matrix to identify the QR code.
[0050] In step S110, the QR code in the initial image is located to obtain a preliminary location area containing the QR code region. In the initial stage of the QR code recognition process, the input is typically an initial image containing the target QR code, a complex background, and irrelevant elements, such as... Figure 3 As shown, it is therefore necessary to initially separate the QR code from this potentially noisy initial image and delineate a relatively clear initial positioning area that contains only the QR code and its necessary edge regions.
[0051] Specifically, the first step is to use a certain algorithm, such as a traditional or deep learning algorithm, to locate the approximate position of the QR code and obtain the four vertices of the QR code. Figure 4 The four green dots in the diagram represent the four vertices of the QR code, determining the QR code region 110. The steps following S110 are based on the roughly aligned QR code for analysis. The QR code only needs to be roughly aligned, as the subsequent algorithms have some fault tolerance; therefore, this application does not have very high requirements for the initial QR code positioning. Next, as... Figure 2 and Figure 5 As shown, after obtaining the four vertices of the QR code, some outward expansion processing is required, mainly to obtain the static area 120 of the QR code. Figure 5 The four red dots in the image represent the four vertices of static area 120, preparing for the subsequent determination of the QR code background.
[0052] Accordingly, step S110 includes: S111, performing preliminary positioning of the four vertices of the QR code to obtain the QR code area; and S112, probing the area surrounding the QR code area to obtain a static area, wherein the QR code area and the static area form a preliminary positioning area. Accordingly, the preliminary positioning area includes the QR code area 110 and the static area 120 surrounding the QR code area 110.
[0053] In step S120, a view transformation is performed on the preliminary positioning area to obtain a front view of the preliminary positioning area. After extracting the preliminary positioning area containing the QR code, the obtained image area is often not ideal. During actual shooting, there is almost unavoidable angular tilt and distance changes between the camera and the QR code carrier, resulting in geometric distortion in the acquired QR code image. The most common and severe distortion is perspective distortion. This distortion causes the originally square QR code to appear as an arbitrary quadrilateral, and its internal grid becomes irregular, disrupting the parallelism between lines.
[0054] If subsequent feature recognition (such as locating the square pattern 10 and aligning the pattern 20) is performed directly on this distorted image, the positioning algorithm will fail because its preset geometric features (such as the width ratio of 1:1:3:1:1) are severely distorted. Therefore, it is necessary to correct this view distortion using mathematical methods to obtain a standard image, as if it were taken vertically from the front, to restore the inherent square structure and regular grid of the QR code. This lays a crucial foundation for subsequent accurate and reliable color unification, pattern positioning, and decoding processes.
[0055] Specifically, after determining the positions of the QR code area 110 and the static area 120, the preliminary positioning area can be corrected by perspective transformation to facilitate subsequent processing. During the process of correcting the preliminary positioning area by perspective transformation, the QR code area 110 and the static area 120 are also corrected by perspective transformation.
[0056] Accordingly, step S120 includes: S121, performing perspective transformation on the preliminary positioning area to obtain a front view of the preliminary positioning area. The view of the QR code area 110 in the front view of the preliminary positioning area is the front view of the QR code area 110, and the view of the static area 120 is the front view of the static area 120.
[0057] In step S130, the background color of the QR code area 110 in the front view of the unified preliminary positioning area is white and the color of the QR code is black to obtain a unified color QR code image with alternating black and white, as shown below. Figure 9As shown, a QR code is formed from multiple modules. After obtaining a front view of the initial positioning area, the image is still either grayscale or color, and the QR code may have two diametrically opposed color modes: "white background with black code" (black modules, white background) or "black background with white code" (white modules, black background). To simplify subsequent algorithm logic and avoid designing separate processing flows for the two color modes, the color mode of the image must be standardized.
[0058] Specifically, to facilitate determining whether it is a black background with white code or a white background with black code, and to subsequently obtain the position of the QR code's positioning pattern 10 and alignment pattern 20 using statistical methods, the front view of the preliminary positioning area is first subjected to adaptive binarization segmentation, such as... Figure 7 As shown. After obtaining the front view of the binarized preliminary positioning area, the QR code area 110 in the front view of the preliminary positioning area needs to be unified into a black background with white codes. The purpose of doing this is to facilitate unification during subsequent logical processing.
[0059] Accordingly, step S130 includes: S131, performing adaptive binary segmentation on the front view of the initially located area to obtain a binarized image; S132, determining the background color of the QR code area in the binarized image; S133, uniformly setting the background color of the QR code area in the binarized image to black, and uniformly setting the color of the QR code in the binarized image to white.
[0060] More specifically, the method involves sampling the static area 120 of the binarized image to determine whether it is a black background with white code or a white background with black code. If the number of black pixels is greater than the number of white pixels, it is a black background with white code; otherwise, it is a white background with black code. The sampling method involves offsetting a certain distance at the top and left of the QR code area 110 and counting the number of black and white pixels.
[0061] like Figure 8 As shown, during the sampling of the static region 120 of the binarized image, the static region 120 can be sampled in the X direction along the X-direction sampling line 101; and / or sampled in the Y direction along the Y-direction sampling line 102.
[0062] Accordingly, step S132 includes: S1321, sampling the static area in the binarized image and counting the number of black pixels and white pixels in the static area; S1322, determining the background color of the QR code area in the binarized image based on the number of black pixels and white pixels in the static area.
[0063] In step S1322, if the number of black pixels in the static area 120 is greater than the number of white pixels, it is determined that the background color of the QR code area 110 in the binary image is black, and the QR code is a black-on-white code. In subsequent S133, there is no need to adjust the color of the QR code and the background color of the QR code. If the number of white pixels in the static area 120 is greater than the number of black pixels, it is determined that the background color of the QR code in the binary image is white, the QR code area 110 is a white-on-black code, and in subsequent S133, the color of the QR code needs to be adjusted to black and the background color of the QR code needs to be adjusted to white.
[0064] In step S140, based on the KL divergence statistical analysis method, the positions of the three "回" character patterns 10 in the unified color QR code image are located. The three "回" character patterns 10 are the most important and stable geometric benchmarks of the QR code. The exact positions of the three "回" character patterns 10 are the absolute prerequisites for all subsequent key steps. The traditional positioning methods of the "回" character pattern 10 usually rely on image contour detection or geometric feature matching. When facing noise, printing defects or slight residual distortions, their robustness and accuracy will be severely challenged.
[0065] To overcome the above defects of the traditional method, the present invention introduces an innovative and more robust positioning strategy. By using the KL divergence to measure the consistency between the black and white module width distributions of the candidate region and the ideal distribution (such as the "回" character pattern, 1:1:3:1:1), the "回" character pattern 10 is located more robustly. This statistical-based method does not require the "回" character pattern 10 to have a perfect geometric contour, but focuses on the statistically significant black and white module width ratio characteristics presented by it on the scan line. In this way, the resistance of the positioning process to common interference (such as noise, breakpoints, stains) in the image can be greatly enhanced, so as to achieve a more accurate and reliable positioning of the "回" character pattern 10 than the traditional method, providing a solid guarantee for the success rate and stability of the entire two-dimensional code recognition process.
[0066] Specifically, the QR code has a first side, a second side, a third side and a fourth side in the clockwise direction; the first side of the QR code is opposite to the third side; the second side of the QR code is opposite to the fourth side; the three "回" character patterns 10 include a first "回" character pattern 11, a second "回" character pattern 12 and a third "回" character pattern 13, wherein, the first "回" character pattern 11 and the third "回" character pattern 13 are on the first diagonal line of the QR code.
[0067] One sign of the "回" character pattern 10 is the width ratio of the black module and the white module. Taking the horizontal direction (i.e., the X direction) as an example, the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area is approximately equal to 1:1:3:1:1, and the same is true for the vertical direction (i.e., the Y direction). As Figure 10As shown, taking the horizontal direction as an example, start horizontal scanning from the upper left corner along the X-direction scanning line 103 within approximately half of the area in the horizontal direction of the QR code. When it is found that the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area is approximately equal to 1:1:3:1:1, record the X coordinate position. As Figure 11 shown, when scanning the entire area of the QR code with uniform color, the X coordinates of all areas satisfying this ratio value (1:1:3:1:1) can be roughly obtained, that is, the X coordinate values of the square-within-a-square pattern 10.
[0068] The same applies to the Y direction. Start vertical scanning from the upper left corner along the Y-direction scanning line 104 within approximately half of the area in the vertical direction of the QR code. When it is found that the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area is approximately equal to 1:1:3:1:1, record the Y coordinate position. When scanning the entire area, the Y coordinates of all areas satisfying this ratio value (1:1:3:1:1) can be roughly obtained, that is, the Y coordinate values of the square-within-a-square pattern 10.
[0069] When scanning, record the starting position of the black-and-white change, then multiple square-within-a-square candidate areas can be obtained. Each square-within-a-square candidate area includes adjacent white areas, black areas, white areas, black areas, and white areas in sequence, and the widths of the adjacent white areas and black areas can be obtained. When it is judged that the ratio of the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area approximately satisfies 1:1:3:1:1, the algorithm is required to be robust. It cannot be set that only when the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area = 1:1:3:1:1 does it meet the judgment condition of the square-within-a-square pattern 10. A certain degree of fault tolerance is required. For example, the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area = 20:30:50:21:24 may also be the square-within-a-square pattern 10, which is due to the poor quality of the on-site QR code. This situation should be adaptable.
[0070] This application does not use the method of judging whether the pattern of a square-within-a-square candidate area is the square-within-a-square pattern 10 based on the square of the distance difference. This application uses the KL divergence in statistical analysis to judge whether the pattern of a square-within-a-square candidate area is the square-within-a-square pattern 10. The KL divergence can measure the closeness of two probability distributions.
[0071] The KL divergence (Kullback-Leibler divergence) is also called the KL distance, which is used to calculate the distance difference between two distributions, the distribution and The KL divergence calculation formula is: .
[0072] In order to evaluate whether the ratio of the width of the white area: the width of the black area: the width of the white area: the width of the black area: the width of the white area in the square character candidate area is close to 1:1:3:1:1 using the KL divergence, first obtain the width distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence as follows: ; where represents the width distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area; respectively represent the widths of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area.
[0073] It can be normalized to obtain the width probability distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area, which is expressed as: ; where represents the width probability distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area; represents the sum of the widths of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area; where .
[0074] This application uses the first preset probability distribution as the ideal probability distribution, and calculates the KL divergence of relative to the first preset probability distribution, that is, the first KL divergence; where the first preset probability distribution is expressed as: ; correspondingly, the first KL divergence of relative to the first preset probability distribution is:
[0075] When the first KL divergence corresponding to a square character candidate area is greater than or equal to 0 and less than the first preset threshold, it means that the width probability distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence in this square character candidate area are relatively close to the ideal first preset probability distribution, and it can be determined that this square character candidate area is the area where the square character pattern 10 is located. In an example of this application, the first preset threshold is 0.15.
[0076] For example, the width distributions of the white area, black area, white area, black area, and white area that are adjacent in sequence in the horizontal or vertical direction of the square character candidate area ; The width probability distribution of the white regions, black regions, white regions, black regions, and white regions that are adjacent to each other in sequence in the horizontal or vertical direction of the square candidate area . The first KL divergence with respect to the first preset probability distribution is: .
[0077] By means of the method of sampling along the X direction or the Y direction, and the method of determining the square pattern 10, several X coordinate values and several Y coordinate values in the square pattern area can be obtained. In order to exclude the influence of noise, the method of taking the median can be used to determine the center point of the square pattern 10, that is, sorting several Xs and Ys, and then taking the coordinates formed by the X coordinate value at the middle position and the Y coordinate value at the middle position as the coordinates of the center point of the final square pattern area, and taking the coordinates of the center point of the final square pattern area as the coordinates of the center point of the square pattern 10.
[0078] Correspondingly, step S140 includes: S141, scanning the unified color QR code image to obtain multiple square candidate areas, each square candidate area including white regions, black regions, white regions, black regions, and white regions that are adjacent to each other in sequence; S142, calculating the first KL divergence of the width probability distribution of the white regions, black regions, white regions, black regions, and white regions that are adjacent to each other in sequence in each square candidate area with respect to the first preset probability distribution; S143, determining the position of the square pattern based on the first KL divergence.
[0079] The width probability of each area of the square candidate area is equal to the ratio of the width of the area to the sum of the widths of the white regions, black regions, white regions, black regions, and white regions that are adjacent to each other in sequence in the square candidate area.
[0080] Step S143 includes: S1431, taking the square candidate area with the first KL divergence greater than or equal to 0 and lower than the first preset threshold as the final square pattern area; S1432, calculating the coordinates of the center point of the final square pattern area as the coordinates of the center point of the square pattern.
[0081] In step S150, the basic information of the QR code is determined based on the position of the square pattern, where the basic information includes version information, module arrangement method, and module quantity information. Currently, there are multiple versions of QR codes, and each version of the QR code has an inherent module arrangement method and module arrangement quantity. The module of the QR code refers to the square black and white dots that make up the QR code. For example, in an example of the present application, the QR code has 29 * 29 modules, and is arranged in the manner of 29 modules per row and 29 modules per column.
[0082] The relative positions of the three back-shaped patterns 10 in each version of the QR code are specific; the number of modules corresponding to the back-shaped patterns 10 is fixed at 7. Accordingly, after obtaining the positions of the three back-shaped patterns 10 in the QR code, it is easy to obtain information such as the version of the QR code, the module layout, and the number of modules.
[0083] In step S160, the corrected matrix is obtained based on the basic information of the QR code. Some versions of the QR code have an alignment pattern 20, while some versions do not. If, after obtaining the basic information of the QR code, it is found that the QR code does not have an alignment pattern 20, the corrected matrix is obtained using the back-shaped pattern 10; if, after obtaining the basic information of the QR code, it is found that the QR code has an alignment pattern 20, the corrected matrix is obtained using both the back-shaped pattern 10 and the alignment pattern 20.
[0084] Accordingly, step S160 includes: S161, determining whether the QR code contains an alignment pattern based on the basic information of the QR code; S162, in response to the QR code containing an alignment pattern, obtaining the corrected matrix through the position of the back-shaped pattern 10 and the alignment pattern; or, S163, in response to the QR code not containing an alignment pattern 20, obtaining the corrected matrix through the back-shaped pattern 10 in the uniform color QR code image.
[0085] Specifically, after the positions and version information of the three back-shaped patterns 10 of the QR code are determined in step S162, the position of the alignment pattern 20 can be calculated. The position of the alignment pattern 20 is fixed in the QR code, so the approximate position of the alignment pattern 20 can be calculated. However, this position may be slightly offset from the center of the alignment pattern 20, so fine adjustment is required.
[0086] Accordingly, the corrected matrix is obtained by the positions of the back-shaped pattern and the alignment pattern 20, including: S1621, calculating the position of the alignment pattern in the uniform color QR code image based on the positions of at least two back-shaped patterns; S1622, constructing the corrected matrix based on the positions of the back-shaped pattern and the alignment pattern.
[0087] Specifically, the second back-shaped pattern 12 and the alignment pattern 20 are located on the second diagonal of the QR code; the first back-shaped pattern 11 and the second back-shaped pattern 12 are located on the first side of the QR code; the second back-shaped pattern 12 and the third back-shaped pattern 13 are located on the second side of the QR code; the third back-shaped pattern 13 and the alignment pattern 20 are located on the third side of the QR code; and the first back-shaped pattern 11 and the alignment pattern 20 are located on the fourth side of the QR code.
[0088] like Figure 12As shown, based on the positions of the first and third back-shaped patterns 11 and 13, the specific edges of the first and third back-shaped patterns 11 and 13 can be determined respectively. Then, the intersection point of the two edges is calculated. This intersection point is the approximate location of the center point of the alignment pattern 20, which can be defined as the initial center point of the alignment pattern 20. Next, a region is searched within the area surrounding the initial center point of the alignment pattern 20, where the width ratio of the adjacent white, black, and white regions in the horizontal or vertical directions is approximately 1:1:1. When a region is found where the width ratio of the white region to the black region to the white region in the horizontal direction around the initial center point of the alignment pattern 20 is approximately 1:1:1, the X-coordinate position is recorded. When a region is found where the width ratio of the white region to the black region to the white region in the vertical direction around the initial center point of the alignment pattern 20 is approximately 1:1:1, the Y-coordinate position is recorded.
[0089] Accordingly, step S1621 includes: S16211, determining the edge line of the first character pattern facing the third side of the QR code and the edge line of the third character pattern facing the fourth side of the QR code; S16212, taking the intersection point of the edge line of the first character pattern facing the third side of the QR code and the edge line of the third character pattern facing the fourth side of the QR code as the preliminary center point of the alignment pattern; S16213, probing the area around the preliminary center point of the alignment pattern to determine the alignment pattern area.
[0090] During the process of probing the area surrounding the initial center point of alignment pattern 20, the starting position of the black-and-white transition is recorded, thus obtaining multiple alignment candidate areas. Each alignment candidate area includes sequentially adjacent white areas, black areas, and white areas, and the widths of the sequentially adjacent white and black areas can be obtained. When determining whether the ratio of white area width: black area width: white area width is approximately 1:1:1, the algorithm must be robust. It cannot be set that the condition for aligning pattern 20 is only satisfied if the ratio of white area width: black area width: white area width is exactly 1:1:1. A certain degree of fault tolerance is required. For example, a white area width: black area width: white area width = 20:21:24 might also be alignment pattern 20. This is due to poor QR code quality on site, and the algorithm should be able to adapt to this situation.
[0091] This application does not use the method of determining whether the pattern of an alignment candidate region is an alignment pattern 20 based on the squared difference of distance. Instead, this application uses KL divergence in statistical analysis to determine whether the pattern of an alignment candidate region is an alignment pattern 20.
[0092] To evaluate whether the ratio of white region width:black region width:white region width in the aligned candidate region is close to 1:1:1 using KL divergence, we first obtain the width distribution of sequentially adjacent white regions, black regions, and white regions as follows: ;in, This indicates the width distribution of the alignment candidate region in the horizontal or vertical direction, where white, black, and white regions are sequentially adjacent. These represent the widths of the white, black, and white regions that are sequentially adjacent in the horizontal or vertical direction, respectively, representing the alignment candidate areas.
[0093] This can be normalized to obtain the width probability distribution of the aligned candidate regions in the horizontal or vertical directions, consisting of successively adjacent white, black, and white regions, as shown below: ;in, This represents the probability distribution of the width of the aligned candidate region in the horizontal or vertical direction, where the white, black, and white regions are sequentially adjacent. This represents the sum of the widths of the adjacent white, black, and white regions in the horizontal or vertical direction of the alignment candidate region; where, .
[0094] This application uses a second preset probability distribution as a reference. The ideal probability distribution is calculated by... The KL divergence relative to the second preset probability distribution, i.e., the second KL divergence; wherein the second preset probability distribution is expressed as: .
[0095] Accordingly, The second KL divergence relative to the second preset probability distribution is: .
[0096] When the second KL divergence corresponding to an alignment candidate region is greater than or equal to 0 and lower than the second preset threshold, it indicates that the width probability distribution of the successively adjacent white, black, and white regions of the alignment candidate region is close to the ideal second preset probability distribution, and the alignment candidate region can be determined to be an alignment pattern region. In one example of this application, the second preset threshold is 0.15.
[0097] For example, the width distribution of the candidate regions in the horizontal or vertical direction of sequentially adjacent white, black, and white regions. The probability distribution of the width of the aligned candidate regions in the horizontal or vertical directions of sequentially adjacent white, black, and white regions. . The second KL divergence relative to the second preset probability distribution is: .
[0098] Through the above method for determining the alignment pattern 20, several X coordinate values and several Y coordinate values in the alignment pattern area can be obtained. To exclude the influence of noise, the method of taking the median can be used to determine the final center point of the alignment pattern 20, that is, sort several Xs and Ys, and then take the coordinate formed by the X coordinate value at the middle position and the Y coordinate value at the middle position as the coordinate of the final center point of the final alignment pattern area, and take the coordinate of the center point of the final alignment pattern area as the coordinate of the final center point of the alignment pattern 20.
[0099] Correspondingly, step S16213 includes: S162131, scanning the unified color QR code image to obtain multiple alignment candidate areas, each alignment candidate area including successively adjacent white areas, black areas, and white areas; S162132, calculating the second KL divergence of the width probability distribution of the successively adjacent white areas, black areas, and white areas in each alignment candidate area relative to the second preset probability distribution; S162133, determining the position of the alignment pattern based on the second KL divergence.
[0100] The width probability of each area of the alignment candidate area is equal to the ratio of the width of the area to the sum of the widths of the successively adjacent white areas, black areas, and white areas of the alignment candidate area.
[0101] Step S162133 includes: S1621331, taking the alignment candidate area with the second KL divergence greater than or equal to 0 and lower than the second preset threshold as the final alignment pattern area; S1621332, calculating the coordinate of the final center point of the final alignment pattern area as the coordinate of the final center point of the alignment pattern.
[0102] In step S1622, a corrected matrix is constructed based on the positions of the square-within-a-square pattern and the alignment pattern. To be able to process distorted QR codes, the present application will perform local partitioning on the QR code. And perform affine or perspective transformation processing on each local area to efficiently process distorted QR codes. In addition, the present application uses the colors of each module of the QR code in the initial image as the colors of the corrected matrix, avoiding information loss caused by binarization and thus being unable to recognize the QR code.
[0103] Correspondingly, step S1622 includes: S16221, partitioning the unified color QR code image into multiple local areas based on the positions of the square-within-a-square pattern and the alignment pattern; S16222, obtaining the matrix transformation relationships between the multiple local areas and the multiple local areas in the initial image; S16223, determining the colors of each module of the QR code in the initial image corresponding to each module of the multiple local areas in the unified color QR code image based on the matrix transformation relationships to obtain the corrected matrix.
[0104] In step S16221, the unified color QR code image is divided into multiple local regions based on the positions of the square-within-a-square pattern and the alignment pattern. As Figure 13 shown, in this application, the unified color QR code image is divided into local regions by multiple control points 30; Figure 13 the multiple green dots in it represent the multiple control points 30. In an embodiment of this application, the multiple control points 30 are feature points selected from the square-within-a-square pattern 10 and the alignment pattern 20.
[0105] Correspondingly, in an embodiment of this application, step S16221 includes: S162211, selecting at least one point of the square-within-a-square pattern and at least one point of the alignment pattern in the unified color QR code image as control points; S162212, dividing the unified color QR code image into multiple local regions based on the multiple control points.
[0106] In one example of this application, the center point of each alignment pattern 20 in the uniform color QR code image is selected as a control point 30; three points of each back-shaped pattern 10 in the uniform color QR code image are selected as control points 30; wherein, the first control point and the second control point on the first back-shaped pattern 11 are located on the edge line of the first back-shaped pattern 11 facing the second side of the QR code and are located in the edge region of the first back-shaped pattern 11 and are in a straight line with the center point of the alignment pattern 20, wherein the first control point is closer to the second control point in the relative direction of the first side and the second side of the QR code. Align the center point of pattern 20; the third control point on the first back-shaped pattern 11 is located on the third side of the first back-shaped pattern 11 facing the QR code and is located in the edge area of the first back-shaped pattern 11 and is in a straight line with the first control point, wherein the line containing the first control point and the second control point is perpendicular to the line containing the first control point and the third control point; the fourth and fifth control points on the second back-shaped pattern 12 are located on the third side of the second back-shaped pattern 12 facing the QR code and are located in the edge area of the second back-shaped pattern 12 and are in a straight line with the first control point and the third control point. On a straight line, the fourth control point is closer to the first control point in the relative direction between the second and fourth sides of the QR code than the fifth control point; the sixth control point on the second back-shaped pattern 12 is located on the edge line of the second back-shaped pattern 12 facing the fourth side of the QR code and is located in the edge region of the second back-shaped pattern 12 and is on a straight line with the fourth control point, wherein the straight line containing the fourth and sixth control points is perpendicular to the straight line containing the fourth and fifth control points; the seventh and eighth control points on the third back-shaped pattern 13 are located on the first side of the third back-shaped pattern 13 facing the QR code. The seventh control point is located on the edge of the third back-shaped pattern 13 and is in line with the center point of the alignment pattern 20. The seventh control point is closer to the center point of the alignment pattern 20 than the eighth control point in the relative direction between the second and fourth sides of the QR code. The ninth control point on the third back-shaped pattern 13 is located on the edge of the fourth side of the third back-shaped pattern 13 facing the QR code and is in line with the seventh control point. The line containing the seventh and ninth control points is perpendicular to the line containing the seventh and eighth control points.
[0107] It is worth mentioning that in step S162212, the uniform color QR code image is divided into multiple local regions based on multiple control points. The uniform color QR code image can be divided into multiple local regions containing different numbers of control points 30, so that different types of matrix transformations can be performed on regions with different numbers of control points 30 in the subsequent matrix transformation process. Such distinctive localization processing is more effective in handling complex nonlinear distortions than a single global transformation.
[0108] In one embodiment of this application, step S162212 includes: dividing the uniform color QR code image into a local region containing only 3 control points 30, and / or dividing the uniform color QR code image into a local region containing only 4 control points 30, such as... Figure 14 As shown.
[0109] In one embodiment of this application, a radial transformation matrix is calculated for a local region containing only 3 control points 30; and a perspective transformation matrix is calculated for a local region containing only 4 control points 30.
[0110] Accordingly, step S16222 includes: S162221, obtaining the affine transformation relationship between the local region containing only 3 control points and the local region in the initial image; S162222, obtaining the perspective transformation relationship between the local region containing only 4 control points and the local region in the initial image.
[0111] In step S16223, the colors of each module in the initial image of the QR code corresponding to each module in multiple local regions of the unified color QR code image are determined based on the matrix transformation relationship to obtain the corrected matrix. After obtaining the version information of the QR code, the dimension of the QR (i.e., the arrangement and number of modules) can be determined based on the version information. Assuming the dimension is 29×29, the QR code is a 29×29 0, 1 matrix, where 0 represents black and 1 represents white.
[0112] By iterating through 29×29 points (i.e. modules), and then using the corresponding transformation matrix relationship, we can know the position of the point on the original image. We only need to determine whether the point is black or white on the original image.
[0113] Unlike previous algorithms that sampled directly from the binarized black-and-white image, this application samples directly from the original image, thus avoiding information loss caused by direct binarization. Specifically, the original image is first preprocessed, for example, by Gaussian filtering to remove noise; then, each point is traversed according to the dimensions of the QR; next, the position of the point in the original image is calculated according to the matrix transformation relationship; then, the mean value within a preset local region (the size of several modules can be set) at the point is calculated; the pixel value of the initial image is obtained within the local region of the point, for example, within a 3×3 or 5×5 local region of the point, and the number of modules with pixel values greater than and less than the mean value in the local region of the initial image at the point, n1 and n2, are counted respectively; if n1>n2, the color of the point is considered white, otherwise it is black; after traversal, a 29×29 corrected matrix is obtained. In this application, the pixel value range is 0-255 (0=black, 255=white).
[0114] Accordingly, step S16223 includes: S162231, preprocessing the initial image; S162232, determining the color of each module of the QR code in the preprocessed initial image based on the basic information of the QR code; S162233, forming a corrected matrix based on the color of each module of the QR code in the preprocessed initial image; wherein the module arrangement and number of modules in the corrected matrix are consistent with the module arrangement and number of modules determined by the basic information of the QR code, and the color of each module is consistent with the color of each module of the QR code in the initial image.
[0115] Step S162233 includes: S1622331, determining the average pixel value of multiple modules in a local area of a preset size where each module of the QR code is located in the preprocessed initial image based on the module arrangement and number of modules of the QR code; S1622332, comparing the number of modules with pixel values greater than the average pixel value and the number of modules with pixel values less than the average pixel value in the local area of the preset size where the module is located; S1622333, in response to the number of modules with pixel values greater than the average pixel value in the local area of the preset size where the module is located being greater than the number of modules with pixel values less than the average pixel value, determining that the color of the module is white, otherwise it is black.
[0116] In step S163, in response to the QR code not containing an alignment pattern, the corrected matrix is obtained through the back-shaped pattern in the unified color QR code image. Specifically, the unified color QR code image is divided into multiple local regions based on the back-shaped pattern 10; the matrix transformation relationship between the multiple local regions and the multiple local regions in the initial image is obtained; based on the matrix transformation relationship, the color of each module of the QR code in the initial image corresponding to each module in the multiple local regions of the unified color QR code image is determined to obtain the corrected matrix.
[0117] In the process of dividing the uniform color QR code image into multiple local areas based on the back pattern 10, multiple points of the back pattern 10 in the uniform color QR code image are first selected as control points 30, and then the uniform color QR code image is divided into multiple local areas based on the multiple control points 30.
[0118] In the process of dividing a uniform color QR code image into multiple local regions based on multiple control points 30, the uniform color QR code image is divided into a local region containing only 3 control points 30, and / or, the uniform color QR code image is divided into a local region containing only 4 control points 30.
[0119] In the process of obtaining the matrix transformation relationship between multiple local regions and multiple local regions in the initial image, if there is a local region containing 3 control points 30, obtain the affine transformation relationship between the local region containing only 3 control points 30 and the local region in the initial image; obtain the perspective transformation relationship between the local region containing only 4 control points 30 and the local region in the initial image.
[0120] When a QR code does not contain an alignment pattern of 20, the process of determining the colors of each module in the initial image of the QR code corresponding to each module in multiple local regions of the QR code image based on matrix transformation relationship to obtain the corrected matrix can be referred to as the process of determining the colors of each module in the initial image of the QR code corresponding to each module in multiple local regions of the QR code image based on matrix transformation relationship to obtain the corrected matrix.
[0121] In step S170, the corrected matrix is decoded to identify the QR code. From initial positioning, view transformation, and color unification, to the positioning of the square pattern 10 and the alignment pattern 20, and finally to grid correction, the common goal is to generate an idealized, distortion-free, digital corrected matrix. However, this corrected matrix is still data in coded form, raw information that can be directly read or used by a computer; therefore, further decoding is required.
[0122] Specifically, the corrected matrix can be input into a QR code decoding library for decoding, such as Zbar, ZXing, OpenCV, etc.
[0123] In summary, the statistical analysis-based QR code recognition method has been clarified. This method improves the accuracy and stability of QR code recognition under complex lighting conditions, background interference, image distortion, and noise. Furthermore, through an optimized algorithm, computational complexity is effectively controlled while maintaining high accuracy, thus meeting the real-time requirements of practical applications. This enhances the reliability and practicality of QR code recognition technology under various demanding conditions.
[0124] The present application and its embodiments have been described above. This description is not restrictive, and the accompanying drawings are only one embodiment of the present application. The actual structure is not limited to this. In conclusion, if a person skilled in the art is inspired by this description and designs a similar structure and embodiment without departing from the spirit of the present application, such design should fall within the protection scope of the present application.
Claims
1. A QR code recognition method based on statistical analysis, characterized in that, The method comprises the following steps: locating a positioning QR code in an initial image to obtain a preliminary positioning area containing a QR code region; performing view transformation on the preliminary positioning area to obtain an orthographic view of the preliminary positioning area; unifying the background color of the QR code region in the orthographic view of the preliminary positioning area to white and the color of the QR code to black to obtain a unified color QR code image with black and white contrast; locating the positions of three backword letter patterns in the unified color QR code image based on a KL divergence statistical analysis method; determining the basic information of the QR code based on the positions of the backword letter patterns, wherein the basic information comprises version information, module arrangement mode and module quantity information; obtaining a corrected matrix based on the basic information of the QR code; decoding the corrected matrix to identify the QR code.
2. The QR code recognition method based on statistical analysis according to claim 1, characterized in that, The method for locating the positions of the three backword letter patterns in the unified color QR code image based on the KL divergence statistical analysis method comprises the following steps:
3. The QR code recognition method based on statistical analysis according to claim 2, characterized in that, scanning the unified color QR code image to obtain a plurality of backword letter candidate regions, each of which comprises sequentially adjacent white regions, black regions, white regions, black regions and white regions; 4. The QR code recognition method based on statistical analysis according to claim 3, characterized in that, calculating the first KL divergence of the width probability distribution of the sequentially adjacent white regions, black regions, white regions, black regions and white regions in each backword letter candidate region relative to a first preset probability distribution; 5. The QR code recognition method based on statistical analysis according to claim 4, characterized in that, determining the positions of the backword letter patterns based on the first KL divergence.
6. The QR code recognition method based on statistical analysis according to claim 5, characterized in that, The method for verifying the positions of the backword letter patterns in the backword letter candidate regions based on the first KL divergence comprises the following steps:
7. The QR code recognition method based on statistical analysis according to claim 6, characterized in that, regarding the backword letter candidate region with the first KL divergence greater than or equal to 0 and lower than a first preset threshold as a final backword letter pattern region; and calculating the coordinates of the center point of the final backword letter pattern region as the coordinates of the center point of the backword letter pattern. The method for obtaining the corrected matrix based on the basic information of the QR code comprises the following steps: judging whether the QR code contains an alignment pattern based on the basic information of the QR code; obtaining the corrected matrix through the positions of the backword letter patterns and the alignment pattern in response to the QR code containing the alignment pattern; or obtaining the corrected matrix through the backword letter patterns in the unified color QR code image in response to the QR code not containing the alignment pattern. The method for obtaining the corrected matrix through the positions of the backword letter patterns and the alignment pattern comprises the following steps: calculating the position of the alignment pattern in the unified color QR code image based on the positions of at least two backword letter patterns; and constructing the corrected matrix based on the positions of the backword letter patterns and the alignment pattern. The method for constructing the corrected matrix based on the positions of the backword letter patterns and the alignment pattern comprises the following steps: dividing the unified color QR code image into a plurality of local regions based on the positions of the backword letter patterns and the alignment pattern; obtaining the matrix transformation relationship between the plurality of local regions and a plurality of local regions in the initial image, respectively; and determining the colors of the modules of the QR code in the initial image corresponding to the modules in the plurality of local regions in the unified color QR code image based on the matrix transformation relationship to obtain the corrected matrix. The method for dividing the unified color QR code image into a plurality of local regions based on the positions of the backword letter patterns and the alignment pattern comprises the following steps: selecting at least one point of the backword letter patterns and at least one point of the alignment pattern in the unified color QR code image as control points; and dividing the unified color QR code image into a plurality of local regions based on the plurality of control points.
8. The QR code recognition method based on statistical analysis according to claim 7, characterized in that, The uniform color QR code image is divided into a plurality of local areas based on a plurality of control points, including: dividing the uniform color QR code image into a local area containing only 3 control points, and / or dividing the uniform color QR code image into a local area containing only 4 control points; obtaining a matrix transformation relationship between the plurality of local areas and a plurality of local areas in an initial image, including: obtaining an affine transformation relationship between the local area containing only 3 control points and the local area in the initial image; and obtaining a perspective transformation relationship between the local area containing only 4 control points and the local area in the initial image.
9. The QR code recognition method based on statistical analysis according to claim 8, characterized in that, Based on the matrix transformation relationship, the color of each module of the QR code in the initial image corresponding to each module in the plurality of local areas in the uniform color QR code image is determined to obtain a corrected matrix, including: preprocessing the initial image; determining the color of each module of the QR code in the preprocessed initial image based on the basic information of the QR code; forming the corrected matrix based on the color of each module of the QR code in the preprocessed initial image; wherein the module arrangement and the number of modules of the corrected matrix are consistent with the module arrangement and the number of modules determined by the basic information of the QR code, and the color of each module is consistent with the color of each module of the QR code in the initial image.
10. The QR code recognition method based on statistical analysis according to claim 9, characterized in that, Based on the basic information of the QR code, the color of each module of the QR code in the preprocessed initial image is determined, including: determining the average pixel value of a plurality of modules in a local area with a preset size where each module of the QR code in the preprocessed initial image is located based on the module arrangement and the number of modules of the QR code; comparing the number of modules with pixel values greater than the average pixel value and the number of modules with pixel values less than the average pixel value in the local area with the preset size where the module is located; and in response to the number of modules with pixel values greater than the average pixel value being greater than the number of modules with pixel values less than the average pixel value in the local area with the preset size where the module is located, determining that the color of the module is white, otherwise black.