Order precision identification and abnormality repair system and method based on cigarette QR code

By combining anomaly detection and Reed-Solomon coding algorithm with hybrid connected domain labeling algorithm and loss function optimization, the recognition failure problem caused by QR code wear and damage is solved, and efficient QR code repair and order recognition are achieved.

CN119670782BActive Publication Date: 2025-09-12CHINA NAT TOBACCO CORP HENAN PROVINCIAL CO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411733691.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-09-12
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

Existing QR code recognition technology cannot effectively extract complete information when the code is worn, stained or blocked, resulting in a reduced recognition success rate.

Method used

An anomaly detection unit is used to detect QR code anomalies, and the Reed-Solomon encoding algorithm is used to verify the integrity of the codeword. The hybrid connected domain labeling algorithm and the image repair module are combined to preprocess the QR code, detect damaged areas, and repair them. Pixel-level, perception-level, and adversarial loss functions are introduced to optimize the repair process.

Benefits of technology

The success rate and robustness of QR code recognition are improved, ensuring that the repaired QR code has higher accuracy and reliability during the recognition and decoding process, and improving the accuracy and efficiency of order processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119670782B_ABST
    Figure CN119670782B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image recognition technology, and more specifically, to a system and method for accurately identifying and repairing anomalies of orders based on cigarette strip QR codes. The system and method comprise: an anomaly detection unit for detecting whether there is an anomaly in the QR code when scanning the QR code; if there is no anomaly, the QR code is scanned to identify the order; otherwise, an anomaly signal is generated and transmitted to an image processing unit; the image processing unit extracts the image of the QR code, analyzes and repairs the extracted QR code image, and introduces a hybrid connected domain labeling algorithm for optimization in the process of analyzing and repairing the extracted QR code image. The system and method for accurately identifying and repairing anomalies of orders based on cigarette strip QR codes can efficiently and accurately identify the various components in the QR code image, which not only improves the quality of the QR code image repair, but also ensures that the repaired QR code has higher robustness and accuracy during the recognition and decoding process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image recognition technology, and in particular to a system and method for accurately identifying orders and repairing abnormalities based on cigarette QR codes. Background Art

[0002] With the rapid development of e-commerce and logistics, equipping each carton of cigarettes with a unique QR code enables information tracking throughout the entire process, from production to transportation and sales. This not only greatly improves the accuracy and efficiency of order processing, but also allows for the rapid identification and resolution of potential data errors or physical damage, ensuring supply chain transparency and reliability. This effectively prevents counterfeit and substandard products from entering the market and supports more refined inventory management and market demand forecasting.

[0003] In actual applications, due to various reasons (such as wear and tear, stains, etc.), some information in the QR code may be lost or damaged. If the QR code image loses some information due to wear, stains, occlusion or other reasons, then the recognition algorithm based on fixed rules may not be able to correctly extract the complete QR code information. Traditional recognition technology often relies on manually designed feature extractors such as edge detection, color and texture features. These methods are very sensitive to factors such as deformation, rotation, illumination changes and noise. Therefore, when the QR code image is affected by the above factors, the recognition success rate will be greatly reduced. Therefore, a system and method for accurate order recognition and abnormality repair based on cigarette QR codes are provided. Summary of the Invention

[0004] The purpose of the present invention is to provide a system and method for accurate order identification and abnormal repair based on cigarette QR codes, so as to solve the problem raised in the above background technology that if the QR code image loses part of its information due to wear, stain, occlusion or other reasons, then the recognition algorithm based on fixed rules may not be able to correctly extract the complete QR code information, which will greatly reduce the recognition success rate.

[0005] To achieve the above objectives, on the one hand, the present invention aims to provide a system for accurately identifying and fixing anomalies in orders based on cigarette QR codes, comprising:

[0006] An abnormality detection unit, the abnormality detection unit is used to detect whether there is an abnormality in the QR code when scanning the QR code, and if there is no abnormality, scan the QR code to identify the order; otherwise, generate an abnormality signal and transmit it to the image processing unit;

[0007] An image processing unit, configured to extract an image of the QR code upon receiving an abnormal signal, analyze and repair the extracted QR code image, introduce a hybrid connected domain labeling algorithm for optimization during the analysis and repair process of the extracted QR code image, and generate a feedback signal after the repair is completed that is transmitted to the abnormality detection unit;

[0008] The image processing unit includes a pre-processing module, an image restoration module and an image storage module.

[0009] As a further improvement of the present technical solution, in the anomaly detection unit, the detection of whether the QR code is abnormal is based on an error checking mechanism, specifically as follows:

[0010] S1. The user uses a scanning device to scan the QR code. The scanning device determines the position and orientation of the QR code by locating the pattern and reads the format information.

[0011] S2. Demasking the QR code according to the mask mode in the format information;

[0012] S3. Attempt to decode the data codeword, use the Reed-Solomon encoding algorithm, calculate a check code based on the read data codeword, and compare the calculated check code with the check code stored in the QR code;

