Two-dimensional code image restoration method
By using the convolutional neural network Q-GPN to repair PCB QR code images, and leveraging the prior structural information of the QR code and Reed-Solomon decoding, this method solves the problems of insufficient repair accuracy and low efficiency due to reliance on manual labor in existing technologies. It achieves efficient and accurate QR code repair, adapts to different versions and error correction levels, and meets the needs of industrial production.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANG XI XU SHENG DIAN ZI GU FEN YOU XIAN GONG SI
- Filing Date
- 2026-02-05
- Publication Date
- 2026-05-15
AI Technical Summary
Existing circuit board QR code repair methods suffer from poor adaptability to special surface materials, insufficient repair accuracy, low efficiency due to reliance on manual operation, and the inability of natural image repair algorithms to effectively handle QR code damage scenarios, resulting in artifacts, grid misalignment, or logical conflicts in the repair results, which cannot meet the needs of rapid and accurate repair in mass production of circuit boards.
QR code image restoration is performed using a convolutional neural network (Q-GPN). Through geometric correction and binarization, combined with structural masking and Reed-Solomon decoding, end-to-end training is conducted using the black and white dual-color of the QR code, modular gridding, and prior information of key positioning graphics to achieve generative completion and iterative error correction, generating restoration results that conform to the coding specifications.
It significantly improves the decodeability and accuracy of the repair results, has a high degree of automation, can quickly process batch circuit board QR code images, meets the high-efficiency repair needs of industrial production, is compatible with different versions and error correction levels of QR codes, and has versatility and flexibility.
Smart Images

