Two-dimensional code recognition method and device, computer device, and storage medium
By acquiring images of the QR code during its movement, determining reference pixels, and making corrections, the problem of QR code detection and recognition difficulties caused by inconsistent camera focus was solved, achieving clear QR code recognition.
Patent Information
- Application Number
- CN202210528777.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-16
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2042-05-16
AI Technical Summary
In the field of access control, the focus of a camera is inconsistent when capturing facial images and when capturing QR code images, making QR code detection and recognition difficult.
By acquiring an image of the QR code and multiple images of it during its movement, reference pixels that have not changed in the encoded block are identified. These reference pixels are then used to correct the encoded block, resulting in a clear QR code image for recognition.
It effectively counteracts the effects of ambiguity, making the encoded blocks clearer, thus facilitating QR code recognition and improving recognition accuracy and efficiency.
Smart Images

Figure CN114896999B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of QR code recognition, and more particularly to QR code recognition methods, devices, computer equipment, and storage media. Background Technology
[0002] A QR code is a graphic symbol used to record data information, consisting of a specific set of geometric shapes arranged in black and white on a two-dimensional plane according to certain rules. It uses several geometric shapes corresponding to binary numbers to represent textual and numerical information. One coded block in a QR code represents a binary code, and multiple codes can constitute identification information, which can be used to uniquely represent certain identity information.
[0003] In the current access control field, multiple methods such as facial recognition, access card recognition, and QR code recognition are used simultaneously to identify users and meet their diverse needs. To reduce costs, a single camera is often used to capture both the face and the QR code, enabling simultaneous facial and QR code recognition. However, the focal point of the captured facial image and the focal point of the captured QR code image often differ. Even if the camera's focus is sufficient to clearly capture the face, the QR code image may not be clear enough, leading to difficulties in QR code detection and recognition. Summary of the Invention
[0004] This application provides a QR code recognition method, apparatus, computer equipment, and storage medium to address the technical problem of difficulty in QR code detection and recognition caused by insufficient clarity of QR codes captured by cameras.
[0005] Firstly, it provides QR code recognition methods, including:
[0006] When a QR code is detected, an image of the QR code is acquired to obtain a first QR code image, and multiple QR code comparison images corresponding to the first QR code image are acquired, wherein the multiple QR code comparison images are images of the QR code during the moving process;
[0007] Based on the movement and changes of each coded block in the first QR code image in the multiple QR code comparison images, the reference pixel of each coded block is determined, wherein one coded block corresponds to one code, and the reference pixel refers to the pixel in the coded block that does not change during the movement of the QR code.
[0008] Based on the reference pixels of each coded block, each coded block is corrected in the first QR code image to obtain the second QR code image.
[0009] The QR code is recognized based on the second QR code image to obtain the QR code recognition result.
[0010] In this technical solution, when a QR code is detected, an image of the QR code and an image of the QR code during its movement are acquired. Based on the image of the QR code during movement, reference pixels that remain unchanged in each encoded block of the QR code image are determined. Then, each encoded block is corrected based on these unchanged reference pixels to obtain a corrected QR code image. Finally, the corrected QR code image is used for QR code recognition to obtain the recognition result. By using unchanged reference pixels in each encoded block to correct it, the effects of blurriness can be offset, making each encoded block clearer. This allows for QR code recognition based on a clear QR code image, facilitating QR code recognition.
[0011] In conjunction with the first aspect, in one possible implementation, determining the reference pixel of each encoded block based on the movement and changes of each encoded block in the first QR code image across multiple QR code comparison images includes: binarizing each of the multiple QR code comparison images to obtain multiple binary images; performing an XOR operation on the first binary image and the second binary image to obtain a first XOR result, wherein the first binary image and the second binary image belong to the multiple binary images, and the first binary image and the second binary image are respectively binary images of the QR code moving in opposite horizontal directions; performing an XOR operation on the third binary image and the fourth binary image to obtain a second XOR result, wherein the third binary image and the fourth binary image belong to the multiple binary images, and the third binary image and the fourth binary image are respectively binary images of the QR code moving in opposite vertical directions; and determining the reference pixel of each encoded block based on the first XOR result and the second XOR result. By converting the QR code image during movement into a binary image and performing an XOR operation, it is possible to more quickly identify pixels that have not changed, thus reducing the amount of computation.
[0012] In conjunction with the first aspect, in one possible implementation, determining the reference pixel of each coded block based on the first XOR result and the second XOR result includes: determining a first fixed pixel in the target coded block based on the first XOR result corresponding to the target coded block, wherein the first fixed pixel refers to a pixel that does not change after XOR; the target coded block is any coded block in the first QR code image; determining the horizontal position of the reference pixel in the target coded block in the first QR code image based on the first fixed pixel; determining a second fixed pixel in the target coded block based on the second XOR result corresponding to the target coded block, wherein the second fixed pixel refers to a pixel that does not change after XOR; and determining the vertical position of the reference pixel in the target coded block in the first QR code image based on the second fixed pixel. By determining the horizontal position of the unchanged pixel based on the XOR result corresponding to the horizontal movement of the QR code, and determining the vertical position of the unchanged pixel based on the XOR result corresponding to the horizontal movement of the QR code, the pixel least affected by the movement process can be determined, thereby determining the clearest pixel in the coded block.
[0013] In conjunction with the first aspect, in one possible implementation, the step of correcting each encoded block according to the reference pixels of each encoded block to obtain a second QR code image includes: modifying each pixel in the target encoded block to a reference pixel of the target encoded block to correct the target encoded block; the target encoded block is any encoded block in the first QR code image. Since the reference pixel is a pixel that does not change during movement, it indicates that the reference pixel is less affected by movement and is clearer than other pixels in the encoded block. Therefore, modifying each pixel in the encoded block to a reference pixel can make the encoded block clearer.
[0014] In conjunction with the first aspect, in one possible implementation, before acquiring the image of the QR code to obtain a first QR code image, and before acquiring multiple QR code comparison images corresponding to the first QR code image, the method further includes: acquiring two adjacent scene images; binarizing the two adjacent scene images to obtain two binary scene images corresponding to the two adjacent scene images; and determining the QR code detection result based on the XOR result of the two binary scene images. Before acquiring the image of the QR code, the presence of a QR code is detected by acquiring two adjacent frames during the movement of the QR code image and then detecting the presence of a QR code based on the XOR result of the corresponding binary images. This detection method is simple and fast, and can reduce the consumption of processing resources.
[0015] In conjunction with the first aspect, in one possible implementation, determining the QR code detection result based on the XOR result of the two binary scene images includes: determining the XOR image corresponding to the XOR result of the two binary scene images; and determining that a QR code has been detected if a first preset pattern exists in the XOR image. By detecting whether the first preset pattern exists in the XOR image, rapid detection of whether a QR code exists in the acquired image can be achieved.
[0016] In conjunction with the first aspect, one possible implementation, before determining that a QR code has been detected, further includes: determining the target position of the first preset pattern in the XOR image; determining whether a second preset pattern exists at the target position in the two adjacent scene images; and if the first preset image exists at the target position, then performing the step of determining that a QR code has been detected. When it is determined that the first preset pattern exists in the XOR image, by detecting whether the second preset pattern exists in the two adjacent original frames, accurate detection of whether a QR code exists in the acquired image can be achieved.
[0017] Secondly, a QR code recognition device is provided, comprising:
[0018] The image acquisition module is used to acquire an image of the QR code when the QR code is detected, so as to obtain a first QR code image, and to acquire multiple QR code comparison images corresponding to the first QR code image, wherein the multiple QR code comparison images are images of the QR code during the movement process;
[0019] The reference pixel determination module is used to determine the reference pixel of each coding block based on the movement and change of each coding block in the first QR code image in the multiple QR code comparison images. Here, one coding block corresponds to one code, and the reference pixel refers to the pixel in the coding block that does not change during the movement of the QR code.
[0020] The correction module is used to correct each coding block in the first QR code image based on the reference pixels of each coding block to obtain a second QR code image.
[0021] The recognition module is used to perform QR code recognition based on the second QR code image to obtain the QR code recognition result.
[0022] Thirdly, a computer device is provided, including a memory and one or more processors, the one or more processors being configured to execute one or more computer programs stored in the memory, wherein when the one or more processors execute the one or more computer programs, the computer device enables the QR code recognition method of the first aspect described above.
[0023] Fourthly, a computer-readable storage medium is provided, which stores a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the QR code recognition method of the first aspect.
[0024] This application can achieve the following technical effects: by using reference pixels that have not changed in each coding block to correct each coding block, the effects of blurring can be offset, making each coding block clear, thereby enabling QR code recognition based on a clear QR code image, which facilitates QR code recognition. Attached Figure Description
[0025] Figure 1 This application provides a schematic diagram of a QR code recognition scenario.
[0026] Figure 2 A flowchart illustrating a QR code recognition method provided in an embodiment of this application;
[0027] Figure 3 A schematic diagram of an XOR process provided in an embodiment of this application;
[0028] Figure 4 A schematic diagram of a preset pattern provided in the embodiments of this application;
[0029] Figure 5 This is a schematic diagram of the structure of a QR code recognition device provided in an embodiment of this application;
[0030] Figure 6 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0031] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0032] The technical solution of this application can be applied to various QR code recognition scenarios, such as access control recognition scenarios and QR code payment scenarios.
[0033] First see Figure 1 , Figure 1 This is a schematic diagram of a QR code recognition scenario provided in an embodiment of this application. Figure 1As shown, when a terminal device 101 displaying a QR code approaches a QR code detection and recognition device 102 equipped with a camera, the QR code detection and recognition device 102 acquires the image displayed on the terminal device 101 through the camera and performs QR code detection to determine whether a QR code exists in the image displayed on the terminal device 101. When a QR code is detected in the image displayed on the terminal device 101, the QR code detection and recognition device 102 recognizes the QR code displayed on the terminal device 101. Specifically, the QR code detection and recognition device includes, but is not limited to, access control devices, mobile terminals, and PCs. The terminal device 101 can be any device capable of displaying QR codes, including but not limited to mobile phones and tablets.
[0034] The technical principle of this application is as follows: During the QR code detection and recognition process, multiple images of the QR code during its movement are acquired to obtain multiple QR code images. By superimposing the multiple QR code images, reference pixels that are not affected by the movement of the QR code are determined. Based on these reference pixels, the QR code images are corrected to cancel out the Gaussian blur caused by the camera's lack of focus, thereby making the encoded blocks in the QR code images clearer and facilitating QR code recognition.
[0035] See Figure 2 , Figure 2 This is a flowchart illustrating a QR code recognition method provided in an embodiment of this application. This method can be applied to the above-mentioned... Figure 1 The QR code detection and recognition device 102 shown is as follows: Figure 2 As shown, the method includes the following steps:
[0036] S201, when a QR code is detected, an image of the QR code is acquired to obtain a first QR code image, and multiple QR code comparison images corresponding to the first QR code image are acquired.
[0037] The first QR code image can be an image of the QR code in a static state. A static state means the QR code remains stationary at one position for a duration exceeding a preset time. Multiple QR code comparison images refer to images of the QR code during its movement. Specifically, these multiple QR code comparison images include at least images of the QR code moving upwards, downwards, to the left, and to the right. It should be understood that upward and downward movement are relative concepts; similarly, left and right movement are also relative concepts. In some possible cases, the position of the QR code when the first QR code image is obtained can be used as a reference position to determine the direction of movement, thereby obtaining images of the QR code moving upwards, downwards, to the left, and to the right.
[0038] In some possible implementation scenarios, upon detecting a QR code, a QR code movement prompt can be issued, instructing the user to move the carrier displaying the QR code (such as a mobile phone or paper), causing the QR code to move. During the movement of the QR code, images of the QR code are captured frame by frame, thus obtaining multiple QR code comparison images. Optionally, multiple QR code movement prompts can be issued, each instructing the user to move the carrier displaying the QR code in a different direction. Each time a QR code movement prompt is issued, an image of the QR code is captured, thus obtaining multiple QR code comparison images. This application does not limit the method of obtaining multiple QR code comparison images.
[0039] S202, based on the movement and changes of each coded block in the first QR code image in multiple QR code comparison images, determine the reference pixel of each coded block in the first QR code image.
[0040] The coded block refers to the block used to represent the code, and one coded block corresponds to one code; the code can be binary code, that is, 0 or 1.
[0041] A reference pixel is a pixel in the coded block that does not change during the movement of the QR code. It can be understood as a pixel that is less affected or unaffected by the movement of the QR code. Because the reference pixel is less affected or unaffected by the movement of the QR code, it is clearer than other pixels in the coded block.
[0042] In some possible implementations, the movement and changes of the coded block in multiple QR code comparison images can be determined by binarizing the image and XORing it, thereby determining the reference pixels in the coded block. This method can more quickly determine the pixels that have not changed and reduce the amount of computation. The above step S202 may include the following steps A1-A4.
[0043] A1. Binarize the multiple QR code comparison images corresponding to the first QR code image to obtain multiple binary images.
[0044] A2. Perform an XOR operation on the first binary image and the second binary image to obtain the first XOR result.
[0045] A3. Perform an XOR operation on the third and fourth binary images to obtain the second XOR result.
[0046] A4. Based on the first XOR result and the second XOR result, determine the reference pixels of each coded block in the first QR code image.
[0047] The image binarization involved in step A1 above refers to converting each pixel value in the image into one of two values through image segmentation, so that the image corresponds to only two values, thus obtaining a binary image with only black and white visual effects. The two values corresponding to the binary image can be 0 and 1, where 1 represents white and 0 represents black.
[0048] Specifically, multiple QR code comparison images can be binarized using a global thresholding method to obtain multiple binary images. For example, a fixed threshold method or the maximum inter-class variance method can be used to binarize multiple QR code comparison images. Since there are relatively few color elements in QR code images, the global thresholding method can achieve good segmentation results with less computation, thus reducing the computational load.
[0049] Alternatively, multiple QR code comparison images can be binarized using a local thresholding method (such as an adaptive thresholding algorithm) to obtain multiple binary images. This application does not limit the method of image binarization.
[0050] In step A2 above, the first and second binary images belong to the plurality of binary images, and are respectively binary images of the QR code moving in opposite horizontal directions. That is, the first and second binary images are respectively the binary images corresponding to the QR code reference image when the QR code moves to the left and the binary images corresponding to the QR code reference image when the QR code moves to the right. Specifically, the first and second binary images can be respectively the binary images corresponding to the first frame QR code reference image when the QR code moves to the left and the binary images corresponding to the first frame QR code reference image when the QR code moves to the right; where the first frame refers to the first frame obtained. In step A3 above, the third and fourth binary images belong to the plurality of binary images, and are respectively binary images of the QR code moving in opposite vertical directions. That is, the third and fourth binary images are respectively the binary images corresponding to the QR code reference image when the QR code moves upward and the binary images corresponding to the QR code reference image when the QR code moves downward. Specifically, the third binary image and the second binary image are the binary images corresponding to the first frame of the QR code comparison image when the QR code moves upward and the binary images corresponding to the first frame of the QR code comparison image when the QR code moves downward, respectively.
[0051] Specifically, XORing two binary images means XORing the values at the same pixel position in the two binary images. For example, see... Figure 3 , Figure 3 This is a schematic diagram of an XOR process provided for an embodiment of this application. Figure 3 T1 and T2 in the image are two binary images to be XORed. Figure 3In this context, T3 is the XOR result obtained by XORing T1 and T2. The value in the i-th row and j-th column of T3 is obtained by XORing the value in the i-th row and j-th column of T1 with the value in the i-th row and j-th column of T2, where 1 ≤ i ≤ 7 and 1 ≤ j ≤ 7. (Refer to...) Figure 3 The first binary image and the second binary image are XORed in the manner shown, and the first XOR result can be obtained; refer to Figure 3 The second XOR result can be obtained by performing an XOR operation on the third and fourth binary images as shown.
[0052] Specifically, step A4 above may include steps A41-A44.
[0053] A41. Determine the first fixed pixel in the target coding block based on the first XOR result corresponding to the target coding block.
[0054] The target coded block can be any coded block in the first QR code image. The first XOR result corresponding to the target coded block refers to the XOR result obtained by XORing the binary pixels contained in the target coded block in the first binary image with the binary pixels contained in the target coded block in the second binary image. For example, see... Figure 3 With the target coded block as Figure 3 Taking the gray areas T1 and T2 as an example, in T1, the binary pixels contained in the target coded block are the pixels in rows 2-4 and columns 3-5; in T2, the binary pixels contained in the target coded block are the pixels in rows 2-4 and columns 2-4. Therefore, the first XOR result corresponding to the target block includes the result obtained by XORing the pixels in rows 2-4 and columns 2-5 in T1 and T2, that is... Figure 3 The gray area in T3 is the first XOR result corresponding to the target coded block.
[0055] The first fixed pixel refers to the pixel that does not change after XOR; where the pixel that does not change after XOR is the pixel whose XOR result is 0. The target encoding is... Figure 3 Taking the gray areas of T1 and T2 in the example, by Figure 3 It can be seen that the pixels that did not change after XOR are the pixels in the 2nd row and 2nd column, and the pixels in the 3rd-4th rows and 2nd-5th columns.
[0056] A42. Based on the first fixed pixel, determine the horizontal position of the reference pixel in the target coding block in the first QR code image.
[0057] Specifically, the horizontal position of the reference pixel in the first QR code image can be determined based on the horizontal position of the first fixed pixel. Specifically, the center of the horizontal position of the first fixed pixel can be determined as the horizontal position of the reference pixel in the first QR code image; the horizontal coordinates of the reference pixel can be equal to the average of the horizontal coordinates of the second fixed pixel. Taking the first fixed pixel as... Figure 3 If the pixel in the 2nd row and 2nd column is a reference pixel, and the pixels in the 3rd-4th row and 2nd-5th column are reference pixels, then the horizontal coordinate of the reference pixel can be the average of the horizontal coordinates of the pixel in the 2nd row and 2nd column and the horizontal coordinates of the pixels in the 3rd-4th row and 2nd-5th column.
[0058] A43. Determine the second fixed pixel in the target coding block based on the second XOR result corresponding to the target coding block.
[0059] The second XOR result corresponding to the target coded block refers to the XOR result obtained by XORing the binary pixels contained in the target coded block in the third binary image with the binary pixels contained in the target coded block in the fourth binary image. The second fixed pixel refers to the pixel that does not change after the XOR.
[0060] A44. Based on the second fixed pixel, determine the vertical position of the reference pixel in the target coding block in the first QR code image.
[0061] Specifically, the horizontal position of the reference pixel in the first QR code image can be determined based on the vertical position of the second fixed pixel. The center of the horizontal position of the second fixed pixel can be defined as the vertical position of the reference pixel in the first QR code image; the vertical coordinates of the reference pixel can be equal to the average of the vertical coordinates of the second fixed pixel.
[0062] By processing each coded block in the first QR code image according to steps A41-A44, the reference pixels of each coded block in the first QR code image can be determined. By determining the horizontal position of the unchanged pixels based on the XOR result corresponding to the horizontal movement of the QR code, and by determining the vertical position of the unchanged pixels based on the XOR result corresponding to the horizontal movement of the QR code, the pixels least affected by the movement process can be identified, thereby determining the clearest pixels in the coded blocks.
[0063] S203, based on the reference pixels of each coded block in the first QR code image, correct each coded block in the first QR code image to obtain the second QR code image.
[0064] In this embodiment of the application, correcting each encoded block in the first QR code image based on the reference pixels of each encoded block in the first QR code image means modifying the pixel values of other pixels in the target encoded block (excluding the reference pixels) based on the pixel values of the reference pixels in the target encoded block, so that the other pixels become clearer.
[0065] In one feasible implementation, each pixel within a target coding block can be modified to a reference pixel of the target coding block to correct the target coding block; the target coding block is any coding block in the first QR code image. After correcting each coding block in the first QR code image in this manner, a second QR code image is obtained. Since the reference pixel is a pixel that does not change during movement, it indicates that the reference pixel is less affected by movement and is clearer than other pixels in the coding block. Therefore, modifying each pixel within the coding block to a reference pixel can make the coding block clearer.
[0066] S204, Perform QR code recognition based on the second QR code image to obtain the QR code recognition result.
[0067] The second QR code image can be decoded using any QR code image decoding method to obtain the QR code recognition result. For example, the second QR code image can be decoded using a QR code recognition method based on correlation matching or a QR code recognition algorithm based on projection to obtain the QR code recognition result.
[0068] In the above technical solution, when a QR code is detected, the system acquires both an image of the QR code and an image of the QR code during its movement. Based on the image of the QR code during its movement, it determines the unchanged reference pixels in each encoded block of the QR code image. Then, based on these unchanged reference pixels, it corrects each encoded block to obtain a corrected QR code image. Finally, it uses the corrected QR code image for 2D code recognition. By using unchanged reference pixels to correct each encoded block, the effects of blurriness can be offset, making each encoded block clearer. This allows for QR code recognition based on a clear QR code image, facilitating QR code recognition.
[0069] In some possible implementations, QR code detection can be performed before QR code recognition, and QR code recognition can only be performed after QR code detection. This avoids performing QR code recognition on every frame of the acquired image, reducing computational load and improving device operating speed. QR code detection can be performed through steps B1-B3.
[0070] B1. Obtain scene images from two adjacent frames.
[0071] Here, the scene image refers to the image obtained during the QR code detection process. Specifically, during the QR code detection process, the user can be instructed to move the carrier displaying the QR code to make the QR code move, and then two frames of images during the movement of the QR code are acquired as two adjacent frame scene images.
[0072] B2. Binarize the two adjacent frame scene images to obtain two binary scene images corresponding to the two adjacent frame scene images.
[0073] Regarding the concept and method of binarization, reference can be made to the relevant introduction in the foregoing step A1, which will not be elaborated here.
[0074] B3. Determine the QR code detection result according to the exclusive OR result of the two binary scene images corresponding to the two adjacent frame scene images.
[0075] Specifically, the above step B3 may include the following steps B31 - B33.
[0076] B31. Determine the exclusive OR image corresponding to the exclusive OR result of the two binary scene images.
[0077] B32. Detect whether there is a first preset pattern in the exclusive OR image.
[0078] Here, the first preset pattern may be the "three" character area. Exemplarily, reference can be made to Figure 4 , Figure 4 The two images in are respectively the two binary images corresponding to the two adjacent frame scene images. Since there is a "hui" character area ( Figure 4 Q1 and Q2 in) in the QR code image, when the QR code moves, the exclusive OR of the two "hui" character areas can obtain the "three" character area ( Figure 4 Q3 in). When it is detected that there is a "three" character in the exclusive OR image, it indicates that there is a "hui" character in the scene, and the "hui" character is the positioning symbol of the QR code. Therefore, when it is detected that there is a "three" character area in the exclusive OR image, it indicates that there is a non-static "hui" character area in the scene, that is, there is a QR code, and step B33 is executed; when it is not detected that there is a "three" character area in the exclusive OR image, it indicates that there is no QR code in the scene, and step B34 is executed.
[0079] B33. Determine that the QR code is detected.
[0080] B34. Determine that the QR code is not detected.
[0081] By detecting whether there is a first preset pattern in the exclusive OR image, the rapid detection of whether there is a QR code in the acquired image can be achieved.
[0082] Optionally, in some possible cases, when it is determined that there is a first preset pattern in the XOR image, the target position of the first preset pattern in the XOR image can also be determined, and it is judged whether there is a second preset pattern at the target position in two adjacent frames of scene images; if there is a second preset pattern at the target position in two adjacent frames of scene images, step B33 is executed; if there is no second preset pattern at the target position in two adjacent frames of scene images, step B34 is executed.
[0083] Wherein, the second preset pattern is a "hui" character area. When it is determined that there is a first preset pattern in the XOR image, by detecting whether there is a second preset pattern in the original two adjacent frames of images obtained, the accurate detection of whether there is a two-dimensional code in the obtained images can be realized.
[0084] The above introduces the method of the present application. To better implement the method of the present application, the device of the present application is introduced next.
[0085] See Figure 5 , Figure 5 is a schematic structural diagram of a two-dimensional code recognition device provided by an embodiment of the present application. The two-dimensional code recognition device can be the two-dimensional code detection and recognition device 102 or a part of the two-dimensional code detection and recognition device 102. As Figure 5 shown, the two-dimensional code recognition device 30 includes:
[0086] An image acquisition module 301, configured to acquire an image of the two-dimensional code to obtain a first two-dimensional code image when detecting the two-dimensional code, and acquire multiple two-dimensional code comparison images corresponding to the first two-dimensional code image, wherein the multiple two-dimensional code comparison images are images of the two-dimensional code during movement;
[0087] A reference pixel determination module 302, configured to determine the reference pixels of each coding block according to the movement changes of each coding block in the first two-dimensional code image in the multiple two-dimensional code comparison images, wherein one coding block corresponds to one code, and the reference pixel refers to the pixel that does not change during the movement of the two-dimensional code in the coding block;
[0088] A correction module 303, configured to correct each coding block in the first two-dimensional code image according to the reference pixels of each coding block to obtain a second two-dimensional code image;
[0089] An identification module 304, configured to perform two-dimensional code identification based on the second two-dimensional code image to obtain a two-dimensional code identification result.
[0090] In some possible designs, the reference pixel determination module 302 is specifically used to: binarize the multiple QR code comparison images to obtain multiple binary images; XOR the first binary image and the second binary image to obtain a first XOR result, wherein the first binary image and the second binary image belong to the multiple binary images, and the first binary image and the second binary image are respectively binary images of the QR code moving in opposite horizontal directions; XOR the third binary image and the fourth binary image to obtain a second XOR result, wherein the third binary image and the fourth binary image belong to the multiple binary images, and the third binary image and the fourth binary image are respectively binary images of the QR code moving in opposite vertical directions; and determine the reference pixel of each coding block based on the first XOR result and the second XOR result.
[0091] In some possible designs, the reference pixel determination module 302 is specifically used to: determine a first fixed pixel in the target encoding block based on the first XOR result corresponding to the target encoding block, wherein the first fixed pixel refers to a pixel that does not change after XOR; the target encoding block is any encoding block in the first QR code image; determine the horizontal position of the reference pixel in the target encoding block in the first QR code image based on the first fixed pixel; determine a second fixed pixel in the target encoding block based on the second XOR result corresponding to the target encoding block, wherein the second fixed pixel refers to a pixel that does not change after XOR; and determine the vertical position of the reference pixel in the target encoding block in the first QR code image based on the second fixed pixel.
[0092] In some possible designs, the correction module 303 is specifically used to: modify each pixel in the target coding block to the reference pixel of the target coding block according to the reference pixel of the target coding block, so as to correct the target coding block; the target coding block is any coding block in the first QR code image.
[0093] In some possible designs, the QR code recognition device 30 may also include a detection module 305, which is used to acquire two adjacent scene images; binarize the two adjacent scene images to obtain two binary scene images corresponding to the two adjacent scene images; and determine the QR code detection result based on the XOR result of the two binary scene images.
[0094] In one possible design, the detection module 305 is specifically used to: determine an XOR image corresponding to the XOR result of the two binary scene images; and, if a first preset pattern exists in the XOR image, determine that a QR code has been detected.
[0095] In some possible designs, the detection module 305 is further configured to: determine the target position of the first preset pattern in the XOR image; determine whether a second preset pattern exists at the target position in the two adjacent scene images; and if the first preset image exists at the target position, execute the step of determining that a QR code has been detected.
[0096] It should be noted that, Figure 5 For any content not mentioned in the corresponding embodiments, please refer to the description of the foregoing method embodiments, which will not be repeated here.
[0097] The aforementioned device, upon detecting a QR code, acquires both an image of the QR code and an image of the QR code during its movement. Based on the image of the QR code during movement, it determines the unchanged reference pixels in each encoded block of the QR code image. Then, based on these unchanged reference pixels, it corrects each encoded block to obtain a corrected QR code image. Finally, it uses the corrected QR code image for 2D code recognition. By using unchanged reference pixels to correct each encoded block, the effects of blurriness can be offset, making each encoded block clearer. This allows for QR code recognition based on a clear image, facilitating QR code recognition.
[0098] See Figure 6 , Figure 6 This is a schematic diagram of the structure of a computer device 40 provided in an embodiment of this application. The computer device 40 includes a processor 401 and a memory 402. The processor 401 is connected to the memory 402, for example, the processor 401 can be connected to the memory 402 via a bus.
[0099] Processor 401 is configured to support the computer device 40 in performing the corresponding functions in the methods described in the above method embodiments. Processor 401 may be a central processing unit (CPU), a network processor (NP), a hardware chip, or any combination thereof. The aforementioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.
[0100] Memory 402 is used to store program code, etc. Memory 402 may include volatile memory (VM), such as random access memory (RAM); memory 402 may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD); memory 402 may also include combinations of the above types of memory.
[0101] Processor 401 can call the program code to perform the following operations:
[0102] When a QR code is detected, an image of the QR code is acquired to obtain a first QR code image, and multiple QR code comparison images corresponding to the first QR code image are acquired, wherein the multiple QR code comparison images are images of the QR code during the moving process;
[0103] Based on the movement and changes of each coded block in the first QR code image in the multiple QR code comparison images, the reference pixel of each coded block is determined, wherein one coded block corresponds to one code, and the reference pixel refers to the pixel in the coded block that does not change during the movement of the QR code.
[0104] Based on the reference pixels of each coded block, each coded block is corrected in the first QR code image to obtain the second QR code image.
[0105] The QR code is recognized based on the second QR code image to obtain the QR code recognition result.
[0106] This application also provides a computer-readable storage medium storing a computer program, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the method described in the foregoing embodiments.
[0107] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0108] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. A QR code recognition method, characterized in that, include: When a QR code is detected, an image of the QR code is acquired to obtain a first QR code image, and multiple QR code comparison images corresponding to the first QR code image are acquired, wherein the multiple QR code comparison images are images of the QR code during the moving process; Based on the movement and changes of each coded block in the first QR code image in the multiple QR code comparison images, the reference pixel of each coded block is determined, wherein one coded block corresponds to one code, and the reference pixel refers to the pixel in the coded block that does not change during the movement of the QR code. Based on the reference pixels of each coded block, each coded block is corrected in the first QR code image to obtain the second QR code image. Based on the second QR code image, QR code recognition is performed to obtain the QR code recognition result. The step of determining the reference pixel of each coding block based on the movement and change of each coding block in the first QR code image in the multiple QR code comparison images includes: binarizing the multiple QR code comparison images to obtain multiple binary images. The first binary image and the second binary image are XORed to obtain the first XOR result. The first binary image and the second binary image belong to the plurality of binary images, and the first binary image and the second binary image are respectively the binary images of the QR code when it moves in opposite horizontal directions. XOR the third binary image and the fourth binary image to obtain a second XOR result; the third binary image and the fourth binary image belong to the multiple binary images, and the third binary image and the fourth binary image are respectively the binary images of the QR code when it moves in opposite vertical directions; The reference pixels of each coded block are determined based on the first XOR result and the second XOR result.
2. The method according to claim 1, characterized in that, The step of determining the reference pixel of each coding block based on the first XOR result and the second XOR result includes: determining the first fixed pixel in the target coding block based on the first XOR result corresponding to the target coding block, wherein the first fixed pixel refers to a pixel that does not change after XOR; the target coding block is any coding block in the first QR code image; Based on the first fixed pixel, determine the horizontal position of the reference pixel in the target coding block in the first QR code image; Based on the second XOR result corresponding to the target coding block, a second fixed pixel in the target coding block is determined, wherein the second fixed pixel refers to a pixel that does not change after the XOR. Based on the second fixed pixel, the vertical position of the reference pixel in the target coding block in the first QR code image is determined.
3. The method according to claim 1, characterized in that, The step of correcting each coding block according to the reference pixels of each coding block to obtain a second QR code image includes: modifying each pixel in the target coding block to the reference pixels of the target coding block to correct the target coding block; the target coding block is any coding block in the first QR code image.
4. The method according to any one of claims 1 to 2, characterized in that, Before obtaining the image of the QR code to obtain the first QR code image, and before obtaining multiple QR code comparison images corresponding to the first QR code image, the method further includes: obtaining two adjacent frame scene images; The two adjacent scene images are binarized to obtain two binary scene images corresponding to the two adjacent scene images; The QR code detection result is determined based on the XOR result of the two binary scene images.
5. The method according to claim 4, characterized in that, The step of determining the QR code detection result based on the XOR result of the two binary scene images includes: determining the XOR image corresponding to the XOR result of the two binary scene images; If a first preset pattern exists in the XOR image, it is determined that a QR code has been detected.
6. The method according to claim 5, characterized in that, Before determining that a QR code has been detected, the method further includes: determining the target position of the first preset pattern in the XOR image; Determine whether a second preset pattern exists at the target location in two adjacent scene images; If the second preset pattern exists at the target location, then the step of determining that a QR code has been detected is executed.
7. A computer device, characterized in that, The device includes a memory and a processor, the processor being configured to execute one or more computer programs stored in the memory, the processor causing the computer device to perform the method as described in any one of claims 1 to 6 when executing the one or more computer programs.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, the computer program including program instructions that, when executed by a processor, cause the processor to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Coded image recognition method and mobile terminal
CN109492451A