[0013] S4. If the calculated verification code matches the verification code stored in the QR code, order recognition is performed; otherwise, an abnormal signal is generated and transmitted to the image processing unit.

[0014] As a further improvement of the present technical solution, in S3, the Reed-Solomon encoding algorithm is used to calculate the check code according to the read data codeword, and the calculated check code is compared with the check code stored in the QR code as follows:

[0015] Generator polynomial:

[0016] g(x)=(x-α 0 )(x-α 1 )…(x-α t-1 );

[0017] Among them, g(x) is the generating polynomial; α is the finite field GF(2 m ) primitive element; t is the maximum number of errors that can be corrected; x is a formal variable used to represent the polynomial;

[0018] D(x)=d0+d1x+d2x 2 +…+d k-1 x k-1 ;

[0019] C(x)=D(x)·x t +r(x);

[0020] Where D(x) is the original data polynomial; k is the length of the original data; d0, d1, ..., d k-1 are the coefficients of the polynomial D(x); C(x) is the encoded polynomial; x t Indicates that the data polynomial is shifted left by t bits; r(x) is the remainder polynomial;

[0021] Receive polynomial:

[0022] R(x)=C(x)+E(x);

[0023] Where R(x) is the received polynomial; E(x) is the error polynomial;

[0024] Calculate the syndrome, if any S i If it is not zero, it means there is an error or the QR code is damaged:

[0025] S i =R(α i );

[0026] Among them, S i is the syndrome; i=0,1,…,2t-1;

[0027] Damage location polynomial:

[0028] Λ(x)=1+λ1x+λ2x 2 +…+λ v x v ;

[0029] where Λ(x) is the damage location polynomial; v is the number of errors; λ1,λ2,…,λ v are the coefficients of the polynomial.

[0030] As a further improvement of this technical solution, in the image processing unit,

[0031] The preprocessing module is used to perform preliminary processing on abnormal QR codes and convert color images into grayscale images to reduce computational complexity and convert grayscale images into binary images;

[0032] The image repair module is used to detect and repair the damaged areas of the pre-processed QR code image based on the damaged areas located by the anomaly detection unit, and then evaluate the repair effect. After the repair is completed, a feedback signal is generated and the repaired image is transmitted to the image storage module;

[0033] The image storage module is used to temporarily store the repaired image and delete it after scheduling is completed.

[0034] As a further improvement of this technical solution, the image repair module detects damaged areas on the pre-processed QR code image, specifically as follows:

[0035] Use -1 to represent unlabeled feature pixels; traverse each pixel in the image, and if the current pixel is 1 and unlabeled, assign a new label; then use breadth-first search to label all pixels connected to the current pixel; finally output the labeled connected domain image I labeled .

[0036] As a further improvement of the present technical solution, in the image processing unit, a hybrid connected domain labeling algorithm is introduced to optimize the process of analyzing and repairing the extracted two-dimensional code image, as follows:

[0037] S221, Initialization:

[0038] Input binary image I, where the foreground pixels in the binary image are 1 and the background pixels are 0;

[0039] Initialize a label array L with the same size as the input image, and initialize all elements to -1, indicating that they are not labeled;

[0040] Initialize another union-find set;

[0041] S222, first traversal:

[0042] For each pixel I(x,y), if I(x,y)=1, check the pixels above and to the left:

[0043] If the pixels above and to the left are both 0, assign a new label L(x, y) = new_label and increment new_label.

[0044] If the pixel above or to the left is 1, assign the same label L(x,y)=min(L(x-1,y),L(x,y-1));

[0045] If the pixel labels above and to the left are different, record the equivalence between the labels and merge the two labels using union-find: union(L(x-1,y),L(x,y-1));

[0046] S223, second traversal:

[0047] For each pixel I(x,y), if I(x,y)=1, then all equivalent labels are unified into one label L(x,y)=find(L(x,y)) according to the equivalence relation table;

[0048] S224. Mark all pixels connected to the current pixel:

[0049] For each pixel I(x,y), if I(x,y) = 1 and L(x,y) = -1, assign a new label L(x,y) = new_label and increment new_label; and use breadth-first search to mark all pixels connected to the current pixel;

[0050] S225, output the connected area image after labeling: the label array L is the connected area image I after labeling labeled ′.

[0051] As a further improvement of the present technical solution, in S224, all pixels connected to the current pixel are marked using breadth-first search as follows:

[0052] Use a queue to store the pixels to be processed. Initially, add the current pixel to the queue, take a pixel from the queue, visit its four neighbors, and if the neighboring pixel is 1 and unlabeled, assign the same label new_label and add the neighboring pixel to the queue.

[0053] As a further improvement of this technical solution, the image repair module repairs the damaged area of ​​the pre-processed QR code image as follows:

[0054] Establish pixel-level loss function:

[0055]

[0056] Among them, L pixel is the pixel-level loss function; N is the total number of pixels in the image; I repaired (i) is the value of the i-th pixel in the repaired image; I true (i) is the value of the i-th pixel in the real image; is the square of the Euclidean distance;