Figure CN122048744A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of circuit board manufacturing technology, specifically a method for restoring QR code images. Background Technology
[0002] A circuit board QR code is a unique identifier on a printed circuit board (PCB) used for traceability, similar to an "ID card" for the circuit board. It mainly contains information such as model, batch, and serial number, and its entire lifecycle data can be traced by scanning it.
[0003] Repairing QR codes on circuit boards is a necessary measure to ensure product quality and improve management efficiency. It is recommended to contact professional technicians for testing and repair to ensure the integrity and readability of the QR codes. Existing QR code image repair methods often suffer from poor adaptability to special surface materials of circuit boards, insufficient repair accuracy, and low efficiency due to reliance on manual operation. They are particularly ill-suited for scenarios where QR codes are damaged during production due to scratches, ink loss, solder pad reflections, or obstruction by surrounding circuitry, failing to meet the practical needs of rapid and accurate QR code repair in mass production of circuit boards. Furthermore, existing image repair algorithms (such as PatchMatch, GMCNN, and EdgeConnect) are geared towards natural images and do not utilize the strong prior knowledge of QR codes, such as their "black and white dual-color, modular gridding, and inclusion of synchronization / correction graphics," leading to artifacts, grid misalignment, or logical conflicts in the repair results, making decoding impossible. Therefore, this invention provides a QR code image repair method. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a QR code image restoration method, aiming to solve the aforementioned problems.
[0005] To achieve the above objectives, the present invention provides the following technical solution: a QR code image restoration method, comprising the following steps:
[0006] S1. Obtain the QR code image to be repaired (I) in ;
[0007] S2, regarding the I in Geometric correction and binarization are performed to obtain a standard-sized binary image I. bin ;
[0008] S3, Analyze the I bin It identifies the positioning pattern, timing pattern, version information, and format information, and generates a structural mask M. s ;
[0009] S4, the I bin With the structure mask M s Input the Q-GPN generative completion network to obtain the initial repair graph I.rec0 The Q-GPN is a convolutional neural network, and its training process includes: constructing a training set containing triples of damaged QR code images, structural masks, and corresponding complete QR code images, and using a total loss function L... total Perform end-to-end training, the L total This includes pixel loss, perceptual loss, adversarial loss, and codeword consistency loss;
[0010] S5, regarding the I rec0 Perform Reed-Solomon decoding. If decoding is successful, output the I value. rec0 This will be the final repaired image; if decoding fails, proceed to step S6.
[0011] S6. Update the error correction mask M based on the codeword positions where Reed-Solomon decoding failed. e and the M e With the structure mask M s Fusion yields the joint mask M u ;
[0012] S7. Using the combined mask M u To constrain, the I is re-defined. rec0 The Q-GPN is input for refinement and repair, resulting in refined and repaired image I. rec1 ;
[0013] S8, regarding the I rec1 Perform Reed-Solomon decoding again. If decoding is successful, output the I value. rec1 As the final repaired image; if decoding fails and the number of iterations does not reach the preset maximum number of iterations N, then return to S6; otherwise, output the I... rec1 And mark it as requiring manual review.
[0014] Preferably, the geometric correction includes the following steps:
[0015] Detection of QR code image to be repaired I bin The three corner positioning patterns in the image are: the image contour features are extracted by the edge detection operator, and the "3×3 black-white-black" module structure template of the QR code positioning pattern is matched to select three candidate positioning areas that meet the size ratio and symmetry features, and their center coordinates are determined. When the positioning pattern is partially missing, the missing contour is filled in and the center coordinates are calculated based on the center coordinates of the other positioning patterns and the fixed structure prior of the QR code positioning pattern.
[0016] An affine transformation matrix is constructed based on the center coordinates of three positioning patterns: using the center coordinates of the positioning patterns of the standard QR code as the target, rotation, scaling, and translation parameters are calculated to map the QR code image to be repaired onto a rectangular standard coordinate space, completing geometric correction and obtaining the corrected image I. geo .
[0017] Preferably, the binarization specifically includes: addressing issues such as pad reflection and uneven local illumination on the tested surface, employing an optimized local adaptive threshold segmentation algorithm to segment I... geo Convert to a binary image containing only black and white pixels, where black pixels represent valid QR code modules and white pixels represent background or invalid areas, ultimately resulting in a standard-sized binary image I. bin .
[0018] Preferably, the structural mask M s The generation process includes: based on the coordinates of the identified positioning graphic, timing graphic, version information area and format information area, marking the above areas as 1 and the remaining data areas as 0, forming a binary mask with the same size as the input QR code.
[0019] Preferably, the error correction mask M e The update method is as follows: based on the error codeword position index returned when Reed-Solomon decoding fails, the pixel region of the corresponding codeword in the image is marked as 1 (the region that needs to be repaired), and the region of no error codewords is marked as 0; when decoding fails for the first time, M e Initialize as a zero-based mask, marking only the current erroneous codeword region; during iteration, in the original M... e New error codeword region markers are superimposed on top of this.
[0020] Preferably, the completion network Q-GPN specifically includes:
[0021] The encoder module employs a multi-layer convolutional neural network to process the input binary image I. bin With structural mask M s The splicing features are extracted layer by layer to obtain multi-scale QR code feature representations;
[0022] The structural information fusion module, through an attention mechanism, embeds key structural information such as positioning and timing patterns into the features output by the encoder, thereby enhancing the network's ability to perceive the structure of the QR code.
[0023] The decoder module uses transposed convolutional layers to progressively restore the spatial resolution of the feature maps, outputting an initial repaired image I with the same size as the input. rec0 .
[0024] Preferably, the convolutional layers of the encoder module employ ReLU activation and batch normalization; the attention weights of the structural information fusion module are based on the QR code structural mask M. s The spatial distribution is dynamically calculated; the output layer of the decoder module uses the Sigmoid activation function to map the feature values to the 0-1 interval to generate a binarized repair result.
[0025] Preferably, the total loss function L of the Q-GPN completion network is... total for:
[0026] ,
[0027] in, for Pixel loss;
[0028] To perceive loss;
[0029] To combat the losses;
[0030] This is due to codeword consistency loss;
[0031] These are the weighting coefficients.
[0032] Preferably, the Q-GPN training of the completion network includes:
[0033] Constructing the training dataset: Collect standard QR code images of different versions and error correction levels as the basic sample library. For each basic sample, generate damaged QR code images by simulating the damage type in real-world scenarios, and retain the corresponding complete QR code images as the real labels. For each damaged sample, pre-generate its structural mask M. s This forms training data consisting of a triplet of damaged image, a structural mask, and a ground truth label.
[0034] Initialize model parameters: Use the He normal distribution to initialize all learnable parameters of the Q-GPN encoder, structural information fusion module and decoder;
[0035] Set training hyperparameters: Select the Adam optimizer, set the initial learning rate to 1e-4, and decay the learning rate to 10% of the initial value every 100 epochs using a cosine annealing strategy; set the batch size to 32, and the maximum number of training epochs to 500.
[0036] Perform training iterations: In each training epoch, randomly sample several triplet data points, concatenate the damaged QR code image with the structural mask, and input the result into the Q-GPN to obtain the repaired output. Calculate the total loss function L between the output and the true label. total All parameters of the model are updated through backpropagation;
[0037] Validation and model saving: Every 20 epochs, the model's repair success rate and average loss value are evaluated using an independent validation dataset. If the current model has the highest repair success rate and the smallest loss value on the validation set, the model parameters are saved as the optimal model.
[0038] Model fine-tuning: After training, the optimal model is fine-tuned using a small number of scene-specific damage samples to further improve the model's repair performance in the target scene, based on the damage characteristics of the specific scene.
[0039] Preferably, the preset maximum number of iterations N ranges from 3 to 5 times; and the marking information for manual review includes: the damage type of the QR code, the number of iterations for repair, and the distribution location map of the erroneous codewords.
[0040] Beneficial effects
[0041] Compared with the prior art, the present invention has the following advantages:
[0042] This invention fully utilizes the strong prior information of QR codes, such as their black-and-white dual-color scheme, modular grid structure, and key positioning graphics, avoiding artifacts, grid misalignment, or logical conflicts that are easily generated by natural image restoration algorithms, thus significantly improving the decodeability of the restoration results. The Q-GPN network enhances the perception of QR code structure through a structural information fusion module, and combined with an iterative error correction mechanism, it precisely refines the restoration of erroneous codeword areas, greatly improving restoration accuracy and success rate. The entire process is highly automated, requiring minimal manual intervention, and can quickly process batches of circuit board QR code images, meeting the actual needs of efficient restoration in industrial production. It is compatible with different versions and error correction levels of QR codes, and can be further adapted to specific production environments through scene-specific sample fine-tuning, exhibiting strong versatility and flexibility.
[0043] Image standardization is ensured through geometric correction and binarization. A structural mask is generated by combining the structural prior of the QR code. Generative completion is achieved using the Q-GPN network. The repair effect is iteratively optimized through Reed-Solomon decoding feedback. This effectively solves the problems of poor adaptability, insufficient repair accuracy, and low efficiency due to reliance on manual labor in existing technologies. Attached Figure Description
[0044] Figure 1 This is a flowchart of the process of this invention;
[0045] Figure 2This is a flowchart illustrating the geometric correction process of the present invention;
[0046] Figure 3 This is a working block diagram of the Q-GPN network of this invention;
[0047] Figure 4 This is a schematic diagram of the Q-GPN training process for the completion network in this invention. Detailed Implementation
[0048] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0049] Please see Figure 1-4 This embodiment provides a QR code image restoration method, including the following steps:
[0050] S1. Obtain the QR code image to be repaired (I) in This provides raw data support for subsequent QR code image preprocessing, damaged area identification and location, and iterative repair, ensuring that the repair process can conduct accurate analysis and targeted operations based on the initial image, laying the foundation for damage type judgment, error code location, and repair strategy selection in subsequent steps.
[0051] S2, for I in Geometric correction and binarization are performed to obtain a standard-sized binary image I. bin This eliminates geometric distortions and grayscale interference caused by shooting angle deviations, optical distortions, or uneven lighting in the original image, converting the image into a standardized binary form that conforms to the QR code encoding standard. It clearly presents the codeword array structure and positioning mark features of the QR code, providing a unified and reliable image analysis foundation for the accurate identification of damaged areas, rapid location of erroneous codewords, and targeted implementation of iterative repair strategies. This ensures that the judgment of damage type, the location of erroneous codeword distribution, and the selection of repair schemes in subsequent steps can be carried out based on standardized image data, improving the accuracy and efficiency of the entire repair process.
[0052] S3, Analysis I bin It identifies the positioning pattern, timing pattern, version information, and format information, and generates a structural mask M. sThis allows for a clear understanding of the spatial distribution and structural boundaries of the various functional modules within the QR code. It precisely divides fixed structural areas (such as positioning graphics, timing graphics, version and format information areas) from variable data codeword areas, forming a structured area identification template. This not only effectively avoids erroneous operations on non-data areas during subsequent repair processes but also provides a clear spatial reference framework for quickly locating the damaged location and extent of data codewords in the damaged area identification step. This ensures that subsequent damage type judgment and repair strategy formulation can focus on the data areas that truly need repair, further improving the targeting and accuracy of the repair. Simultaneously, it provides structural constraints for modifying and verifying data codewords during iterative repair, ensuring that the repaired QR code still meets the structural requirements of the coding specifications.
[0053] S4, I bin With structural mask M s Input the Q-GPN generative completion network to obtain the initial repair graph I. rec0 The Q-GPN is a convolutional neural network, and its training process includes: constructing a training set containing triples of damaged QR code images, structural masks, and corresponding complete QR code images, and using a total loss function L... total Perform end-to-end training, the L total This includes pixel loss, perceptual loss, adversarial loss, and codeword consistency loss; thus, it can leverage the contextual awareness and structure-aware characteristics of generative models to target structural masks M. s The identified damaged data codeword areas are accurately filled in. Under the premise of strictly following the constraints of the QR code encoding structure, an initial repair result that conforms to the data codeword distribution pattern and neighborhood correlation is generated. This initial repair map not only provides a basic template with reasonable data distribution for subsequent iterative repair steps, but also reduces the computational load of subsequent verification and adjustment through the global consistency guarantee of generative completion. This ensures that the iterative repair process can be carried out in an initial state that is closer to the true solution, further improving the efficiency of repair and the reliability of the final result. At the same time, it provides a structured candidate repair scheme for subsequent verification and fine-tuning steps based on error correction codes.
[0054] S5, to I rec0 Perform Reed-Solomon decoding. If decoding is successful, output I. rec0As the final repaired image, it enables rapid verification of the validity and data integrity of the initial repair result. The error correction mechanism of Reed-Solomon codes is used to confirm the correctness of the encoding logic of Irec0 output by the generative completion network. If decoding is successful, it indicates that the initial repair has accurately restored the original information of the damaged data codewords. At this time, directly outputting the result can avoid redundant iterative calculations and ensure that the repaired QR code not only meets the structural requirements of the encoding specification but can also be accurately recognized and parsed by standard scanning devices, achieving dual compliance of data content and visual structure, that is, restoring its readability and information accuracy. If decoding fails, S6 is executed.
[0055] S6. Update the error correction mask M based on the codeword positions where Reed-Solomon decoding failed. e and M e With structural mask M s Fusion yields the joint mask M u This allows for the precise marking of target repair sub-regions that belong to both variable data codeword regions and have decoding errors. It deeply integrates structural constraints with data-level error information to form a joint repair template that combines spatial structure guidance and error location functions.
[0056] S7, using a combined mask M u To constrain, I will be re-evaluated. rec0 Inputting Q-GPN for refinement and repair yields refinement and repair image I. rec1 This allows the Q-GPN (QR code generative completion network) to focus on the local locations requiring correction, based on the key decoding error codeword regions marked by the joint mask Mu. This avoids redundant processing of error-free regions and leverages the network's contextual association capabilities and error-aware characteristics to improve the initial repair of the QR code. rec0 Precise local adjustments and optimizations are made to codewords with deviations, which not only specifically resolve decoding errors not eliminated in the initial repair but also improve the structural mask M. s Under the constraints of [unclear], this ensures that the adjusted codewords still conform to the spatial distribution specifications and structural requirements of QR codes, providing candidate repair results that are closer to real data for subsequent Reed-Solomon decoding verification, significantly improving the probability of successful decoding; at the same time, it refines the repaired I [unclear]. rec1 It retains the correct structural modules and valid data information from the initial repair, and also specifically corrects the core deviations that caused the decoding failure. This provides a high-quality image foundation for the next step of the iterative repair process, such as verification or termination. It further ensures that the repaired QR code can meet the dual requirements of visual structural compliance and data content readability, and ensures that the final output repair result can be accurately recognized and parsed by standard barcode scanning devices.
[0057] S8, to I rec1 Perform Reed-Solomon decoding again. If decoding is successful, output I. rec1 As the final repaired image; if decoding fails and the number of iterations has not reached the preset maximum number of iterations N, then return to S6; otherwise, output I. rec1 And mark it as requiring manual review.
[0058] Specifically, geometric correction includes the following steps:
[0059] Detection of QR code image to be repaired I bin The three corner positioning patterns in the image are: the image contour features are extracted by the edge detection operator, and the "3×3 black-white-black" module structure template of the QR code positioning pattern is matched to select three candidate positioning areas that meet the size ratio and symmetry features, and their center coordinates are determined. When the positioning pattern is partially missing, the missing contour is filled in and the center coordinates are calculated based on the center coordinates of the other positioning patterns and the fixed structure prior of the QR code positioning pattern.
[0060] An affine transformation matrix is constructed based on the center coordinates of three positioning patterns: using the center coordinates of the positioning patterns of the standard QR code as the target, rotation, scaling, and translation parameters are calculated to map the QR code image to be repaired onto a rectangular standard coordinate space, completing geometric correction and obtaining the corrected image I. geo .
[0061] The aforementioned geometric correction accurately corrects geometric distortions in the original QR code image caused by tilted shooting angles, perspective distortion, or physical bending. It converts irregular QR code images into regular rectangular structures conforming to encoding standards, ensuring that the spatial positions and proportions of each functional module (such as positioning graphics, timing graphics, and data codeword areas) strictly adhere to QR code encoding specifications. Simultaneously, by completing the outline of missing positioning patterns, it resolves correction failures caused by localized damage to the positioning patterns, improving the adaptability of the geometric correction step to severely damaged QR codes. The final output corrected image I... geo This provides a geometrically normalized image basis for subsequent binarization processing, ensuring that the resulting I... bin It can accurately reflect the codeword array structure of the QR code, providing a reliable spatial coordinate reference for subsequent structural analysis, damaged area identification and generative completion repair, effectively improving the entire repair process's ability to handle geometrically distorted QR codes and the repair success rate.
[0062] Specifically, binarization includes: addressing issues such as pad reflection and uneven local illumination on the tested surface, employing an optimized local adaptive threshold segmentation algorithm to segment I... geoConvert to a binary image containing only black and white pixels, where black pixels represent valid QR code modules and white pixels represent background or invalid areas, ultimately resulting in a standard-sized binary image I. bin .
[0063] Specifically, the structural mask M s The generation process includes: based on the coordinates of the identified positioning pattern (a square area at three corners), timing pattern (alternating black and white lines in the horizontal and vertical directions), version information area, and format information area, marking the above areas as 1 (the structural areas to be retained) and the remaining data areas as 0 (the areas that can be completed), forming a binary mask with the same size as the input QR code; that is, it can clearly define the fixed structural modules that cannot be modified and the data codeword areas that can be completed in the QR code, effectively avoiding the subsequent repair algorithm's misoperation of the core structures such as the positioning pattern and timing pattern; at the same time, it provides a precise spatial division basis for the damaged area identification step, enabling the algorithm to quickly focus on the damaged location of the data area and reduce invalid calculations; in addition, the structural mask M s It can also serve as a spatial constraint for generative completion networks, ensuring that the network strictly adheres to the structural specifications of QR codes when completing data codewords, and avoiding the generation of module layouts that do not conform to the encoding standards; finally, the structural mask M s This also provides a structural reference for the subsequent Reed-Solomon decoding process, helping the decoding algorithm to accurately skip fixed structural regions and focus on parsing data codewords, thereby improving the accuracy and efficiency of decoding.
[0064] Specifically, the error correction mask M e The update method is as follows: based on the error codeword position index returned when Reed-Solomon decoding fails, the pixel region of the corresponding codeword in the image is marked as 1 (the region that needs to be repaired), and the region of no error codewords is marked as 0; when decoding fails for the first time, M e Initialize as a zero-based mask, marking only the current erroneous codeword region; during iteration, in the original M... e On top of this, new error codeword region markers are superimposed. This update method can accurately capture the positions of codewords that have not been correctly repaired in each iteration, achieving dynamic tracking and focusing on error regions. This avoids repeated operations on correctly recovered regions during subsequent repair processes, significantly improving the efficiency of iterative repair. Simultaneously, by iteratively superimposing error region markers, all problematic data codewords in the QR code can be gradually covered, ensuring that the generative completion network can specifically address each unresolved error in subsequent refined repair steps, effectively improving the repair capability for severely damaged QR codes. Furthermore, this update method, along with the structural mask M... s The fusion can further clarify the priority and scope of repair, enabling the joint mask M uIt incorporates structural constraints and precisely targets the current error region, guiding the Q-GPN network to concentrate resources on repairing critical erroneous codewords while strictly adhering to coding specifications, thus reducing unnecessary computation. Ultimately, through this dynamically updated error correction mask, it ensures that each iteration of repair can be precisely adjusted based on the latest error feedback, gradually approaching the correct original data, significantly increasing the probability of successful final decoding. At the same time, it provides a clear basis for determining the distribution of error regions for iteration termination conditions, ensuring the scientific and efficient nature of the repair process.
[0065] Specifically, completing the network Q-GPN includes:
[0066] The encoder module employs a multi-layer convolutional neural network to process the input binary image I. bin With structural mask M s The splicing features are extracted layer by layer to obtain multi-scale QR code feature representations;
[0067] The structural information fusion module, through an attention mechanism, embeds key structural information such as positioning and timing patterns into the features output by the encoder, thereby enhancing the network's ability to perceive the structure of the QR code.
[0068] The decoder module uses transposed convolutional layers to progressively restore the spatial resolution of the feature maps, outputting an initial repaired image I with the same size as the input. rec0 .
[0069] Specifically, the convolutional layers of the encoder module employ ReLU activation and batch normalization to avoid gradient vanishing and accelerate model convergence; the attention weights of the structural information fusion module are based on the QR code structural mask M. s The spatial distribution is dynamically calculated to ensure that the features of key structural regions are preferentially preserved; the output layer of the decoder module uses the Sigmoid activation function to map the feature values to the 0-1 interval to generate a binarized repair result.
[0070] In summary, with the effective cooperation of the encoder module, structural information fusion module, and decoder module, accurate generative completion of damaged areas in QR code data can be achieved, while strictly adhering to the structural mask M... s Under the constraint that the defined fixed structural region cannot be modified, the multi-scale features extracted by the encoder are used to capture the global and local contextual relationships of the QR code. The attention mechanism of the structural information fusion module is used to strengthen the guiding role of key structures in data region completion. Finally, the decoder outputs a binarized initial repaired image I that conforms to the QR code encoding standard. rec0The Q-GPN completion network can not only effectively handle local or large-area data codeword damage caused by scratches, occlusions, ink loss, etc., but also ensure that the repaired QR code is structurally highly consistent with the original encoding standard. This provides a solid foundation for subsequent error correction verification and iterative refinement repair based on Reed-Solomon codes, and significantly improves the accuracy, robustness and efficiency of the entire QR code image repair process.
[0071] Specifically, complete the total loss function L of the Q-GPN network. total for:
[0072] ,
[0073] in, for Pixel loss; To perceive loss; To combat the losses; This is due to codeword consistency loss; These are the weighting coefficients.
[0074] Specifically, Q-GPN training for network completion includes:
[0075] Constructing the training dataset: Collect standard QR code images of different versions and error correction levels as the basic sample library. For each basic sample, generate damaged QR code images by simulating damage types in real-world scenarios (such as random occlusion, linear scratching, Gaussian blur, uneven brightness, etc.), and retain the corresponding complete QR code images as the real labels. For each damaged sample, pre-generate its structural mask M. s This generates training data consisting of a damaged image, a structural mask, and a ground truth label; thus, it provides the Q-GPN network with high-quality training samples covering multiple scenarios and damage types, enabling the network to simultaneously learn the structural constraints of the QR code during training (through the structural mask M). s By analyzing the distribution patterns of QR codewords with real data (using real labels), the model simulates the complex and diverse damage scenarios in real-world applications, significantly improving its generalization and repair capabilities for different degrees and types of damage. Simultaneously, a pre-generated structural mask M... s This avoids the redundant overhead of repeatedly calculating structural information during the training phase, thus accelerating model training efficiency. The input format of triplet data can also guide the network to strictly follow the fixed structural specifications of QR codes when completing data regions, ensuring that the generated repair results not only meet the visual structural requirements but also accurately restore the data information, laying a solid model foundation for efficient repair in subsequent real-world scenarios.
[0076] Initializing model parameters: All learnable parameters of the Q-GPN encoder, structural information fusion module, and decoder are initialized using the He normal distribution. This ensures that the parameters of each layer of the model are within a reasonable numerical distribution range during the initial training phase, effectively avoiding gradient explosion or vanishing problems caused by improper parameter initialization, and providing a stable starting point for the subsequent backpropagation optimization process. At the same time, for complex tasks such as multi-scale feature extraction of the encoder, attention weight calculation of the structural information fusion module, and spatial resolution restoration of the decoder in the Q-GPN network, the He normal distribution initialization can maintain a relatively stable variance of the output features of each layer, helping the network to capture the correlation between the fixed structure of the QR code and the data codewords more quickly, improving the accuracy and efficiency of the model in completing damaged areas, and laying a solid foundation for the efficient advancement of the entire training process.
[0077] Setting training hyperparameters: Select the Adam optimizer, with an initial learning rate of 1e-4. This effectively adapts to the non-convex optimization requirements of structural constraints and data recovery in QR code repair tasks, quickly converging to a better parameter space. The learning rate decays to 10% of its initial value every 100 epochs using a cosine annealing strategy. This strategy allows for rapid exploration of the parameter range with a larger learning rate in the early stages of training, followed by gradual reduction of the learning rate to fine-tune model parameters. This avoids parameter oscillations caused by an excessively high learning rate or convergence stagnation caused by an excessively low learning rate, improving the model's accuracy in repairing damaged QR code structures and recovering data. Batch size (batch...) The batch size is set to 32. This ensures the stability of gradient estimation while balancing GPU memory utilization and training efficiency, enabling the model to efficiently process training data from damaged samples across multiple scenarios. The maximum number of training epochs is set to 500. This provides the model with sufficient iterations to ensure it fully learns the structural patterns and codeword distribution of QR codes. Combined with appropriate regularization, this effectively avoids overfitting, ultimately giving the Q-GPN network excellent generalization repair capabilities and stable performance.
[0078] Training iterations are performed: In each training epoch, several triplet data points are randomly sampled. The damaged QR code image is then stitched together with a structural mask and input into the Q-GPN to obtain the repaired output. This continuous iterative optimization process allows the model to constantly correct parameter deviations, gradually reducing the structural differences and data errors between the repaired output and the true label. Combining the structural constraints of the triplet data with the data guidance of the true label, the model strengthens its adherence to the fixed structural specifications of the QR code and the capture of the data codeword distribution patterns in each iteration. The total loss function L between the output and the true label is calculated. totalBy updating all model parameters through backpropagation and precisely adjusting the parameters of the encoder, structural information fusion module, and decoder through backpropagation of the total loss function, the model can gradually improve repair accuracy during training on damaged samples in multiple scenarios. At the same time, random sampling ensures the diversity of training data and avoids overfitting of the model to specific samples. Ultimately, the Q-GPN network can stably output repair results that meet both structural requirements and accurate decoding, thus satisfying the high reliability requirements of QR code damage repair in real-world scenarios.
[0079] Validation and Model Saving: Every 20 epochs, the model's repair success rate and average loss are evaluated using an independent validation dataset. If the current model has the highest repair success rate and the lowest loss on the validation set, the model parameters are saved as the optimal model. This allows for timely capture of the model's optimal generalization state through periodic validation, avoiding performance degradation due to overfitting during subsequent training. The use of an independent validation dataset ensures that the evaluation results are not affected by training data distribution bias, truly reflecting the model's repair capabilities in unseen damage scenarios. Saving the optimal model parameters not only provides the most stable and accurate version for actual deployment but also avoids resource waste caused by training interruptions or parameter oscillations. Ultimately, this ensures that the Q-GPN network can efficiently and reliably complete various damaged QR code repair tasks in practical applications, meeting the high requirements for QR code image repair in different scenarios.
[0080] Model fine-tuning: After training, the optimal model is fine-tuned using a small number of scene-specific damage samples to further improve its repair performance in the target scene, targeting the damage characteristics of specific scenarios (such as QR codes on circuit boards, QR codes on paper documents, etc.). This allows the model to quickly adapt to the unique damage characteristics of specific scenarios (such as oil stains and metallic reflections common in QR codes on circuit boards, and wrinkles, deformations, and ink stains in QR codes on paper documents), compensating for the insufficient coverage of scene-specific damage patterns in the general training dataset. The fine-tuning strategy using a small number of scene-specific samples avoids overfitting the model to small sample data and efficiently transfers the QR code structure and data recovery capabilities learned by the general model to the target scene. Ultimately, this significantly improves the repair success rate, decoding accuracy, and robustness of the Q-GPN network in the target scene, meeting the precise and customized needs of QR code image repair in various industry sub-scenarios, and promoting the wider application of AI-driven QR code repair technology in practical application scenarios such as industrial quality inspection and document management.
[0081] Specifically, the maximum number of iterations N is preset to a range of 3 to 5 times, which can reduce unnecessary iterative calculations and improve the efficiency of the overall repair process while ensuring the repair effect. The marking information for manual review includes: the type of damage to the QR code (such as large-area obstruction, severe blurring, code word errors that cannot be corrected after multiple iterations), the number of iterations for repair, and the distribution map of the erroneous code words, so that reviewers can quickly locate the problem area and make targeted corrections.
[0082] Furthermore, any content not described in detail in this specification is existing technology known to those skilled in the art.
[0083] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0084] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for restoring QR code images, characterized in that, Includes the following steps: S1. Obtain the QR code image to be repaired (I) in ; S2, regarding the I in Geometric correction and binarization are performed to obtain a standard-sized binary image I. bin ; S3, Analyze the I bin It identifies the positioning pattern, timing pattern, version information, and format information, and generates a structural mask M. s ; S4, the I bin With the structure mask M s Input the QR code generative completion network Q-GPN to obtain the initial repair graph I. rec0 The Q-GPN is a convolutional neural network, and its training process includes: constructing a training set containing triples of damaged QR code images, structural masks, and corresponding complete QR code images, and using a total loss function L... total Perform end-to-end training, the L total This includes pixel loss, perceptual loss, adversarial loss, and codeword consistency loss; S5, regarding the I rec0 Perform Reed-Solomon decoding. If decoding is successful, output the I value. rec0 This will be the final repaired image; if decoding fails, proceed to step S6. S6. Update the error correction mask M based on the codeword positions where Reed-Solomon decoding failed. e and the M e With the structure mask M s Fusion yields the joint mask M u ; S7. Using the combined mask M u To constrain, the I is re-defined. rec0 The Q-GPN is input for refinement and repair, resulting in refined and repaired image I. rec1 ; S8, regarding the I rec1 Perform Reed-Solomon decoding again. If decoding is successful, output the I value. rec1 As the final repaired image; if decoding fails and the number of iterations does not reach the preset maximum number of iterations N, then return to S6; otherwise, output the I... rec1 And mark it as requiring manual review.
2. The QR code image restoration method according to claim 1, characterized in that, The geometric correction includes the following steps: Detection of QR code image to be repaired I bin The three corner positioning patterns in the image are: the image contour features are extracted by the edge detection operator, and the "3×3 black-white-black" module structure template of the QR code positioning pattern is matched to select three candidate positioning areas that meet the size ratio and symmetry features, and their center coordinates are determined. When the positioning pattern is partially missing, the missing contour is filled in and the center coordinates are calculated based on the center coordinates of the other positioning patterns and the fixed structure prior of the QR code positioning pattern. An affine transformation matrix is constructed based on the center coordinates of three positioning patterns: using the center coordinates of the positioning patterns of the standard QR code as the target, rotation, scaling, and translation parameters are calculated to map the QR code image to be repaired onto a rectangular standard coordinate space, completing geometric correction and obtaining the corrected image I. geo .
3. The QR code image restoration method according to claim 2, characterized in that, The binarization specifically includes: addressing issues such as pad reflection and uneven local illumination on the tested surface, employing an optimized local adaptive threshold segmentation algorithm to segment I... geo Convert to a binary image containing only black and white pixels, where black pixels represent valid QR code modules and white pixels represent background or invalid areas, ultimately resulting in a standard-sized binary image I. bin .
4. The QR code image restoration method according to claim 1, characterized in that, The structural mask M s The generation process includes: based on the coordinates of the identified positioning graphic, timing graphic, version information area and format information area, marking the above areas as 1 and the remaining data areas as 0, forming a binary mask with the same size as the input QR code.
5. A QR code image restoration method according to claim 1, characterized in that, The error correction mask M e The update method is as follows: based on the error codeword position index returned when Reed-Solomon decoding fails, the pixel area of the corresponding codeword in the image is marked as 1 (the area that needs to be repaired), and the area of no error codeword is marked as 0; When the first decoding fails, M e Initialize to an all-zero mask, marking only the current erroneous codeword region; During the iteration process, in the original M e New error codeword region markers are superimposed on top of this.
6. The QR code image restoration method according to claim 1, characterized in that, The completion network Q-GPN includes: The encoder module employs a multi-layer convolutional neural network to process the input binary image I. bin With structural mask M s The splicing features are extracted layer by layer to obtain multi-scale QR code feature representations; The structural information fusion module, through an attention mechanism, embeds key structural information such as positioning and timing patterns into the features output by the encoder, thereby enhancing the network's ability to perceive the structure of the QR code. The decoder module uses transposed convolutional layers to progressively restore the spatial resolution of the feature maps, outputting an initial repaired image I with the same size as the input. rec0 .
7. A QR code image restoration method according to claim 6, characterized in that, The convolutional layers of the encoder module employ ReLU activation and batch normalization; the attention weights of the structural information fusion module are based on the QR code structural mask M. s The spatial distribution is dynamically calculated; the output layer of the decoder module uses the Sigmoid activation function to map the feature values to the 0-1 interval to generate a binarized repair result.
8. The QR code image restoration method according to claim 1, characterized in that, The total loss function of the Q-GPN completion network L total for: , in, for Pixel loss; To perceive loss; To combat the losses; This is due to codeword consistency loss; These are the weighting coefficients.
9. A QR code image restoration method according to claim 1, characterized in that, The Q-GPN training of the completion network specifically includes: Constructing the training dataset: Collect standard QR code images of different versions and error correction levels as the basic sample library. For each basic sample, generate damaged QR code images by simulating the damage type in real-world scenarios, and retain the corresponding complete QR code images as the real labels. For each damaged sample, pre-generate its structural mask M. s This forms training data consisting of a triplet of damaged image, a structural mask, and a ground truth label. Initialize model parameters: Use the He normal distribution to initialize all learnable parameters of the Q-GPN encoder, structural information fusion module and decoder; Set training hyperparameters: Select the Adam optimizer, set the initial learning rate to 1e-4, and decay the learning rate to 10% of the initial value every 100 epochs using a cosine annealing strategy; set the batch size to 32, and the maximum number of training epochs to 500. Perform training iterations: In each training epoch, randomly sample several triplet data points, concatenate the damaged QR code image with the structural mask, and input the result into the Q-GPN to obtain the repaired output. Calculate the total loss function L between the output and the true label. total All parameters of the model are updated through backpropagation; Validation and model saving: Every 20 epochs, the model's repair success rate and average loss value are evaluated using an independent validation dataset. If the current model has the highest repair success rate and the smallest loss value on the validation set, the model parameters are saved as the optimal model. Model fine-tuning: After training, the optimal model is fine-tuned using a small number of scene-specific damage samples to further improve the model's repair performance in the target scene, based on the damage characteristics of the specific scene.
10. A QR code image restoration method according to claim 1, characterized in that, The preset maximum number of iterations N ranges from 3 to 5 times; and the marking information for manual review includes: the damage type of the QR code, the number of iterations for repair, and the distribution location map of the erroneous codewords.