Two-dimensional code recognition method, electronic equipment and computer program product
By performing Fourier transform and frequency domain denoising on the QR code image, the problems of high resource requirements and poor real-time performance of QR code recognition are solved, achieving efficient and accurate QR code recognition.
Patent Information
- Application Number
- CN202511041463.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-11-14
AI Technical Summary
In existing technologies, QR code recognition methods have high computational resource requirements, are difficult to construct high-quality datasets, have high annotation costs, and affect the real-time performance of recognition.
By performing a Fourier transform on the QR code image, the frequency domain signal of the image is obtained. The frequency domain signal is then denoised and subjected to an inverse Fourier transform to obtain the pixel matrix to be identified. Finally, the QR code is decoded based on the QR code decoding algorithm.
It improves the accuracy and efficiency of QR code recognition, reduces recognition complexity and cost, enhances decoding success rate in low-contrast and noisy environments, and is suitable for real-time response scenarios.
Smart Images

Figure CN120952027A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of QR code technology, and in particular to a QR code recognition method, electronic device, and computer program product. Background Technology
[0002] With the rapid development of computer technology, QR codes are being used in an increasing number of scenarios, such as e-commerce, logistics, automobiles, batteries, and the pharmaceutical industry. A QR code is a black-and-white graphic that uses specific geometric shapes arranged in a certain pattern on a two-dimensional plane to record data symbols.
[0003] Currently, traditional methods for recognizing QR codes involve filling or segmenting the QR code image and then inputting it into a convolutional decoding model or a fuzzy kernel classification model for classification and recognition. These methods have high requirements for device resources, limiting their application scenarios. Furthermore, collecting high-quality data is difficult and the annotation cost is high. Additionally, the overall recognition time is increased during image processing and model inference, affecting real-time performance. Summary of the Invention
[0004] According to various embodiments of this application, a QR code recognition method, electronic device, and computer program product are provided; these can reduce the cost of QR code image recognition and improve recognition efficiency.
[0005] Firstly, this application provides a QR code recognition method, which includes:
[0006] The process involves acquiring the initial first image of the QR code and converting it into a black-and-white second image; performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image; performing frequency domain denoising on the first frequency domain information to obtain the second frequency domain information of the second image; performing an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the second image; and decoding the second pixel matrix based on the decoding standard corresponding to the QR code to obtain the QR code recognition result.
[0007] By converting the QR code image into a black and white image using the above method, a Fourier transform is performed on the image to obtain its frequency domain information. Noise reduction is then performed based on this frequency domain information, improving the accuracy and efficiency of QR code recognition, reducing recognition complexity and cost, increasing decoding success rate in low-contrast and noisy environments, and demonstrating strong ease of use and practicality.
[0008] In one possible implementation of the first aspect, converting the first image into a black-and-white second image includes:
[0009] The first image is processed to obtain a grayscale image of the first image; the grayscale image is then binarized and subjected to morphological processing to obtain the second image.
[0010] In one possible implementation of the first aspect, before performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image, the method further includes:
[0011] Detect the positioning pattern and clock pattern in the second image; calculate the perspective transformation matrix based on the positioning pattern, the clock pattern, and the standard QR code grid; perform geometric correction on the second image based on the perspective transformation matrix; wherein the geometrically corrected second image is aligned with the standard QR code grid.
[0012] In one possible implementation of the first aspect, performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image includes:
[0013] Perform a one-dimensional Fourier transform on each row of the pixel sequence in the first pixel matrix to obtain a first pixel matrix in which each row of the pixel sequence satisfies the frequency threshold; perform a two-dimensional Fourier transform on the first pixel matrix in which each row of the pixel sequence satisfies the frequency threshold to obtain the first frequency domain information.
[0014] In one possible implementation of the first aspect, the step of performing frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image includes:
[0015] The preset band-stop filter is multiplied with the first frequency domain information to perform frequency domain denoising processing, thereby obtaining the second frequency domain information of the second image.
[0016] In one possible implementation of the first aspect, after performing an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the two images, the method further includes:
[0017] The second pixel matrix is binarized using a local thresholding algorithm to obtain a denoised pixel matrix; the denoised pixel matrix is then downsampled to obtain a QR code standard decoding matrix.
[0018] In one possible implementation of the first aspect, the QR code standard decoding matrix is decoded based on the decoding standard corresponding to the QR code to obtain the QR code recognition result.
[0019] In one possible implementation of the first aspect, after converting the first image into a black-and-white second image, the method further includes:
[0020] Along the rows and columns of the QR code, the pixels of the second image are collected to generate the first pixel matrix of the second image.
[0021] Secondly, this application provides a QR code recognition device, which includes:
[0022] The acquisition unit is used to acquire an initial first image of the QR code and convert the first image into a black and white second image.
[0023] The first processing unit is used to perform a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image;
[0024] The second processing unit is used to perform frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image.
[0025] The third processing unit is used to perform an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the two images;
[0026] The decoding unit is used to decode the second pixel matrix based on the decoding standard corresponding to the QR code to obtain the recognition result of the QR code.
[0027] Thirdly, this application provides an electronic device including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the method described in any one of the first aspects.
[0028] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in any one of the first aspects.
[0029] Fifthly, this application provides a computer program product that, when run on a device, causes the device to perform the method described in any one of the first aspects above.
[0030] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0031] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 A schematic diagram illustrating the implementation process of the QR code recognition method provided in this application embodiment;
[0033] Figure 2 A schematic diagram of the QR code positioning pattern and clock pattern provided in the embodiments of this application;
[0034] Figure 3 A schematic diagram of another positioning pattern and clock pattern of the QR code provided in the embodiments of this application;
[0035] Figure 4 This is a schematic diagram of the structure of the QR code recognition device provided in the embodiments of this application;
[0036] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0037] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.
[0038] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.
[0039] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.
[0040] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0041] In the description of the embodiments in this application, 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 " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.
[0042] Currently, QR code recognition based on convolutional models has high requirements for computing resources and memory, which may lead to performance bottlenecks in resource-constrained scenarios such as embedded or mobile devices. Furthermore, it requires the construction of high-quality datasets covering complex scenarios (such as low light, noise, and dynamic environments), which is difficult to construct and has high annotation costs. The processing of QR code images, model inference, and decoding matrices increases the overall recognition implementation, thus affecting the real-time performance of the recognition response.
[0043] To address the above technical issues, this application provides a QR code recognition method. This method involves performing a Fourier transform on the QR code image to obtain its frequency domain signal, denoising the frequency domain signal, and then performing an inverse Fourier transform to obtain the pixel matrix to be recognized. Finally, a QR code decoding algorithm is used to decode the image and obtain the QR code recognition result. Based on Fourier transform and frequency domain denoising, the method improves the efficiency and accuracy of QR code recognition in complex scenarios, making it better suited for real-time response scenarios.
[0044] The implementation process of QR code recognition is described below through specific examples.
[0045] Please see Figure 1 , Figure 1 This is a schematic diagram illustrating the implementation flow of the QR code recognition method provided in this application embodiment. The method may include the following steps:
[0046] S101, acquire the initial first image of the QR code, and convert the first image into a black and white second image.
[0047] In this embodiment, the electronic device may be equipped with a camera to capture an initial first image of the QR code, or the electronic device may acquire a first image transmitted by an independently configured camera. This first image may be a color, distortion-free QR code image containing R (red), G (green), and B (blue) three-channel pixel values. The electronic device acquires the color first image, performs grayscale processing on the first image, and then performs binarization processing to convert the first image into a black-and-white second image.
[0048] For example, the type of QR code in the captured QR code image may include Quick Response Code (QR) and Data Matrix Code (DM).
[0049] In some embodiments, converting a first image into a black-and-white second image includes: performing grayscale processing on the first image to obtain a grayscale image of the first image; and performing binarization and morphological processing on the grayscale image to obtain a second image.
[0050] For example, the first image can be a color image in RGB format, or a color image in various formats such as Hue, Saturation, Value / Brightness / Lightness (HSV / HSB / HSL format), or Luminance (Y) and Chromaticity (UV) (YUV format). The first image is converted to a grayscale image by multiplying and summing the three-channel pixel values of the acquired first image based on a preset scaling factor. Taking an RGB format first image as an example, the conversion process can be calculated using the following expression:
[0051] I gray = 0.299×R + 0.587×G + 0.114×B
[0052] Where R, G, and B are the pixel values of the first image in the red, green, and blue channels, respectively, and I... gray These are the pixel values of the grayscale image.
[0053] Accordingly, based on local thresholding algorithms (such as the Sauvola algorithm), grayscale images are binarized to adapt to application scenarios with uneven lighting; for example, the following expression is used to binarize a grayscale image:
[0054]
[0055] Where x is the x-coordinate of a pixel in the grayscale image, y is the y-coordinate of a pixel in the grayscale image, μ(x,y) is the local mean of the pixel value (or grayscale value) corresponding to each pixel in the grayscale image, σ(x,y) is the local standard deviation of the pixel value (or grayscale value) corresponding to each pixel in the grayscale image, k is an adjustment parameter (usually ranging from 0.2 to 0.5), P is the dynamic range of the grayscale value (usually 128), and T(x,y) is the local threshold calculated based on the local mean and local standard deviation.
[0056] For example, by processing the grayscale of the first image, the grayscale value of each pixel is calculated, and a local threshold corresponding to a neighborhood window (such as a local region) is calculated based on the grayscale values of all pixels. Then, the grayscale value of each pixel in the grayscale image is compared with the local mean to obtain the binarized second image. For example, the binarized second image is obtained based on the following expression:
[0057]
[0058] Among them, I binary (x,y) represents the pixel values of each pixel in the binarized second image.
[0059] For example, after binarizing the first image, morphological processing can be performed on the binarized image, such as performing a closing operation on the grayscale image to fill the empty parts inside the QR code module in the first image, and then performing an opening operation to eliminate isolated noise, remove image burrs, blemishes, and broken or missing lines that appear in the image processing, to obtain the second image.
[0060] In some embodiments, the method further includes: detecting a positioning pattern and a clock pattern in the second image; calculating a perspective transformation matrix based on the positioning pattern, the clock pattern, and a standard QR code grid; and performing geometric correction on the second image based on the perspective transformation matrix; wherein the geometrically corrected second image is aligned with the standard QR code grid.
[0061] For example, for the binarized second image, the positioning pattern and clock pattern of the QR code in the second image are detected by Hough transform. A two-dimensional parameter space is established based on the features of clock and timing patterns of different types of QR codes; by traversing each edge point in the image, the pixels that conform to the two-dimensional parameter space are calculated and accumulated in the parameter space, and the local maximum value where the accumulated value is greater than a threshold is found to determine the features in the image.
[0062] For example, Figure 2 The image of the data matrix code shown is used to filter out lines that are close to horizontal or vertical based on the angle or direction features of the detected lines, and to obtain pairs of lines that are perpendicular to each other and reasonably spaced, thus determining the L-shaped positioning pattern.
[0063] For example, Figure 3 The fast response matrix code shown identifies three positioning markers by detecting straight lines and based on the geometric characteristics of the positioning pattern. For example, if a feature region with a 1:1:3:1:1 ratio of black and white modules is detected in both the horizontal and vertical directions of the QR code image, the center point of this region is taken as the center point of the position detection pattern. Finally, the position of the positioning pattern is calculated to determine the direction and angle of the QR code image. The ratio of the number of black and white modules refers to the ratio of the number of black modules to the number of white modules in different regions when the black modules (i.e., the black squares in the QR code) in the positioning pattern (position detection pattern) are arranged horizontally or vertically.
[0064] Accordingly, by detecting circles in the second image as the outer frame of the clock and straight lines in the second image as the hands of the clock, the clock's trajectory is analyzed based on the detected circles and lines to determine the clock pattern. Therefore, based on the detected positioning pattern and clock pattern, the position and type of the QR code pattern can also be determined.
[0065] For example, after detecting the positioning pattern and clock pattern of the QR code in the second image, the position, orientation and angle of the QR code are determined. Based on the position, orientation and angle of the QR code, the perspective transformation matrix of the image is calculated, and the QR code in the second image is geometrically corrected to ensure that the positioning pattern and clock trajectory of the QR code image are aligned with the square grid.
[0066] For example, based on the detected positioning pattern, the four corner points of the QR code are determined, and the four corrected target corner points are determined based on the square grid. The perspective transformation matrix is calculated using the getPerspectiveTransform function in OpenCV, and the perspective transformation is performed on the QR code image using the warpPerspective function to ensure that the square grid of the QR code is aligned.
[0067] In some embodiments, the method further includes: acquiring pixels of the second image along the row and column directions of the QR code to generate a first pixel matrix of the second image.
[0068] For example, after correcting the QR code in the second image, sampling is performed along the row and column directions of the corrected QR code to collect each pixel of the QR code pattern in the second image, generating a first pixel matrix P(x,y); where x = 1, ..., n; y = 1, ..., m; n is the pixel width of the QR code pattern, and m is the pixel height of the QR code pattern. Since the value of each pixel is 0 or 1 after binarization, the first pixel matrix is a binary matrix containing only 0 and 1; thus, the number of modules N*M of the QR code pattern can be determined based on the value and position of the pixel; where each module (black block or white block) of the QR code pattern can include multiple pixels, i.e., N is less than n, and M is less than m.
[0069] For example, a black block corresponds to a 4×4 pixel matrix with 16 pixels having a value of 0, while the adjacent 4×4 pixel matrix has 16 pixels with a value of 1, thus corresponding to a white block. The correspondence between black and white blocks and local pixel matrices is merely illustrative and can be determined based on the binarized values of each pixel in the QR code pattern. Each module of the QR code pattern can include a local pixel matrix composed of different numbers of pixels.
[0070] S102, Perform Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image.
[0071] In the embodiment of the present application, a discrete Fourier transform is performed on the first pixel matrix of the second image to convert the two-dimensional code image from the spatial domain (i.e., the pixel matrix) to frequency domain information. Since each pixel value in the first pixel matrix is 0 or 1 after binarization processing, the subsequent calculation process of performing a discrete Fourier transform on the first pixel matrix is simplified.
[0072] Among them, performing a discrete Fourier transform on the first pixel matrix to obtain the frequency domain information of the two-dimensional code pattern represented by a complex matrix, that is, the first frequency domain information. The first frequency domain information includes an amplitude spectrum (amplitude) and a phase spectrum. By taking the logarithmic amplitude spectrum, high-frequency (such as the edges or details of the two-dimensional code pattern) and low-frequency (the overall result of the two-dimensional code pattern) components are determined.
[0073] Exemplarily, the positioning pattern and clock pattern of the two-dimensional code can be manifested as specific high-frequency components in the frequency domain information. Through discrete Fourier transform, this feature is strengthened, facilitating subsequent decoding processing. Through fast Fourier transform, the response speed of identifying the two-dimensional code can be improved, which is more suitable for real-time response scenarios.
[0074] In some embodiments, performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image includes:
[0075] Performing a one-dimensional Fourier transform on each row pixel sequence in the first pixel matrix to obtain a first pixel matrix where each row pixel sequence meets the frequency threshold; performing a two-dimensional Fourier transform on the first pixel matrix where each row pixel sequence meets the frequency threshold to obtain the first frequency domain information.
[0076] Exemplarily, performing a one-dimensional discrete Fourier transform on each row pixel sequence P(x,:) to extract the periodic features in the row and column directions, and the modular structure of the two-dimensional code is manifested as an alternately bright and dark periodic signal in the spatial domain. For example, through the following expression, performing a Fourier transform on each row pixel sequence:
[0077]
[0078] Among them, u is the row coordinate in the frequency domain, and N is the number of modules of the two-dimensional code pattern; after Fourier transform, the low-frequency components (the part that meets the frequency threshold, such as |u| < N / 4) are retained, and the rest are set to zero. Thus, high-frequency noise (such as scanning blurring, printing defects, stains, etc.) in each row pixel sequence is removed to obtain a first pixel matrix that meets the frequency threshold, achieving noise positioning; the frequency domain information after Fourier transform is concentrated in the region of |u| < N / 4.
[0079] Correspondingly, performing a two-dimensional Fourier transform on the first pixel matrix to obtain the first frequency domain information. For example, performing a two-dimensional Fourier transform through the following expression to obtain the first frequency domain information of the two-dimensional code pattern:
[0080]
[0081] Where u and v are the row and column coordinates in the frequency domain, respectively.
[0082] S103, perform frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image.
[0083] In this embodiment of the application, the first frequency domain information and the characteristics of periodic noise in the frequency domain are denoised in the frequency domain to obtain the second frequency domain information; wherein, the periodic noise includes noise that is common in industrial production, shooting and scanning processes and manifests as discrete spikes in the frequency domain, such as printing patterns, sensor grid noise and mechanical scanning stripes.
[0084] In some embodiments, performing frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image includes: multiplying a preset band-stop filter with the first frequency domain information to perform frequency domain denoising processing to obtain the second frequency domain information of the second image.
[0085] For example, based on the center frequency of the noise spike, a band-stop filter is designed to denoise the first frequency domain information of the second image; for example, the expression of the band-stop filter is as follows:
[0086]
[0087] Here, u0 and v0 are the center frequencies of the noise peaks in the frequency domain coordinates, which can be determined using the one-dimensional discrete Fourier transform. During image processing, the frequency domain characteristics of each row and column of pixels in the image are analyzed using the one-dimensional discrete Fourier transform to detect periodic noise (such as stripes, grid noise, etc.). Taking each row as an example, based on the obvious peak position (i.e., high-frequency or low-frequency component, depending on the noise period) of the periodic noise corresponding to that row in the frequency domain, the center frequency u0 of that row is initially estimated. Based on the same implementation principle as for each row, the center frequency v0 of each column is initially estimated based on the obvious peak position of the periodic noise corresponding to that column in the frequency domain.
[0088] Accordingly, the above-mentioned band-stop filter is applied to eliminate periodic noise, and the second frequency domain information is obtained. The expression for the calculation process is as follows:
[0089] F′(u,v)=F(u,v)·H(u,v)
[0090] Where F′(u,v) represents the second frequency domain information of the second image.
[0091] S104, perform inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the second image.
[0092] In this embodiment, the second frequency domain information is subjected to inverse discrete Fourier transform to obtain the image sequence P′(x,y) of the second image, i.e., the second pixel matrix; the expression for the inverse discrete Fourier transform is as follows:
[0093]
[0094] In some embodiments, after performing an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the second image, the method further includes:
[0095] The second pixel matrix is binarized using a local thresholding algorithm to obtain a denoised pixel matrix; the denoised pixel matrix is then downsampled to obtain the standard QR code decoding matrix.
[0096] For example, the second pixel matrix is binarized according to local contrast adaptive binarization to obtain the denoised pixel matrix Q(x,y); the expression for the binarization is as follows:
[0097]
[0098] Where μ(x,y) and σ(x,y) are the local mean and standard deviation of the pixel values calculated based on the denoised pixel matrix, respectively; α is an adjustment parameter, usually taken as 1 to 2.
[0099] Accordingly, after binarization, the obtained pixel matrix Q(x,y) is downsampled to N*M to obtain the QR code standard decoding matrix Q′(x,y).
[0100] S105 decodes the second pixel matrix based on the decoding standard corresponding to the QR code to obtain the QR code recognition result.
[0101] In the embodiments of this application, the type of QR code can be determined by recognizing the positioning pattern and clock pattern of the QR code as described above; for example, the type of QR code can be a Quick Response Matrix Code (QR code) or a Data Matrix Code (DM code).
[0102] In some embodiments, the QR code standard decoding matrix is decoded based on the decoding standard corresponding to the QR code to obtain the QR code recognition result.
[0103] For example, the ECC200 standard is used to decode DM codes, and the ISO / IEC 18004 decoding standard is used to decode QR codes.
[0104] In this embodiment, noise in the image is removed by Discrete Fourier Transform, which improves the decoding success rate and decoding robustness in low-contrast and noisy environments; frequency domain denoising makes the denoised pixel matrix clearer, reduces the bit error rate, and improves decoding accuracy; by using Discrete Fourier Transform and inverse transform, the computational complexity is reduced, and compared with traditional template matching and geometric feature decoding methods, the decoding speed is faster and the applicability is wider.
[0105] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0106] Corresponding to the QR code recognition method provided in the above embodiments, such as Figure 4 The diagram shown is a schematic representation of the structure of the QR code recognition device provided in this application embodiment. For ease of explanation, only the parts related to this application embodiment are shown.
[0107] The QR code recognition device includes:
[0108] Acquisition unit 41 is used to acquire the initial first image of the QR code and convert the first image into a black and white second image;
[0109] The first processing unit 42 is used to perform a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image.
[0110] The second processing unit 43 is used to perform frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image.
[0111] The third processing unit 44 is used to perform an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the two images;
[0112] Decoding unit 45 is used to decode the second pixel matrix based on the decoding standard corresponding to the QR code to obtain the recognition result of the QR code.
[0113] In one possible implementation, the acquisition unit 41 is further configured to perform grayscale processing on the first image to obtain a grayscale image of the first image; and to perform binarization and morphological processing on the grayscale image to obtain the second image.
[0114] In one possible implementation, the acquisition unit 41 is further configured to detect a positioning pattern and a clock pattern in the second image; calculate a perspective transformation matrix based on the positioning pattern, the clock pattern, and the standard QR code grid; and perform geometric correction on the second image based on the perspective transformation matrix; wherein the geometrically corrected second image is aligned with the standard QR code grid.
[0115] In one possible implementation, the first processing unit 42 is further configured to perform a one-dimensional Fourier transform on each row of pixel sequences in the first pixel matrix to obtain a first pixel matrix in which each row of pixel sequences satisfies a frequency threshold; and to perform a two-dimensional Fourier transform on the first pixel matrix in which each row of pixel sequences satisfies a frequency threshold to obtain the first frequency domain information.
[0116] In one possible implementation, the second processing unit 43 is further configured to multiply a preset band-stop filter with the first frequency domain information to perform frequency domain denoising processing, thereby obtaining the second frequency domain information of the second image.
[0117] In one possible implementation, the third processing unit 44 is further configured to perform binarization processing on the second pixel matrix based on a local thresholding algorithm to obtain a denoised pixel matrix; and to downsample the denoised pixel matrix to obtain a QR code standard decoding matrix.
[0118] In one possible implementation, the decoding unit 45 is further configured to decode the QR code standard decoding matrix based on the decoding standard corresponding to the QR code to obtain the recognition result of the QR code.
[0119] In one possible implementation, the acquisition unit 41 is further configured to acquire pixels of the second image along the row and column directions of the QR code to generate the first pixel matrix of the second image.
[0120] Figure 5 A schematic diagram of the hardware structure of electronic device 5 is shown.
[0121] like Figure 5 As shown, the electronic device 5 of this embodiment includes: at least one processor 51 ( Figure 5 Only one is shown in the diagram), and a memory 52 stores a computer program 53 that can run on the processor 51. When the processor 51 executes the computer program 53, it implements the steps in the above method embodiments, for example... Figure 1 S101 to S105 are shown. Alternatively, when the processor 51 executes the computer program 53, it implements the functions of each module / unit in the above-described device embodiments.
[0122] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 5. In other embodiments of this application, the electronic device 5 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0123] The electronic device 5 may include, but is not limited to, a processor 51 and a memory 52. Those skilled in the art will understand that... Figure 5 This is merely an example of electronic device 5 and does not constitute a limitation on electronic device 5. It may include more or fewer components than shown, or combine certain components, or different components. For example, the server may also include input sending devices, network access devices, buses, etc.
[0124] The processor 51 mentioned above can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.
[0125] The processor 51 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 51 is a cache memory. This memory can store instructions or data that the processor 51 has just used or that are used repeatedly. If the processor 51 needs to use the instruction or data again, it can directly retrieve it from the memory. This avoids repeated accesses, reduces the waiting time of the processor 51, and thus improves the efficiency of the system.
[0126] In some embodiments, the aforementioned memory 52 may be an internal storage unit of the electronic device 5, such as a hard disk or memory of the electronic device 5. The memory 52 may also be an external storage device of the electronic device 5, such as a plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, etc., equipped on the electronic device 5. Furthermore, the memory 52 may include both internal and external storage units of the electronic device 5. The memory 52 is used to store operating systems, applications, bootloaders, data, and other programs, such as program code for computer programs. The memory 52 can also be used to temporarily store data that has been sent or will be sent.
[0127] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0128] It should be noted that the structure of the above-mentioned electronic device is only illustrative and may include other physical structures depending on the application scenario. The physical structure of the electronic device is not limited here.
[0129] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0130] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.
[0131] This application provides a computer program product that, when run on a server, enables the server to execute the steps described in the above-described method embodiments.
[0132] If the integrated modules / units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.
[0133] The electronic devices, computer storage media, and computer program products provided in the embodiments of this application are all used to execute the methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects corresponding to the methods provided above, and will not be repeated here.
[0134] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0135] It should be understood that the above description is merely to help those skilled in the art better understand the embodiments of this application, and is not intended to limit the scope of the embodiments of this application. Based on the examples given above, those skilled in the art can obviously make various equivalent modifications or changes. For example, some steps in the various embodiments of the above detection method may be unnecessary, or new steps may be added. Alternatively, any combination of two or more of the above embodiments may be used. Such modifications, changes, or combinations also fall within the scope of the embodiments of this application.
[0136] It should also be understood that the methods, situations, categories, and classifications of embodiments in this application are for the convenience of description only and should not constitute a special limitation. Various methods, categories, situations, and features in embodiments can be combined without contradiction.
[0137] It should also be understood that, in the various embodiments of this application, unless otherwise specified or in case of logical conflict, the terms and / or descriptions between different embodiments are consistent and can be referenced by each other, and the technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationships.
[0138] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0139] In the embodiments provided in this application, it should be understood that the disclosed apparatus / network devices and methods can be implemented in other ways. For example, the apparatus / network device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0140] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0141] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
[0142] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A QR code recognition method, characterized in that, The method includes: Obtain the initial first image of the QR code, and convert the first image into a black and white second image; Perform a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image; The first frequency domain information is subjected to frequency domain denoising processing to obtain the second frequency domain information of the second image; Perform an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the two images; Based on the decoding standard corresponding to the QR code, the second pixel matrix is decoded to obtain the recognition result of the QR code.
2. The method according to claim 1, characterized in that, The step of converting the first image into a black and white second image includes: The first image is processed to obtain a grayscale image of the first image; The grayscale image is binarized and morphologically processed to obtain the second image.
3. The method according to claim 1, characterized in that, Before performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image, the method further includes: Detect the positioning pattern and clock pattern in the second image; Calculate the perspective transformation matrix based on the positioning pattern, the clock pattern, and the standard QR code grid. Based on the perspective transformation matrix, the second image is geometrically corrected; The geometrically corrected second image is aligned with the standard QR code grid.
4. The method according to claim 1, characterized in that, The step of performing a Fourier transform on the first pixel matrix of the second image to obtain the first frequency domain information of the second image includes: Perform a one-dimensional Fourier transform on each row of the pixel sequence in the first pixel matrix to obtain a first pixel matrix in which each row of the pixel sequence satisfies the frequency threshold; Perform a two-dimensional Fourier transform on the first pixel matrix that satisfies the frequency threshold for each row of pixel sequence to obtain the first frequency domain information.
5. The method according to claim 1, characterized in that, The step of performing frequency domain denoising processing on the first frequency domain information to obtain the second frequency domain information of the second image includes: The preset band-stop filter is multiplied with the first frequency domain information to perform frequency domain denoising processing, thereby obtaining the second frequency domain information of the second image.
6. The method according to claim 1, characterized in that, After performing an inverse Fourier transform on the second frequency domain information to obtain the second pixel matrix of the two images, the method further includes: The second pixel matrix is binarized based on the local thresholding algorithm to obtain the denoised pixel matrix. The denoised pixel matrix is downsampled to obtain the QR code standard decoding matrix.
7. The method according to claim 6, characterized in that, The method further includes: Based on the decoding standard corresponding to the QR code, the QR code standard decoding matrix is decoded to obtain the recognition result of the QR code.
8. The method according to any one of claims 1 to 7, characterized in that, After converting the first image into a black and white second image, the method further includes: Along the rows and columns of the QR code, the pixels of the second image are collected to generate the first pixel matrix of the second image.
9. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method of any one of claims 1 to 8.
10. A computer program product, characterized in that, When the computer program product is run on the device, it causes the device to perform the method according to any one of claims 1 to 8.