[0057] Establish the perceptual loss function:

[0058]

[0059] Among them, I perceptual is the perceptual loss function; φ(I repaired (i)) is the feature representation of the repaired image obtained by the pre-trained feature extraction network; φ(I true (i)) is the feature representation of the real image obtained by the pre-trained feature extraction network; ||·||1 is the sum of absolute values;

[0060] Establishing adversarial loss function:

[0061]

[0062] Among them, L adversarial is the adversarial loss function; D is the discriminator network; I repaired The restored image generated by the generator; For all generated repair images I repaired expected value;

[0063] Total loss function:

[0064] L total =αL pixel +βL perceptual +γL adversarial ;

[0065] Among them, L total is the total loss function; α is the weight of the pixel-level loss function; β is the weight of the perceptual loss function; and γ is the weight of the adversarial loss function.

[0066] As a further improvement of the present technical solution, after the image repair module completes the repair, it generates a feedback signal that is transmitted to the abnormality detection unit. After receiving the feedback signal, the abnormality detection unit displays an error message to the user and prompts him to rescan. When the user performs a second scan, the repaired QR code image stored in the image storage module is scheduled to identify the order. After successful identification, a termination signal is sent to the image storage module, and the image storage module deletes the scheduled image.

[0067] On the other hand, the present invention provides a method for accurately identifying and repairing orders based on cigarette QR codes, which is used in any of the above-mentioned systems for accurately identifying and repairing orders based on cigarette QR codes, and includes the following steps:

[0068] S10.1. When scanning the QR code, detect whether there is any abnormality in the QR code. If there is no abnormality, scan the QR code to identify the order. Otherwise, generate an abnormality signal and transmit it to the image processing unit;

[0069] S10.2. After receiving the abnormality signal, the image processing unit pre-processes the image and transmits the pre-processed image to the image restoration module. After the restoration is complete, the image restoration module generates a feedback signal that is transmitted to the abnormality detection unit and temporarily stores the restored image in the image storage module.

[0070] S10.3. After receiving the feedback signal, the abnormality detection unit displays an error message to the user and prompts him to rescan.

[0071] S10.4. When the user performs a second scan, the repaired QR code image stored in the image storage module is scheduled to identify the order. After successful identification, a termination signal is sent to the image storage module, and the image storage module deletes the scheduled image.

[0072] Compared with the prior art, the present invention has the following beneficial effects:

[0073] 1. In the system and method for accurate order recognition and abnormal repair based on cigarette QR codes, the introduction of a hybrid connected domain labeling algorithm for optimization not only clearly displays the independent connected parts in the original image, but also provides a precise foundation for subsequent image repair work through the effective segmentation and labeling of these areas. It can efficiently and accurately identify the various components of the QR code image, and can effectively handle even defective or damaged parts.

[0074] 2. The system and method for accurate order recognition and anomaly repair based on cigarette QR codes combines pixel-level loss, perceptual loss, and adversarial loss, which not only improves the quality of QR code image repair, but also ensures that the repaired QR code has higher robustness and accuracy during the recognition and decoding process, thereby improving the overall performance and reliability of the system for accurate order recognition and anomaly repair. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] Figure 1 It is the overall flow chart of the present invention;

[0076] Figure 2 A flow chart of the overall method of the present invention;

[0077] The meaning of each number in the figure is:

[0078] 1. Abnormality detection unit; 2. Image processing unit; 21. Preprocessing module; 22. Image restoration module; 23. Image storage module. DETAILED DESCRIPTION

[0079] The following will provide a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making any creative efforts shall fall within the scope of protection of the present invention.

[0080] Example 1:

[0081] See also Figure 1As shown, a system for accurately identifying and repairing orders based on cigarette QR codes is provided, comprising an anomaly detection unit 1 and an image processing unit 2. By integrating the anomaly detection unit 1 and the image processing unit 2, the system achieves the function of intelligently identifying and repairing defective QR codes. When the anomaly detection unit 1 detects an anomaly in the QR code during scanning, it triggers the image processing process, which is received by the image processing unit 2. The image processing unit 2 comprises a preprocessing module 21, an image repair module 22, and an image storage module 23. The preprocessing module 21 first optimizes the quality of the original image, enhancing contrast and reducing computational complexity. Subsequently, the image repair module 22 uses techniques such as the hybrid connected domain labeling algorithm to accurately locate and repair damaged areas, while also evaluating the repair effect to ensure that the repaired image can be accurately read. After the repair is complete, the image is temporarily stored in the image storage module 23 until the user attempts to scan again, at which point the system will call the repaired image to complete the order recognition task. Once the recognition is successful, the relevant temporary data is cleared to ensure the efficient use of system resources. The entire process not only improves the success rate of QR code recognition, but also enhances the system's user experience, reduces operational interruptions caused by QR code damage, and improves data accuracy and efficiency in the tobacco product supply chain.

[0082] Specifically:

