A method and device for QR code recognition
By correcting the QR code image with the detection and perspective transformation matrix, generating a standard grid in combination with the prior network and using the enhanced network for defuzzing, the problem of low recognition efficiency of QR codes on low computing power terminals is solved, and efficient and accurate QR code recognition is achieved.
Patent Information
- Application Number
- CN202510294053.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2045-03-13
AI Technical Summary
In the prior art, QR codes are susceptible to factors such as hand shaking, distance, angle and light during scanning and recognition, resulting in blurring or skewed images, making it difficult to accurately identify them, especially in low recognition efficiency on terminals with low computing capabilities.
The detection network model is used to detect the QR code position and mark the corner points, the images are corrected through the perspective transformation matrix, and the standard grid is generated in combination with the prior network model. The enhanced network model is used for noise reduction and defuzzing, and the standard grid is used to guide the processing process and improve image quality.
It realizes efficient and accurate identification of skewed, dummy and motion fuzzy QR codes on low-computing terminals, improves the recognition success rate, and improves the universality and accuracy of QR code recognition.
Smart Images

Figure CN119785277B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and particularly relates to a method and device for two-dimensional code recognition. Background Art
[0002] A two-dimensional code is a specific geometric figure, which distributes a black-and-white rectangular matrix on a plane according to certain rules to record data symbol information.
[0003] Currently, to ensure accurate scanning and recognition of two-dimensional codes, it is necessary to ensure that the scanned two-dimensional code image is clear; in actual scanning and recognition scenarios, a clear two-dimensional code image may be difficult to scan successfully. For example, when scanning a two-dimensional code with a handheld scanning device, the scanned two-dimensional code may have motion blur due to hand shaking, too far distance between the scanning device and the two-dimensional code, or insufficient resolution of the scanning device, making it impossible to accurately distinguish the boundaries of black and white cells in the two-dimensional code, and thus unable to recognize or misrecognize the two-dimensional code. In actual scanning and recognition scenarios, due to reasons such as scanning angle and light, the scanned two-dimensional code image may be skewed, defocused, etc., affecting recognition. The simultaneous occurrence of one or more of the above situations exacerbates the difficulty of efficient and accurate recognition of two-dimensional codes. Summary of the Invention
[0004] In view of the problems existing in the prior art, the present invention proposes a method and device for two-dimensional code recognition, which uses a detection network model to detect, extract, and mark the intercepted two-dimensional code image; uses a prior network model to detect the version of the two-dimensional code, generates a corresponding standard two-dimensional code grid according to the detected two-dimensional code version information, and inputs the corresponding standard two-dimensional code grid as prior knowledge into an enhancement network model; the enhancement network model performs noise reduction and deblurring processing on the received two-dimensional code, and at the same time, uses the standard two-dimensional code grid to guide the noise reduction and deblurring processing process to achieve high-quality enhancement of the two-dimensional code; thereby realizing efficient and accurate recognition of two-dimensional codes and improving the success rate of two-dimensional code recognition.
[0005] To achieve the above object, the present invention adopts a method for two-dimensional code recognition, including the following sequential steps:
[0006] S1. Detect whether there is a two-dimensional code in the target area, lock and intercept the two-dimensional code in the target area;
[0007] S2. Use a detection network model to detect, extract, and mark the intercepted two-dimensional code image, and identify and mark three corner points of the two-dimensional code;
[0008] S3. Calculate the perspective transformation matrix according to the identified corner points of the two-dimensional code to align the two-dimensional code;
[0009] S4. Input the adjusted square QR code into the QR code decoding library for decoding. If it can be directly decoded, obtain the recognition content of the QR code; if the QR code cannot be decoded, input it into the prior network model and the enhancement network model;
[0010] S5. Use the prior network model to detect the version of the adjusted square QR code, generate the corresponding standard QR code grid according to the detected QR code version information, and input the corresponding standard QR code grid as prior knowledge into the enhancement network model;
[0011] S6. The enhancement network model performs noise reduction and deblurring processing on the received QR code. At the same time, use the standard QR code grid to guide the noise reduction and deblurring processing process to achieve high-quality enhancement of the QR code;
[0012] S7. Input the enhanced QR code image into the QR code decoding library for decoding, so as to obtain the recognition content of the QR code.
[0013] Preferably, the enhancement network model adopts the DeblurGANv2 model. The backbone network part of this model adopts the MobileNet lightweight network and uses efficient technologies such as depthwise separable convolution, significantly reducing the number of parameters and the amount of calculation. While ensuring high-performance effects, the model can be deployed on terminals with low computing levels to run efficiently.
[0014] Preferably, the enhancement network model adopts a Batch Normalization normalization layer, which reduces the quantization accuracy loss when the model is deployed on terminal devices compared to using the original Instance Normalization normalization layer.
[0015] Preferably, the detection network model adopts the YOLOv8 model to achieve lightweight design, significantly reducing the computing cost while maintaining high accuracy, and is suitable for real-time detection scenarios.
[0016] Preferably, the prior network model adopts the MobileNetv2 model, achieving low-computing power operation while maintaining high detection accuracy and speed.
[0017] Preferably, it further includes a first QR code data set for training the detection network model. The first QR code data set is obtained through the following steps:
[0018] By shooting a QR code video and performing average continuous short exposure frames to generate blurred images, thus forming the first QR code data set for training;
[0019] The QR code video is cross - mixed with multiple QR codes of various different versions, and the positions are scattered and not fixedly set. The first QR code dataset is used to train the detection network model to obtain parameter weights, thereby ensuring the high detection accuracy and rapidity of the model.
[0020] Preferably, it further includes a second QR code dataset for training the prior network model. The second QR code dataset is obtained through the following steps:
[0021] By shooting a QR code video and performing average continuous short - exposure frames to generate a blurred image, thereby forming the second QR code dataset for training;
[0022] The QR code video contains QR codes of various different versions classified by version. The QR code images in the second QR code dataset are input into the prior network model for training according to the version to obtain the parameter weights corresponding to the version; then repeat the prior network model training process, and train with QR codes of different versions in turn to obtain the parameter weights corresponding to each different version, thereby ensuring the high detection accuracy and rapidity of the model.
[0023] Preferably, it further includes a third QR code dataset for training the enhancement network model. The third QR code dataset is obtained through the following steps:
[0024] By shooting a QR code video and performing average continuous short - exposure frames to generate a blurred image, and taking the original QR code image that constitutes the QR code video as a clear image, thereby forming the third QR code dataset for training by pairwise combination;
[0025] The QR code video contains QR codes of various different versions classified by version. The QR code images in the third QR code dataset are input into the enhancement network model in pairs according to the version for training, and at the same time, the standard QR code grid corresponding to the version is input as prior knowledge to guide the noise reduction and de - blurring process to obtain the parameter weights corresponding to the version; then repeat the enhancement network model training process, and train with QR codes of different versions in turn to obtain the parameter weights corresponding to each different version, so that the model can have a high - accuracy enhancement ability for QR codes of different versions and improve the generalization of the model.
[0026] Preferably, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to \(0.7\) and less than \(1\); to ensure the decodability of the enhanced QR code image.
[0027] The present invention also provides a QR code recognition device, including:
[0028] The image acquisition module detects and determines whether there is a QR code in the target area, intercepts the QR code in the target area, automatically adjusts the ISP exposure according to the scene environment during the interception process, and transmits the intercepted QR code to the image correction module;
[0029] The image correction module detects and extracts the QR code in the image, and performs processing such as rotation and deformation adjustment on the QR code, adjusts the QR code with arbitrary angle inclination and deformation to a square QR code in the correct orientation, and transmits the adjusted square QR code to the QR code decoding module;
[0030] The QR code decoding module uses the ZXing QR code decoding library to decode the received QR code and obtain the recognition content of the QR code; if the decoding of the received QR code fails, the QR code is transmitted to the version priori module and the image enhancement module;
[0031] The version priori module performs QR code version detection on the received QR code, generates a corresponding standard QR code grid according to the detected QR code version information, and inputs the corresponding standard QR code grid as priori knowledge into the image enhancement module;
[0032] The image enhancement module performs noise reduction and deblurring processing on the received QR code. At the same time, the standard QR code grid is used to guide the noise reduction and deblurring processing process to achieve high-quality enhancement of the QR code; among them, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 1; the enhanced QR code image is input into the QR code decoding module.
[0033] The present invention realizes the recognition of QR codes by combining multiple neural network models, improves the processing and enhancement capabilities for skewed, defocused, and motion-blurred QR codes. Each network model has been pre-trained with a high quantity and complexity, and the generated model has high flexibility and versatility, thereby improving the universality of the popularization and application of the present invention.
[0034] The present invention uses a priori network models to perform QR code version detection on QR codes, generates a corresponding standard QR code grid according to the detected QR code version information, and inputs the corresponding standard QR code grid as priori knowledge into the enhancement network model; the enhancement network model performs noise reduction and deblurring processing on the received QR code. At the same time, the standard QR code grid is used to guide the noise reduction and deblurring processing process to achieve high-quality enhancement of the QR code; thereby realizing efficient and accurate recognition of QR codes and improving the QR code recognition success rate.
[0035] The enhanced network model uses the DeblurGANv2 model. The backbone network of this model uses the MobileNet lightweight network, which significantly reduces the number of parameters and computational complexity. While ensuring high performance, the model can be deployed and run efficiently on terminals with low computing capabilities. The enhanced network model also uses the Batch Normalization layer to reduce the loss of quantization accuracy when the model is deployed on terminal devices, avoiding data errors generated by the model.
[0036] The present invention adopts an adversarial loss function that integrates the structural similarity metric SSIM. The structural similarity metric SSIM is used to guide the discriminator to more accurately evaluate the structural similarity between the generated image and the real image. It also helps the generator to generate images that are more structurally similar, thereby improving the quality of image generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0038] Figure 1 This is a workflow diagram of a two-dimensional code recognition method of the present invention;
[0039] Figure 2 This is a schematic diagram of the structural modules of a two-dimensional code recognition device of the present invention. DETAILED DESCRIPTION
[0040] The present invention will be further described in detail below with reference to the accompanying drawings and examples. Example 1
[0041] Reference Figure 1 This embodiment provides a QR code recognition method. First, in step S1, a QR code is detected within a target area. The target area can be the area that a camera can monitor when it is fixed in a certain position, or the area that a handheld camera can capture when scanning a code. If a QR code is present within the target area, the system locks on and captures it. During the capture process, the ISP exposure is automatically adjusted based on the scene environment to avoid overexposure. If no QR code is present within the target area, the system continues detecting the QR code.
[0042] Affected by factors such as different shooting distances and angles, the intercepted QR code images may vary in size and shape. For example, in the intercepted QR code images, the QR code part may be diamond-shaped or square-shaped; among different QR code images, the side length of the QR code boundary and the orientation position of the QR code in the image are also different.
[0043] In step S2, a detection network model is used to detect the position of the QR code in the image, extract the QR code, and identify and mark three corner points of the QR code. To ensure the high detection accuracy, speed, and lightweight design of the model, the YOLOv8 model is adopted for the detection network model. A first QR code dataset for training the detection network model is designed and produced. Specifically, by shooting a QR code video and performing average continuous short-exposure frames to generate blurred images, a first QR code dataset for training is thus formed. In this QR code video, multiple QR codes of different versions with scattered and unfixed positions are cross-mixed. For example, a QR code image of the fourth version can be set after a QR code image of the first version, and a QR code image of the second version can be set after the QR code image of the fourth version. In addition, the QR code can be randomly rotated by any angle to increase the diversity and complexity of the training samples, so as to simulate various scanning situations that can be encountered in the actual QR code scanning scenario. There should be no less than 5000 blurred QR code images for each version. The first QR code dataset is used to train the detection network model to obtain parameter weights, thus ensuring the high detection accuracy and speed of the model.
[0044] The intercepted QR code image is processed using the trained detection network model. Since the model has been trained for blurred QR code images during the training process, the trained detection network model can quickly detect the position of the QR code in the received blurred QR code image, extract the QR code, and identify and mark three corner points of the QR code.
[0045] After identifying and marking three corner points of the QR code, step S3 is performed. The perspective transformation matrix is calculated based on the identified corner points of the QR code to achieve QR code alignment. Specifically, based on the three corner points of the marked QR code and the three corner points in the standard coordinates, the corresponding mapping relationship is established. Based on this mapping relationship, the QR code image is corrected, and processing such as rotation and deformation adjustment of the QR code is performed to adjust the QR code into a square QR code in the correct orientation. The so-called correct orientation means that the three corner points of the QR code are respectively located at the upper left, upper right, and lower left positions, and the orientation when the QR code as a whole has no inclination.
[0046] In step S4, the adjusted Founder QR code is input into a QR code decoding library for decoding to determine whether it can be decoded. The QR code decoding library can use the ZXing QR code decoding library. If it can be directly decoded, the recognition content of the QR code is obtained; if the QR code cannot be decoded, it is input into a prior network model and an enhancement network model.
[0047] The prior network model is used to detect the version information of the QR code and generate a corresponding standard QR code grid. To ensure the high detection accuracy, rapidity, and low computing power operation of the model, the prior network model can adopt the MobileNetv2 model. A second QR code dataset for training the prior network model is designed and produced. By shooting a QR code video and performing average continuous short exposure frames to generate blurred images, a second QR code dataset for training is formed. The QR code video contains QR codes of various different versions collected by version classification, and the positions of the QR codes in the image are scattered and not fixed, and the QR codes in the image also have different rotation angles of different sizes to increase the diversity and complexity of training samples, so as to simulate various QR code scanning situations that can be encountered in the actual QR code scanning scenario. The number of blurred images of QR codes for each version should be no less than 5000. The QR code images in the second QR code dataset are input into the prior network model by version for training to obtain the parameter weights corresponding to the corresponding version. Then, the prior network model training process is repeated, and QR codes of different versions are used for training in turn to obtain the corresponding parameter weights under each different version.
[0048] In step S5, the trained prior network model is used to detect the QR code version of the adjusted Founder QR code, and a corresponding standard QR code grid is generated according to the detected QR code version information. For example, a grid corresponding to the fourth version of the QR code, the grid size is 33x33 pixels, which is the same as the size of the fourth version of the QR code, and the size of the smallest square in the grid is also the same as the size of the smallest square of the fourth version of the QR code; then the corresponding standard QR code grid is used as prior knowledge and input into the enhancement network model. Since the model has been trained for blurred QR code images during the model training process, the trained prior network model can quickly detect and recognize the QR code version of the received blurred QR code image, generate a corresponding standard QR code grid according to the detected QR code version information, and use the corresponding standard QR code grid as prior knowledge and input it into the enhancement network model.
[0049] The enhanced network model is used to reduce noise and deblur QR codes. To ensure the deblurring effect and speed of the model, first, a third QR code dataset for training the enhanced network model is designed and produced. By shooting a QR code video and performing average consecutive short exposure frames to generate blurred images, and using the original QR code images that make up the QR code video as clear images, they are paired up to form the third QR code dataset for training. The QR code video contains paired QR codes collected by version classification. The number of pairs of QR codes for each version should be no less than 5000 pairs.
[0050] In real life, since the need to recognize QR codes often appears on terminals with low computing power and the recognition time limit is strict, therefore, the enhanced network model of the present invention can adopt the DeblurGANv2 model, which maintains extremely low parameter and computation amounts while ensuring efficient detection. The overall structure of this model includes two parts: a generator and a discriminator.
[0051] The generator network of the enhanced network model is constructed by introducing a Feature Pyramid Network (FPN) and a MobileNet backbone network; the Feature Pyramid Network has a bottom-up path, a top-down path, and lateral connections; in the bottom-up path, through consecutive convolutional and pooling operations, the spatial resolution of the feature map is gradually reduced while increasing the depth of the feature map, thereby extracting the semantic information of the image. In the top-down path, upsampling technology is used to increase the size of the original image. By cleverly applying an appropriate interpolation algorithm between the original image pixels, new pixel elements are inserted, and then the expansion of the image size is realized. Lateral connections: used to match and fuse the deep and shallow feature maps, this kind of fusion enhances the semantic information of the feature map and retains the detail information.
[0052] In the present invention, the MobileNet network is used as the backbone network, which is a design of a solution to improve the efficiency and adaptability of deblurring processing. This network adopts efficient technologies such as depthwise separable convolutions, significantly reducing the parameter and computation amounts. Compared with using the ResNet network as the backbone network, it can ensure high-performance effects while enabling it to be deployed on terminals with low computing levels for efficient operation.
[0053] In the present invention, the discriminator network of the enhanced network model adopts a dual-scale structure, including a global discriminator and a local discriminator. The global discriminator discriminates the entire image, while the local discriminator discriminates the local regions in the image. This dual-scale structure enables the discriminator to better capture the global and local features in the image. The discriminator measures the difference between the real image and the generated image according to a specific loss function. In the present invention, an adversarial loss function that incorporates the structural similarity metric value SSIM is adopted. The structural similarity metric value SSIM is used to guide the discriminator to more accurately evaluate the structural similarity between the generated image and the real image, and at the same time, it also helps the generator to generate images that are more similar in structure, thereby improving the quality of image generation.
[0054] In the DeblurGANv2 model adopted in the present invention, both the generator and the discriminator are provided with normalization layers. In the existing DeblurGANv2 model, the normalization layers in the generator and the discriminator often adopt Instance Normalization layers. When the enhanced network model with Instance Normalization layers is deployed on a terminal device for actual testing, it is found that there are cases where the finally generated data is incorrect. Since the Instance Normalization layer calculates the mean and variance separately for each channel of each sample, it is greatly affected by the samples, resulting in a large possible difference in the dynamic range between the input and the output. And quantization usually assumes that the dynamic range of the data is relatively fixed, so it is difficult to accurately represent the output of the Instance Normalization layer, resulting in a serious loss of quantization accuracy, and further resulting in incorrect data finally generated by the model.
[0055] In the present invention, by replacing the Instance Normalization layer with the Batch Normalization layer, the quantization accuracy loss of the model when deployed on a terminal device is effectively reduced, and the situation of incorrect data finally generated by the model is avoided. When the enhanced network model with Batch Normalization layers is deployed on a terminal device for actual testing, it is found that the generated data of the model is correct, ensuring the reliability of the model when deployed on a terminal device.
[0056] After determining the model, the QR code images in the third QR code dataset are input into the enhancement network model in pairs by version for training, and at the same time, the standard QR code grid of the corresponding version is input as prior knowledge to guide the noise reduction and deblurring process to obtain the parameter weights under the corresponding version. More specifically, based on the grid nature of the QR code, a grid structure is introduced as a geometric constraint to force the generation module to be strictly aligned and arranged, effectively suppressing the edge distortion and geometric deviation caused by motion blur, and ensuring that the reconstructed image conforms to the standard encoding specification. Secondly, the grid prior significantly optimizes the training efficiency by limiting the solution space dimension. The model does not need to traverse all pixel combinations, but focuses on the reasonable distribution that conforms to the logical structure of the QR code, effectively improving the parameter convergence speed. More importantly, the grid template has an adaptive error correction ability: when a local module is damaged, the network can infer the color distribution of the missing area based on the topological relationship of adjacent modules, and intelligently complete the information in combination with the redundancy characteristics of the encoding, improving the decodability while maintaining visual coherence.
[0057] During the training process of each version, the structural similarity measure value SSIM between the enhanced QR code image and the original QR code image is verified, and the calculated structural similarity measure value SSIM is compared with the set structural similarity measure value threshold. In the present invention, the set structural similarity measure value threshold is set to 0.7, which is determined based on multiple experimental verifications. When the structural similarity measure value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 1, the enhanced QR code image can be decoded and recognized; when the structural similarity measure value SSIM between the enhanced QR code image and the original QR code image is less than 0.7, the enhanced QR code image may not be decoded and recognized. Therefore, the set structural similarity measure value threshold can be set to 0.7.
[0058] The calculation formula for the structural similarity measure value SSIM is as follows:
[0059] SSIM(x,y)=(2*μx*μy+C1)*(frac{2*σxy+C2}{μx^2+μy^2+C1}*(σx^2+σy^2+C2))
[0060] Where x and y are two images to be compared, μx and μy respectively represent the means of these two images, σx^2 and σy^2 respectively represent the variances of these two images, σxy represents the covariance of these two images, and C1 and C2 are constants used to avoid the denominator being zero. The values of the constants vary according to the color range. Generally, C1=(K1*L)^2, C2=(K2*L)^2, where L is the range of pixel values, L-1 is the maximum pixel value, and K1 and K2 are constants less than 1.
[0061] If the structural similarity measurement value SSIM is less than the set threshold of the structural similarity measurement value, adjust the parameter weights, retrain, and perform the next comparison of the structural similarity measurement value SSIM; if the structural similarity measurement value SSIM is greater than or equal to the set threshold of the structural similarity measurement value, record the corresponding parameter weight data.
[0062] After completing the training of one version, replace the QR code with the QR code of the next version, and continuously repeat the above training process until the training of all versions is completed. Finally, save and record the weight parameters generated by the training to complete the model training.
[0063] In step S6, the trained enhanced network model performs noise reduction and deblurring processing on the received QR code. At the same time, the standard QR code grid is used to guide the noise reduction and deblurring process. Based on the grid nature of the QR code, a grid structure is introduced as a geometric constraint to force the generation module to be strictly aligned and arranged, effectively suppressing the edge distortion and geometric offset caused by motion blur, and ensuring that the reconstructed image conforms to the standard encoding specification. Secondly, the grid prior significantly optimizes the training efficiency by limiting the dimension of the solution space. The model does not need to traverse all pixel combinations, but focuses on the reasonable distribution that conforms to the logical structure of the QR code, effectively improving the parameter convergence speed. More importantly, the grid template has an adaptive error correction ability: when a local module is damaged, the network can infer the color distribution of the missing area based on the topological relationship of adjacent modules, and intelligently complete the information by combining the redundancy characteristics of the encoding, improving the decodability while maintaining visual coherence; among them, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 0.1.
[0064] The enhanced image is clearer and can be recognized by decoding. Finally, perform step S7, and input the enhanced QR code image into the QR code decoding library for decoding to obtain the recognition content of the QR code; the QR code decoding library can use the ZXing QR code decoding library.
[0065] The recognition effect of the QR code recognition method of the present invention has also been tested and compared with other existing public methods. The data is shown in the following table.
[0066] Table 1. Comparison of recognition rates of various QR code enhancement recognition methods
[0067] Method DeblurGAN DeblurGAN-v2 The method of the present invention Recognition rate (%) 35.79% 54.99% 94.00%
[0068] The QR codes used to test the recognition rates of the various methods in the above table are all QR codes with skew, defocus, or motion blur; the test data is as shown in the above table. Currently, the existing excellent public enhancement recognition method is the method using the DeblurGAN-v2 model, and the recognition rate of this method is 54.99%. Compared with the method using the previous version of the DeblurGAN model, the recognition rate has indeed improved. However, in actual scenario applications, this recognition rate is still relatively low, affecting customer use. The recognition rate of the method of the present invention is 94.00%, which is high. And compared with the existing publicly available method using the DeblurGAN-v2 model, the recognition rate has also been significantly improved. The present invention has excellent processing and recognition capabilities for skewed, defocused, and motion-blurred QR codes. Embodiment 2
[0069] Refer to Figure 2 , this embodiment provides a QR code recognition device, including an image acquisition module, an image correction module, a QR code decoding module, a version prior module, and an image enhancement module.
[0070] The image acquisition module detects and determines the QR code within the target area. The target area can be the area range that can be monitored when the camera is fixed at a certain position; the target area can also be the area range that can be captured when the handheld camera lens is used for shooting and scanning. When there is a QR code within the target area, the QR code is locked and intercepted, and during the interception process, ISP exposure adjustment is automatically performed according to the scene environment to avoid overexposure of the image; if there is no QR code within the target area, the detection continues. The intercepted QR code is transmitted to the image correction module.
[0071] The image correction module can quickly detect the position of the blurred QR code image received by using the trained detection network model, extract the QR code, and identify and mark the three corner points of the QR code.
[0072] After identifying and marking the three corner points of the QR code, the detection network model is used to perform processing such as rotation and deformation adjustment on the QR code. Specifically, according to the three corner points of the marked QR code and the three corner points in the standard coordinate system, a corresponding mapping relationship is established, and the QR code image is corrected based on this mapping relationship to adjust the QR code to a square QR code in the correct orientation. The so-called correct orientation means that the three corner points of the QR code are respectively located at the upper left, upper right, and lower left positions, and the overall orientation of the QR code is without tilt. The adjusted square QR code is input into the QR code decoding module.
[0073] The QR code decoding module uses the ZXing QR code decoding library to decode the received QR code and obtain the recognition content of the QR code; if the decoding of the received QR code fails, the QR code is transmitted to the version prior module and the image enhancement module.
[0074] The version prior module uses the trained prior network model to detect the version of the adjusted square QR code. Since the model has been trained for blurred QR code images during the training process, the trained prior network model can quickly detect and recognize the received blurred QR code images, and then generate the corresponding standard QR code grid according to the detected QR code version information. The corresponding standard QR code grid is used as prior knowledge and input into the image enhancement module.
[0075] The image enhancement module uses the trained enhancement network model to perform noise reduction and de-blurring processing on the received QR code. At the same time, the standard QR code grid is used to guide the noise reduction and de-blurring process. Based on the grid nature of the QR code, a grid structure is introduced as a geometric constraint to force the generation module to be strictly aligned and arranged, effectively suppressing edge distortion and geometric deviation caused by motion blur, and ensuring that the reconstructed image conforms to the standard coding specification. Secondly, the grid prior significantly optimizes the training efficiency by limiting the solution space dimension. The model does not need to traverse all pixel combinations, but focuses on the reasonable distribution that conforms to the logical structure of the QR code, effectively improving the parameter convergence speed. More importantly, the grid template has an adaptive error correction ability: when a local module is damaged, the network can infer the color distribution of the missing area based on the topological relationship of adjacent modules, and intelligently complete the information in combination with the redundancy characteristics of the coding, improving the decodability while maintaining visual coherence; among them, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 1.
[0076] The enhanced QR code image is input into the QR code decoding module, and the ZXing QR code decoding library is used to decode the enhanced QR code image to obtain the recognition content of the QR code.
[0077] The above-described embodiments are merely descriptions of the preferred embodiments of the present invention and do not limit the scope of the present invention. Without departing from the design spirit of the present invention, various deformations and improvements made by those of ordinary skill in the art to the technical solutions of the present invention shall fall within the protection scope of the present invention.
Claims
1. A method for identifying a two-dimensional code, characterized in that, It includes the following sequential steps: S1. Detect whether there is a QR code in the target area, lock and intercept the QR code in the target area; S2. Use the detection network model to detect, extract and mark the intercepted QR code image, and identify and mark the three corner points of the QR code; S3. Calculate the perspective transformation matrix according to the identified QR code corner points to align the QR code; S4. Input the adjusted square QR code into the QR code decoding library for decoding. If it can be directly decoded, obtain the recognition content of the QR code; if the QR code cannot be decoded, input it into the prior network model and the enhancement network model; S5. Use the prior network model to detect the QR code version of the adjusted square QR code, generate the corresponding standard QR code grid according to the detected QR code version information, and input the corresponding standard QR code grid as prior knowledge into the enhancement network model; S6. The enhancement network model performs noise reduction and deblurring processing on the received QR code. At the same time, it uses the standard QR code grid to guide the noise reduction and deblurring processing process. Based on the grid nature of the QR code, it introduces a grid structure as a geometric constraint to force the generation module to be strictly aligned and arranged, suppressing edge distortion and geometric offset caused by motion blur, and ensuring that the reconstructed image conforms to the standard coding specification; the grid prior significantly optimizes the training efficiency by limiting the dimension of the solution space. The model does not need to traverse all pixel combinations, but focuses on the reasonable distribution that conforms to the logical structure of the QR code, effectively improving the parameter convergence speed; the grid template has an adaptive error correction ability: when a local module is damaged, the network can infer the color distribution of the missing area based on the topological relationship of adjacent modules, and intelligently complete the information in combination with the redundancy characteristics of the coding, improving the decodability while maintaining visual coherence and realizing high-quality enhancement of the QR code; The enhancement network model adopts the DeblurGANv2 model. The backbone network part of this model adopts the MobileNet lightweight network. The discriminator network of the enhancement network model adopts a dual-scale structure, including a global discriminator and a local discriminator. The discriminator measures the difference between the real image and the generated image according to a specific loss function, and adopts an adversarial loss function that fuses the structural similarity measurement value SSIM. The structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 1; During the training process of each version, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image will be verified. The calculated structural similarity measurement value SSIM is compared with the set structural similarity measurement value threshold. If the structural similarity measurement value SSIM is less than the set structural similarity measurement value threshold, adjust the parameter weights, retrain, and perform the next comparison of the structural similarity measurement value SSIM; If the structural similarity measurement value SSIM is greater than or equal to the set structural similarity measurement value threshold, record the corresponding parameter weight data; S7. Input the enhanced QR code image into the QR code decoding library for decoding to obtain the recognition content of the QR code.
2. The method for identifying a two-dimensional code according to claim 1, characterized in that, The enhanced network model adopts a Batch Normalization normalization layer.
3. A method for identifying a two-dimensional code according to claim 1, characterized in that, The detection network model adopts the YOLOv8 model.
4. A QR code recognition method according to claim 1, characterized in that The prior network model adopts the MobileNetv2 model.
5. A method for identifying a two-dimensional code according to claim 1 or 3 or 4, characterized in that, It also includes a first QR code dataset for training the detection network model, and the first QR code dataset is obtained through the following steps: By shooting a QR code video and performing average continuous short exposure frames to generate blurred images, thereby forming the first QR code dataset for training; In the QR code video, multiple QR codes of different versions are cross-mixed and scattered at different positions without fixed settings. Use this first QR code dataset to train the detection network model to obtain parameter weights.
6. A method for identifying a two-dimensional code according to claim 1 or 3 or 4, characterized in that, It also includes a second QR code dataset for training the prior network model, and the second QR code dataset is obtained through the following steps: By shooting a QR code video and performing average continuous short exposure frames to generate blurred images, thereby forming the second QR code dataset for training; The QR code video contains QR codes of different versions collected by version classification. Input the QR code images in the second QR code dataset into the prior network model by version for training to obtain parameter weights under the corresponding version; Then repeat the training process of the prior network model and train with QR codes of different versions in turn to obtain parameter weights corresponding to different versions.
7. A method for identifying a two-dimensional code according to claim 1 or 3 or 4, characterized in that It also includes a third QR code dataset for training the enhanced network model, and the third QR code dataset is obtained through the following steps: By shooting a QR code video and performing average continuous short exposure frames to generate blurred images, and using the original QR code image that constitutes the QR code video as a clear image, thereby forming the third QR code dataset for training by pairwise combination; The QR code video contains QR codes of different versions collected by version classification. Input the QR code images in the third QR code dataset into the enhanced network model in pairs by version for training, and at the same time input the standard QR code grid of the corresponding version as prior knowledge to guide the noise reduction and deblurring process to obtain parameter weights under the corresponding version; Then repeat the training process of the enhanced network model and train with QR codes of different versions in turn to obtain parameter weights corresponding to different versions.
8. A two-dimensional code recognition device for performing a two-dimensional code recognition method according to any one of claims 1-7, characterized in that, It includes: An image acquisition module that detects and determines whether there is a QR code in the target area, intercepts the QR code in the target area, automatically adjusts the ISP exposure according to the scene environment during the interception process, and transmits the intercepted QR code to the image correction module; An image correction module that detects and extracts the QR code in the image, and performs processing such as rotation and deformation adjustment on the QR code, adjusts the QR code that is tilted at any angle and deformed into a square QR code in the correct orientation, and transmits the adjusted square QR code to the QR code decoding module; A QR code decoding module that uses the ZXing QR code decoding library to decode the received QR code and obtain the recognition content of the QR code; If the decoding of the received QR code fails, the QR code will be transmitted to the version prior module and the image enhancement module. The version prior module detects the version of the received QR code, generates a corresponding standard QR code grid according to the detected QR code version information, and inputs the corresponding standard QR code grid as prior knowledge into the image enhancement module; The image enhancement module performs noise reduction and de-blurring processing on the received QR code. At the same time, it uses the standard QR code grid to guide the noise reduction and de-blurring processing process to achieve high-quality enhancement of the QR code. Among them, the structural similarity measurement value SSIM between the enhanced QR code image and the original QR code image is greater than or equal to 0.7 and less than 1. The enhanced QR code image is input into the QR code decoding module.
Citation Information
Patent Citations
Two-dimensional code identification method, device and equipment
CN110046529A
Low-quality two-dimensional code information extraction method and device based on run length coding
CN112069852A
License plate deblurring detection method based on deep learning
CN113111859A