[0083] The abnormality detection unit 1 is used to detect whether there is an abnormality in the QR code when scanning the QR code. If there is no abnormality, the QR code is scanned to identify the order. Otherwise, an abnormality signal is generated and transmitted to the image processing unit 2;

[0084] In the anomaly detection unit 1, the detection of whether the QR code is abnormal is based on the error checking mechanism, which is as follows:

[0085] S1. The user scans the QR code with a scanning device. The scanning device uses the locator pattern to determine the position and orientation of the QR code and reads the format information. The error correction level and mask mode are read from the format information area near the locator pattern. The format information is located next to the locator pattern in the upper left, upper right, and lower left corners. Two copies of the same information are kept in each location as a backup to increase reliability.

[0086] The positioning pattern determines the position and orientation of the QR code, enabling accurate reading even when tilted or partially obscured. Reading format information, particularly the error correction level and masking mode, provides the necessary parameters for subsequent decoding, ensuring a smooth decoding process. Furthermore, multiple copies of format information enhance the robustness of the QR code, ensuring that even if a portion is damaged, it can be restored using other backups.

[0087] S2. Demasking the QR code based on the mask pattern in the format information to restore the original data codeword. The mask pattern is designed to prevent large areas of a single color from appearing in the QR code pattern, which could affect the scanner's correct recognition. Demasking ensures the originality and accuracy of the data and improves the readability of the QR code.

[0088] S3. Try to decode the data codeword. Even if the decoding is not completely successful, you can use the error check code to preliminarily determine the integrity of the QR code. Use the Reed-Solomon encoding algorithm to calculate the check code based on the read data codeword, and compare the calculated check code with the check code stored in the QR code.

[0089] Attempting to decode the data code verifies the validity of the information contained in the QR code. Even if decoding is not completely successful, the error-checking code can help determine the integrity of the QR code, significantly enhancing the system's fault tolerance. The application of the Reed-Solomon encoding algorithm can correct errors to a certain extent, ensuring successful reading even of slightly damaged QR codes.

[0090] S4. If the calculated verification code matches the verification code stored in the QR code, order recognition is performed; otherwise, an abnormal signal is generated, indicating that the QR code is incorrect or damaged, and the abnormal signal is transmitted to the image processing unit 2; this helps to improve the accuracy of recognition and can also promptly detect and handle abnormal situations, such as errors or damage in the QR code, which is crucial for maintaining the normal operation of the system and improving user experience.

[0091] In S3, the Reed-Solomon encoding algorithm is used to calculate the check code based on the read data codeword, and the calculated check code is compared with the check code stored in the QR code as follows:

[0092] The polynomial is used to generate redundant error-correcting codes to ensure that errors can be detected and corrected during data transmission or storage:

[0093] g(x)=(x-α 0 )(x-α 1 )…(x-α t-1 );

[0094] Among them, g(x) is the generating polynomial, which is a t-degree polynomial used to generate error correction code; x is a formal variable used to represent the polynomial, which does not represent a specific value, but is used to construct a mathematical model of information data and check code; α is the finite field GF(2 m ) is a primitive element in the field, that is, a generator in the field, whose power can generate all non-zero elements in the field; t is the maximum number of errors that can be corrected, for example, if t = 2, then at most 2 errors can be corrected;

[0095] D(x)=d0+d1x+d2x 2 +…+d k-1 x k-1 ;

[0096] C(x)=D(x)·x t +r(x);

[0097] Where D(x) is the original data polynomial, which represents the data to be encoded; k is the length of the original data; d0, d1, ..., d k-1 are the coefficients of the polynomial D(x); C(x) is the encoded polynomial, which contains the original data and the redundant error correction code; x t It means that the data polynomial is shifted left by t bits to leave space for redundant code; r(x) is the remainder polynomial, which is D(x)·x t The remainder after dividing by the generating polynomial g(x) is used to generate a redundant error correction code;

[0098] Receive polynomial:

[0099] R(x)=C(x)+E(x);

[0100] Where R(x) is the received polynomial, which may contain errors; E(x) is the error polynomial, which represents errors that may occur during transmission or storage.

[0101] Compute the syndrome, used to detect errors, if any S i If it is not zero, it means there is an error or the QR code is damaged:

[0102] S i =R(α i );

[0103] Among them, S i is a syndrome, which is a vector of length 2t, used to detect errors; i = 0, 1, ..., 2t-1; in the Reed-Solomon coding algorithm, the syndrome S i The number of i is directly related to the maximum number of errors that can be corrected, t. Since Reed-Solomon codes can correct up to t errors, the number of syndromes computed must be at least 2t to ensure that the locations and values ​​of up to t errors can be uniquely determined. Therefore, the value of i ranges from 0 to 2t-1, which can generate enough syndromes to detect and locate errors.

[0104] Damage location polynomial:

[0105] Λ(x)=1+λ1x+λ2x 2 +…+λ v x v ;

[0106] Where Λ(x) is the damage location polynomial used to determine the location of the error; v is the number of errors, that is, the degree of the polynomial; λ1,λ2,…,λ v are the coefficients of the polynomial;

[0107] In this way, the anomaly detection unit 1 can utilize the built-in error checking mechanism of the QR code to preliminarily judge the integrity of the QR code, promptly discover and handle anomalies, and ensure accurate recognition and decoding of the QR code.

[0108] Image processing unit 2, which is used to extract the image of the QR code when receiving the abnormal signal, analyze and repair the extracted QR code image, introduce a hybrid connected domain labeling algorithm to optimize the analysis and repair process of the extracted QR code image, and generate a feedback signal after the repair is completed and transmit it to the abnormality detection unit 1;

[0109] The image processing unit 2 includes a pre-processing module 21, an image restoration module 22 and an image storage module 23;

[0110] In the image processing unit 2,

[0111] The pre-processing module 21 is used to perform preliminary processing on abnormal QR codes, such as removing background noise, adjusting contrast and brightness, etc., to improve the effect of subsequent processing steps; and converting color images into grayscale images to reduce computational complexity, and converting grayscale images into binary images to enhance contrast;

[0112] The image repair module 22 is used to detect and repair the damaged area of ​​the pre-processed QR code image according to the damaged area located by the anomaly detection unit 1, and then evaluate the repair effect. After the repair is completed, a feedback signal is generated and the repaired image is transmitted to the image storage module 23;

[0113] The image repair module 22 detects damaged areas on the pre-processed QR code image as follows:

[0114] Use -1 to represent unlabeled feature pixels; traverse each pixel in the image, and if the current pixel is 1 and unlabeled, assign a new label; then use breadth-first search to label all pixels connected to the current pixel; finally output the labeled connected domain image I labeled .

[0115] In the image processing unit 2, a hybrid connected domain labeling algorithm is introduced to optimize the process of analyzing and repairing the extracted two-dimensional code image, as follows: S221, initialization:

[0116] Input binary image I, where the foreground pixels in the binary image are 1 and the background pixels are 0;

[0117] Initialize a label array L with the same size as the input image, and initialize all elements to -1, indicating that they are not labeled;

[0118] Initialize a union-find set to record the equivalence relationship between labels;

[0119] The input is a binary image I, where foreground pixels represent damaged areas or features of interest, and the background represents normal areas. The label array L is used to record the connected domain number of each pixel, initially set to -1 to indicate that all pixels are unlabeled. The parallel lookup function is used to efficiently manage the equivalence relationship between different labels, ensuring that even in complex image structures, regions belonging to the same connected domain but temporarily having different labels can be quickly and accurately merged. This setting facilitates the subsequent accurate identification and processing of damaged areas.

[0120] S222, first traversal:

[0121] For each pixel I(x,y), if I(x,y)=1, check the pixels above and to the left:

[0122] If the pixels above and to the left are both 0, assign a new label L(x, y) = new_label and increment new_label.

[0123] If the pixel above or to the left is 1, assign the same label L(x,y)=min(L(x-1,y),L(x,y-1));

[0124] If the pixel labels above and to the left are different, record the equivalence between the labels and merge the two labels using union-find: union(L(x-1,y),L(x,y-1));

[0125] In this phase, each pixel in the image is initially labeled and its neighbors above and to the left are examined to determine whether the pixel should be assigned a new label or adopt the label of an already labeled neighbor. If two different labels are found, they are merged using a union-find algorithm to reflect that the pixels belong to the same connected domain. This method effectively performs a preliminary partitioning of connected domains in the image while simultaneously recording potential label equivalence relationships, laying a solid foundation for subsequent refinement.

[0126] S223, second traversal:

[0127] For each pixel I(x,y), if I(x,y)=1, then all equivalent labels are unified into one label L(x,y)=find(L(x,y)) according to the equivalence relation table;

[0128] By using the previously constructed equivalence table, all equivalent labels are unified into a single label, thus resolving the issue of multiple labels that may be generated during a single traversal. This not only simplifies the labeling system but also ensures that the resulting connected domain labels are accurate and consistent, helping to improve the accuracy of QR code damaged area detection.

[0129] S224. Mark all pixels connected to the current pixel:

[0130] For each pixel I(x,y), if I(x,y) = 1 and L(x,y) = -1, assign a new label L(x,y) = new_label and increment new_label; and use breadth-first search to mark all pixels connected to the current pixel;

[0131] In S224, all pixels connected to the current pixel are marked using breadth-first search:

[0132] Use a queue to store pixels to be processed. Initially, add the current pixel to the queue, take a pixel from the queue, and access its four neighbors (upper, lower, left, and right). If the neighboring pixel is 1 and unlabeled, assign the same label new_label and add the neighboring pixel to the queue.

[0133] Foreground pixels that have not yet been labeled are given new labels, and a breadth-first search strategy is used to recursively label all connected pixels. This breadth-first search allows the entire connected component to be explored from any starting point, ensuring that no parts belonging to the same region are missed. This method enhances the completeness of the connected component labeling, allowing even complex or irregularly distributed damaged areas to be fully identified.

[0134] S225, output the connected area image after labeling: the label array L is the connected area image I after labeling labeled ';

[0135] After the above steps, the label array L is converted into the labeled connected domain image I labeled ', clearly showing each independent connected region in the image. This refined segmentation result can directly guide subsequent restoration work, such as implementing targeted restoration strategies for specific connected domains, thereby achieving higher-quality image restoration. Furthermore, by analyzing the characteristics of connected domains, it can also assist in determining the extent and type of damage, thereby selecting the most appropriate restoration algorithm and improving the efficiency and accuracy of the overall system.

[0136] The image repair module 22 repairs the damaged area of ​​the pre-processed two-dimensional code image as follows:

[0137] Establish pixel-level loss function:

[0138]

[0139] Among them, L pixel is a pixel-level loss function used to measure the pixel difference between the restored image and the real image; N is the total number of pixels in the image; I repaired (i) is the value of the i-th pixel in the repaired image; I true (i) is the value of the i-th pixel in the real image; is the square of the Euclidean distance;

[0140] Pixel-level loss is a direct measure of pixel value differences, calculated by comparing the absolute difference between the restored image and the original, undamaged image. Its primary goal is to ensure color and brightness consistency between the repaired portion and its surroundings, thereby achieving basic visual matching. In QR code repair, pixel-level loss helps restore the image's basic appearance, making low-level features such as color and texture of the repaired area as close to the original image as possible.

[0141] Establish the perceptual loss function:

[0142]

[0143] Among them, I perceptual is the perceptual loss function, which is used to measure the difference between the restored image and the real image in the feature space; φ(I repaired (i)) is the feature representation of the repaired image obtained by the pre-trained feature extraction network; φ(I true (i)) is the feature representation of the real image obtained by the pre-trained feature extraction network; ||·||1 is the sum of absolute values;

[0144] Perceptual loss is typically calculated using feature maps extracted from a pre-trained deep neural network. It measures the similarity between the inpainted image and the reference image at a higher level. Perceptual loss focuses on the semantic information of the image content rather than simple pixel values. This means that even in some cases where pixel values ​​don't exactly match, as long as the inpainted part matches the original image at a high-level, a lower perceptual loss is achieved. Therefore, using perceptual loss in QR code inpainting can help preserve or recover important structural information, such as key positioning patterns and data encoding areas within the QR code.

[0145] Establishing adversarial loss function:

[0146]

[0147] Among them, L adversarialis the adversarial loss function, which is used to measure the similarity between the repaired image generated by the generator and the real image in the discriminator; D is the discriminator network, which is used to distinguish the real image from the generated repaired image; I repaired The restored image generated by the generator; For all generated repair images I repaired In practical applications, this expected value can be approximated by calculating the average value of all samples in a batch;

[0148] Adversarial loss originates from generative adversarial networks, which consist of two competing models: a generator that attempts to create realistic-looking images, and a discriminator that attempts to distinguish between generated images and real ones. The adversarial loss encourages the generator to produce images that are increasingly difficult for the discriminator to identify as fake, thereby improving the realism of the inpainted image. In the QR code inpainting task, the adversarial loss helps generate more natural and realistic inpainting effects, making the inpainted image more difficult to distinguish from the undamaged original.

[0149] Total loss function:

[0150] L total =αL pixel +βL perceptual +γL adversarial ;

[0151] Among them, L total is the total loss function, which combines pixel-level loss, perceptual loss, and adversarial loss; α is the weight of the pixel-level loss function; β is the weight of the perceptual loss function; γ is the weight of the adversarial loss function;

[0152] Specifically, the pixel-level loss ensures that the repaired QR code image is as close to the original image as possible at the pixel level, thereby ensuring the accuracy of the repair. The perceptual loss extracts high-level features to ensure that the repaired image is visually more natural and consistent with human visual perception, enhancing the naturalness of the repair. The adversarial loss, through adversarial training of a generative adversarial network, makes the repaired image more realistic and difficult to distinguish from the real image. The combination of these three loss functions not only improves the quality of QR code image repair, but also ensures that the repaired QR code has greater robustness and accuracy during the recognition and decoding process, thereby improving the overall performance and reliability of the order precision identification and anomaly repair system.

[0153] The image storage module 23 is used to temporarily store the restored image and delete it after the scheduling is completed;

[0154] After the image repair module 22 completes the repair, it generates a feedback signal and transmits it to the abnormality detection unit 1. After receiving the feedback signal, the abnormality detection unit 1 displays an error message to the user and prompts him to rescan. When the user performs a second scan, the repaired QR code image stored in the scheduling image storage module 23 is used to identify the order. After successful identification, a termination signal is sent to the image storage module 23, and the image storage module 23 deletes the scheduled image.

[0155] This process ensures accurate order recognition even if the original QR code has defects through intelligent repair technology, while also optimizing system resource management by promptly clearing temporary data. This mechanism not only improves the efficiency and accuracy of order processing, but also enhances the system's user experience.

[0156] Example 2:

[0157] See also Figure 2 As shown, a method for accurately identifying and repairing orders based on cigarette QR codes is provided, which is used in any of the above-mentioned systems for accurately identifying and repairing orders based on cigarette QR codes, and includes the following steps:

[0158] S10.1. When scanning the QR code, detect whether there is any abnormality in the QR code. If there is no abnormality, scan the QR code to identify the order. Otherwise, generate an abnormality signal and transmit it to image processing unit 2;

[0159] S10.2. After receiving the abnormality signal, the image processing unit 2 pre-processes the image and transmits the pre-processed image to the image restoration module 22. After the restoration is complete, the image restoration module 22 generates a feedback signal that is transmitted to the abnormality detection unit 1 and temporarily stores the restored image in the image storage module 23.

[0160] S10.3. After receiving the feedback signal, the abnormality detection unit 1 displays an error message to the user and prompts him to rescan.

[0161] S10.4. When the user performs a second scan, the repaired QR code image stored in the image storage module 23 is scheduled to identify the order. After successful identification, a termination signal is sent to the image storage module 23, and the image storage module 23 deletes the scheduled image.

[0162] The basic principles, main features, and advantages of the present invention are shown and described above. It should be understood by those skilled in the art that the present invention is not limited to the above-described embodiments. The above-described embodiments and descriptions are merely preferred examples of the present invention and are not intended to limit the present invention. Various changes and modifications may be made to the present invention without departing from the spirit and scope of the present invention, and such changes and modifications fall within the scope of the invention claimed.

Claims

1. The order precision identification and abnormality repair system based on cigarette QR code is characterized by: include: An abnormality detection unit (1) is used to detect whether there is an abnormality in the QR code when scanning the QR code, and if there is no abnormality, scan the QR code to identify the order; otherwise, generate an abnormality signal and transmit it to the image processing unit (2); An image processing unit (2) is used to extract an image of the two-dimensional code when receiving an abnormal signal, analyze and repair the extracted two-dimensional code image, introduce a hybrid connected domain labeling algorithm to optimize the analysis and repair process of the extracted two-dimensional code image, and generate a feedback signal after the repair is completed and transmit it to the abnormality detection unit (1); The image processing unit (2) includes a pre-processing module (21), an image restoration module (22) and an image storage module (23); In the image processing unit (2): The pre-processing module (21) is used to perform preliminary processing on the abnormal two-dimensional code and convert the color image into a grayscale image to reduce the computational complexity and convert the grayscale image into a binary image; The image repair module (22) is used to detect and repair the damaged area of ​​the pre-processed two-dimensional code image according to the damaged area located by the abnormality detection unit (1), and then evaluate the effect of the repair. After the repair is completed, a feedback signal is generated and the repaired image is transmitted to the image storage module (23); The image storage module (23) is used to temporarily store the restored image and delete it after the scheduling is completed; In the image processing unit (2), a hybrid connected domain labeling algorithm is introduced to optimize the process of analyzing and repairing the extracted two-dimensional code image, as follows: S221, Initialization: Input binary image I, where the foreground pixels in the binary image are 1 and the background pixels are 0; Initialize a label array L with the same size as the input image, and initialize all elements to -1, indicating that they are not labeled; Initialize another union-find set; S222, first traversal: For each pixel I(x,y), if I(x,y)=1, check the pixels above and to the left: If the pixels above and to the left are both 0, assign a new label L(x, y) = new_label and increment new_label. If the pixel above or to the left is 1, assign the same label L(x,y)=min(L(x-1,y),L(x,y-1)); If the pixel labels above and to the left are different, record the equivalence between the labels and merge the two labels using union-find: union(L(x-1,y),L(x,y-1)); S223, second traversal: For each pixel I(x,y), if I(x,y)=1, then all equivalent labels are unified into one label L(x,y)=find(L(x,y)) according to the equivalence relation table; S224. Mark all pixels connected to the current pixel: For each pixel I(x,y), if I(x,y) = 1 and L(x,y) = -1, assign a new label L(x,y) = new_label and increment new_label; and use breadth-first search to mark all pixels connected to the current pixel; S225, output the connected area image after labeling: the label array L is the connected area image I after labeling labeled '; In S224, the breadth-first search is used to mark all pixels connected to the current pixel as follows: Use a queue to store the pixels to be processed. Initially, add the current pixel to the queue, take a pixel from the queue, visit its four neighbors, and if the neighboring pixel is 1 and unlabeled, assign the same label new_label and add the neighboring pixel to the queue.

2. The system for accurately identifying and fixing cigarette orders based on QR codes according to claim 1 is characterized by: In the anomaly detection unit (1), whether the QR code is abnormal is detected based on an error checking mechanism, specifically as follows: S1. The user uses a scanning device to scan the QR code. The scanning device determines the position and orientation of the QR code by locating the pattern and reads the format information. S2. Demasking the QR code according to the mask mode in the format information; S3. Attempt to decode the data codeword, use the Reed-Solomon encoding algorithm, calculate a check code based on the read data codeword, and compare the calculated check code with the check code stored in the QR code; S4. If the calculated verification code matches the verification code stored in the QR code, order recognition is performed; otherwise, an abnormal signal is generated and transmitted to the image processing unit (2).

3. The system for accurately identifying and fixing cigarette orders based on QR codes according to claim 2 is characterized by: In S3, the Reed-Solomon encoding algorithm is used to calculate the check code according to the read data codeword, and the calculated check code is compared with the check code stored in the QR code as follows: Generator polynomial: g(x)=(x-α 0 )(x-a 1 )…(x-a t-1 ); Among them, g(x) is the generating polynomial; α is the finite field GF(2 m ) primitive element; t is the maximum number of errors that can be corrected; x is a formal variable used to represent the polynomial; D(x)=d0+d1x+d2x 2 +…+d k-1 x k-1 ; C(x)=D(x)·x t +r(x); Where D(x) is the original data polynomial; k is the length of the original data; d0, d1, ..., d k-1 are the coefficients of the polynomial D(x); C(x) is the encoded polynomial; x t Indicates that the data polynomial is shifted left by t bits; r(x) is the remainder polynomial; Receive polynomial: R(x)=C(x)+E(x); Where R(x) is the received polynomial; E(x) is the error polynomial; Calculate the syndrome, if any S i If it is not zero, it means there is an error or the QR code is damaged: S i =R(α i ); Among them, S i is the syndrome; i=0,1,…,2t-1; Damage location polynomial: Λ(x)=1+λ1x+λ2x 2 +…+l v x v ; where Λ(x) is the damage location polynomial; v is the number of errors; λ1,λ2,…,λ v are the coefficients of the polynomial.

4. The system for accurately identifying and fixing cigarette orders based on QR codes according to claim 3 is characterized by: The image repair module (22) detects damaged areas on the pre-processed two-dimensional code image, specifically as follows: Use -1 to represent unlabeled feature pixels; traverse each pixel in the image, and if the current pixel is 1 and unlabeled, assign a new label; Then use breadth-first search to mark all pixels connected to the current pixel; finally output the marked connected domain image I labeled .

5. The system for accurate order identification and abnormality repair based on cigarette QR codes according to claim 4 is characterized by: The image repair module (22) repairs the damaged area of ​​the pre-processed two-dimensional code image as follows: Establish pixel-level loss function: Among them, L pixel is the pixel-level loss function; N is the total number of pixels in the image; I repaired (i) is the value of the i-th pixel in the repaired image; I true (i) is the value of the i-th pixel in the real image; is the square of the Euclidean distance; Establish the perceptual loss function: Among them, L perceptual is the perceptual loss function; φ(I repaired (i)) is the feature representation of the repaired image obtained by the pre-trained feature extraction network; φ(I true (i)) is the feature representation of the real image obtained by the pre-trained feature extraction network; ||·||1 is the sum of absolute values; Establishing adversarial loss function: Among them, L adversarial is the adversarial loss function; D is the discriminator network; I repaired The restored image generated by the generator; For all generated repair images I repaired expected value; Total loss function: L total =αL pixel +βL perceptual +γL adversarial ; Among them, L total is the total loss function; α is the weight of the pixel-level loss function; β is the weight of the perceptual loss function; and γ is the weight of the adversarial loss function.

6. The system for accurately identifying and fixing cigarette orders based on QR codes according to claim 5 is characterized by: After the image repair module (22) completes the repair, it generates a feedback signal that is transmitted to the abnormality detection unit (1). After receiving the feedback signal, the abnormality detection unit (1) displays an error message to the user and prompts the user to rescan. When the user performs a second scan, the repaired QR code image stored in the scheduling image storage module (23) is used to identify the order. After successful identification, a termination signal is sent to the image storage module (23), and the image storage module (23) deletes the scheduled image.

7. A method for accurately identifying and repairing orders based on cigarette QR codes, used in a system for accurately identifying and repairing orders based on cigarette QR codes as claimed in any one of claims 1 to 6, characterized in that: The steps include: S10.

1. When scanning the QR code, detect whether there is an abnormality in the QR code. If there is no abnormality, scan the QR code to identify the order. Otherwise, generate an abnormality signal and transmit it to the image processing unit (2); S10.2, after receiving the abnormal signal, the image processing unit (2) pre-processes the image and transmits the pre-processed image to the image repair module (22); after the image repair module (22) completes the repair, it generates a feedback signal and transmits it to the abnormality detection unit (1), and temporarily stores the repaired image in the image storage module (23); S10.3, after receiving the feedback signal, the abnormality detection unit (1) displays an error message to the user and prompts the user to rescan; S10.

4. When the user performs a second scan, the repaired QR code image stored in the scheduling image storage module (23) is used to identify the order. After successful identification, a termination signal is sent to the image storage module (23), and the image storage module (23) deletes the scheduled image.

Citation Information

Patent Citations

  • Low-quality two-dimensional code information extraction method and device based on run length coding

    CN112069852A

  • Two-dimensional code appearance defect detection method and two-dimensional code appearance defect detection device

    CN118247211A