Cigarette carton two-dimensional code-based order accurate identification and abnormity restoration system and method
By designing an order accurate identification and abnormal repair system based on the QR code of cigarettes, and using the error verification mechanism and a hybrid connectivity domain marking algorithm for image repair, the problem of information loss caused by wear and other reasons is solved, and the recognition success rate and system reliability are improved.
Patent Information
- Application Number
- CN202411733691.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-11-29
AI Technical Summary
Some information is lost due to wear, defilement, occlusion and other reasons, resulting in the identification algorithm based on fixed rules that cannot correctly extract the complete QR code information, reducing the recognition success rate.
An order accurate identification and abnormal repair system based on a cigarette QR code is designed, including an abnormality detection unit, an image processing unit and an image storage module. The error verification mechanism detects QR code abnormalities, and uses a hybrid connectivity domain marking algorithm and pixel-level, perceptual and adversarial loss functions to perform image repair to ensure that the repaired QR code has higher robustness and accuracy in the recognition and decoding process.
It effectively improves the success rate of QR code identification and the overall performance and reliability of the system, ensuring that accurate order identification can be achieved even if there are defects in QR codes.
Smart Images

Figure CN119670782A_ABST
Abstract
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 industries, information tracking from production, transportation to sales is achieved by equipping each cigarette with a unique QR code. This not only greatly improves the accuracy and efficiency of order processing, but also can quickly locate and solve problems such as data errors or physical damage that may occur, ensuring the transparency and reliability of the supply chain, thereby effectively preventing counterfeit and shoddy products from entering the market, and supporting more refined inventory management and market demand forecasting.
[0003] In practical applications, due to various reasons (such as wear, stain, etc.), some information of the QR code may be lost or damaged. If the QR code image loses some information due to wear, stain, occlusion or other reasons, 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 abnormal 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 recognition and abnormal repair based on cigarette strip 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 an order accurate identification and abnormality repair system based on cigarette QR codes, comprising:
[0006] An abnormality detection unit, wherein 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 abnormal signal and transmit it to the image processing unit;
[0007] An image processing unit, wherein the image processing unit is used to extract the image of the two-dimensional code when receiving the 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;
[0008] The image processing unit includes a preprocessing module, an image restoration module and an image storage module.
[0009] As a further improvement of the technical solution, in the anomaly detection unit, detecting whether the two-dimensional code is abnormal is based on an error checking mechanism, which is as follows:
[0010] S1. The user uses a scanning device to scan the QR code. The scanning device determines the position and direction 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, try to decode the data codeword, use the Reed-Solomon encoding algorithm, calculate the check code according to 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 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 ) is the 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 It means to shift the data polynomial 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, 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 the 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 area of the pre-processed two-dimensional code image according to the damaged area located by the abnormality detection unit, 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;
[0033] The image storage module is used to temporarily store the repaired image and delete it after the scheduling is completed.
[0034] As a further improvement of the technical solution, the image repair module detects the damaged area of the preprocessed two-dimensional code image as follows:
[0035] Use -1 to represent unlabeled feature pixels; traverse each pixel in the image, 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 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-check 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 relationship between the labels and use the union-find method to merge the two labels: 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, all equivalent labels are unified into one label L(x,y)=find(L(x,y)) according to the equivalence relationship 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 region image after labeling: the label array L is the connected region image I after labeling labeled ′.
[0051] As a further improvement of the technical solution, in S224, all pixels connected to the current pixel are marked using breadth-first search:
[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 the technical solution, the image repair module repairs the damaged area of the pre-processed two-dimensional 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 repaired 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; γ 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 which 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 the user 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 one of the above-mentioned systems for accurately identifying and repairing orders based on cigarette QR codes, and comprises the following steps:
[0068] 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 abnormal signal and transmit it to the image processing unit;
[0069] S10.2, after receiving the abnormal signal, the image processing unit pre-processes the image and transmits the pre-processed image to the image restoration module. After the restoration is completed, the image restoration module generates a feedback signal and transmits it 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 the user to rescan;
[0071] S10.4. When the user performs a second scan, the repaired two-dimensional code image stored in the scheduling image storage module is used 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 hybrid connected domain labeling algorithm is introduced for optimization, which not only clearly displays the independent connected parts in the original image, but also provides an accurate foundation for subsequent image repair work through effective segmentation and labeling of these areas. It can efficiently and accurately identify the various components in the QR code image, and can effectively handle even the defective or damaged parts.
[0074] 2. In the order accurate recognition and anomaly repair system and method based on cigarette QR codes, the combination of pixel-level loss, perceptual loss and adversarial loss 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 order accurate recognition and anomaly repair system. 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 be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0080] Embodiment 1:
[0081] See also Figure 1As shown, a system for accurate order recognition and abnormal repair based on cigarette QR codes is provided, including an abnormality detection unit 1 and an image processing unit 2. By integrating the abnormality detection unit 1 and the image processing unit 2, the function of intelligently identifying and repairing defective QR codes is realized. When the abnormality detection unit 1 finds that the QR code is abnormal during the scanning process, the image processing process will be triggered and received by the image processing unit 2, which includes 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, enhances the contrast and reduces the computational complexity; then, the image repair module 22 uses technologies such as the hybrid connected domain labeling algorithm to accurately locate and repair the damaged area, and evaluates the repair effect at the same time to ensure that the repaired image can be accurately read; after the repair is completed, the image will be temporarily stored in the image storage module 23 until the user tries to scan again, and the system will call the repaired image to complete the order recognition task. Once the recognition is successful, the relevant temporary data will be cleared to ensure the effective use of system resources. The entire process not only improves the success rate of QR code recognition, but also enhances the user experience of the system, 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, whether the QR code is abnormal is detected based on the error checking mechanism, which is as follows:
[0085] S1. The user uses a scanning device to scan the QR code. The scanning device determines the position and direction of the QR code through the positioning pattern and reads the format information; the error correction level and mask mode are read from the format information area near the positioning pattern. The format information is located next to the positioning patterns in the upper left corner, upper right corner, and lower left corner. Each position has two copies of the same information as a backup to increase reliability.
[0086] The position and orientation of the QR code are determined by locating the pattern, which allows the QR code to be accurately read even when it is tilted or partially blocked. Reading the format information, especially the error correction level and mask mode, provides the necessary parameters for subsequent decoding, ensuring the smooth progress of the decoding process. At the same time, multiple backups of the format information increase the robustness of the QR code. Even if a part is damaged, it can be restored through other backup information.
[0087] S2. Demasking the QR code according to the mask pattern in the format information to restore the original data codeword; the mask pattern is designed to prevent a large area of a single color from appearing in the QR code pattern, thereby affecting the correct recognition of the scanner. 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, the integrity of the QR code can be preliminarily determined by the error check code. The check code is calculated based on the read data codeword using the Reed-Solomon coding algorithm, and the calculated check code is compared with the check code stored in the QR code.
[0089] Trying to decode the data code can verify whether the information contained in the QR code is valid. Even if the decoding is not completely successful, the error check code can help determine the integrity of the QR code, which greatly enhances the fault tolerance of the system. The application of the Reed-Solomon encoding algorithm can correct errors to a certain extent, ensuring that even if the QR code is slightly damaged, it can be successfully read.
[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 erroneous 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 to 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 according to 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 correction 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. It 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 domain, i.e., a generator in the domain, whose power can generate all non-zero elements in the domain; 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 to shift the data polynomial left by t positions to leave space for the 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 the errors that may occur during transmission or storage;
[0101] Compute the syndrome, which is used to detect errors. If any S i If it is not zero, there is an error or the QR code is damaged:
[0102] S i =R(α i );
[0103] Among them, S i is the 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 is directly related to the maximum number of errors that can be corrected, t. Since Reed-Solomon coding can correct up to t errors, the number of syndromes calculated must be at least 2t to ensure that the location and value of up to t errors can be uniquely determined. Therefore, the value range of i is 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 determine the integrity of the QR code, promptly discover and handle anomalies, and ensure accurate recognition and decoding of the QR code.
[0108] The image processing unit 2 is used to extract the image of the two-dimensional code when receiving the abnormal signal, analyze and repair the extracted two-dimensional code image, introduce the 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;
[0109] The image processing unit 2 includes a preprocessing module 21, an image restoration module 22 and an image storage module 23;
[0110] In the image processing unit 2,
[0111] The preprocessing module 21 is used to perform preliminary processing on the abnormal two-dimensional code, 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 two-dimensional code image according to the damaged area located by the abnormality detection unit 1, and then evaluate the effect of the repair, generate a feedback signal after the repair is completed, and transmit the repaired image to the image storage module 23;
[0113] The image repair module 22 detects the damaged area of the pre-processed two-dimensional code image as follows:
[0114] Use -1 to represent unlabeled feature pixels; traverse each pixel in the image, 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] Input binary image I, where foreground pixels represent damaged areas or features that need attention, and background represents normal parts; label array L is used to record the connected domain number to which each pixel belongs, and is initially set to -1 to indicate that all pixels are unlabeled; and set lookup is used to efficiently manage the equivalence relationship between different labels, ensuring that even in complex image structures, areas belonging to the same connected domain but temporarily having different labels can be quickly and accurately merged. This setting is conducive to 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 relationship between the labels and use the union-find method to merge the two labels: union(L(x-1,y),L(x,y-1));
[0125] At this stage, each pixel in the image is preliminarily labeled and its neighbors above and to the left are checked to determine whether the current pixel should be assigned a new label or adopt the label of the adjacent labeled pixel. If two different labels are found, they are merged using a union-find to reflect that these pixels actually belong to the same connected domain. This method can effectively perform a preliminary division of the connected domain in the image and record the potential label equivalence relationship, laying a good foundation for subsequent refinement.
[0126] S223, second traversal:
[0127] For each pixel I(x,y), if I(x,y)=1, all equivalent labels are unified into one label L(x,y)=find(L(x,y)) according to the equivalence relationship table;
[0128] By using the equivalence relation table constructed previously, all equivalent labels are unified into one label, thus solving the problem of multiple labels that may be generated during one traversal. This not only simplifies the label system, but also ensures that the final connected domain label is accurate and consistent, which helps 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 the pixels to be processed. Initially, add the current pixel to the queue, take a pixel from the queue, access its 4 neighbors (upper, lower, left, and right). If the neighboring pixel is 1 and is not marked, assign the same label new_label and add the neighboring pixel to the queue.
[0133] For the foreground pixels that have not been marked, new labels are given, and all the pixels connected to them are recursively marked using a breadth-first search strategy. The breadth-first search method allows the entire connected component to be explored from any starting point, ensuring that no part belonging to the same area is missed. This method enhances the integrity of the connected domain labeling, allowing even damaged areas with complex shapes or irregular distributions to be fully identified.
[0134] S225, output the connected region image after labeling: the label array L is the connected region 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 area in the image. This fine segmentation result can be directly used to guide subsequent repair work, such as implementing targeted repair strategies for specific connected domains, thereby achieving higher quality image restoration. In addition, by analyzing the characteristics of the connected domain, it can also assist in determining the degree and type of damage, and then select the most appropriate repair algorithm to improve 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 based on the difference in pixel values, calculated by comparing the absolute difference between the repaired image and the original undamaged image. Its main goal is to ensure the consistency of color and brightness between the repaired part and the surrounding environment, so as to achieve basic visual matching. In QR code repair, pixel-level loss helps to restore the basic appearance of the image and make the 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 usually calculated by extracting feature maps from a pre-trained deep neural network, which measures the similarity between the repaired 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, which means that even in some cases the pixel values do not match exactly, as long as the repaired part matches the original image at a high-level feature, a lower perceptual loss can be obtained. Therefore, using perceptual loss in QR code repair can help preserve or restore important structural information, such as key positioning patterns and data encoding areas in QR codes.
[0145] Establishing adversarial loss function:
[0146]
[0147] Among them, L adversarialis the adversarial loss function, which is used to measure the similarity between the inpainted 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 inpainted image; I repaired The repaired 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 comes from the Generative Adversarial Network, which consists of two competing models: a generator that tries to create images that look real, and a discriminator that tries to distinguish between generated images and real images. The adversarial loss encourages the generator to generate images that are increasingly difficult for the discriminator to identify as fake, thereby improving the realism of the repaired image. In the QR code repair task, the adversarial loss helps generate more natural and realistic repair effects, making the repaired image more difficult to distinguish from the undamaged original image.
[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, thus ensuring the accuracy of the repair; the perceptual loss ensures that the repaired image is more visually natural and in line with human visual perception by extracting high-level features, enhancing the naturalness of the repair; the adversarial loss makes the repaired image more realistic and difficult to distinguish from the real image through adversarial training of the generative adversarial network. 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 higher robustness and accuracy during the recognition and decoding process, thereby improving the overall performance and reliability of the order precision recognition and abnormal 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 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.
[0155] This process ensures accurate order recognition through intelligent repair technology even if there are defects in the original QR code, while optimizing system resource management by timely cleaning temporary data. Such a mechanism not only improves the efficiency and accuracy of order processing, but also enhances the user experience of the system.
[0156] Embodiment 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 an abnormality in the QR code. If there is no abnormality, scan the QR code to identify the order. Otherwise, generate an abnormal signal and transmit it to the image processing unit 2.
[0159] 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 restoration module 22. After the restoration is completed, the image restoration module 22 generates a feedback signal and transmits it 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 the user to rescan;
[0161] S10.4. When the user performs a second scan, the repaired two-dimensional 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.
[0162] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited by the above embodiments, and the above embodiments and descriptions are only preferred examples of the present invention, and are not intended to limit the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, and these changes and improvements all fall within the scope of the present invention to be protected.
Claims
1. The order accurate identification and abnormal repair system based on cigarette QR code is characterized by: include: An abnormality detection unit (1), the 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), wherein the image processing unit (2) is used to extract the image of the two-dimensional code when receiving the 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) comprises a preprocessing module (21), an image restoration module (22) and an image storage module (23).
2. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 1 is characterized by: In the anomaly detection unit (1), whether the two-dimensional code is abnormal is detected based on an error checking mechanism, which is as follows: S1. The user uses a scanning device to scan the QR code. The scanning device determines the position and direction 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, try to decode the data codeword, use the Reed-Solomon encoding algorithm, calculate the check code according to 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 two-dimensional code, order recognition is performed; otherwise, an abnormal signal is generated and transmitted to the image processing unit (2).
3. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 2 is characterized by: In S3, the Reed-Solomon coding 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 two-dimensional 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 ) is the 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+d1 x+d2 x 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 It means to shift the data polynomial 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, there is an error or the QR code is damaged: S i =R(α i ); Among them, S i is a syndrome; i = 0, 1, ..., 2t-1; Damage location polynomial: Λ(x)=1+λ1 x+λ2 x 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 order accurate identification and abnormality repair system based on cigarette QR code according to claim 3 is characterized in that: In the image processing unit (2): The preprocessing module (21) is used to perform preliminary processing on the abnormal two-dimensional code, convert the color image into a grayscale image, 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, generate a feedback signal after the repair is completed, and transmit the repaired image 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.
5. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 4 is characterized by: The image repair module (22) detects the damaged area of the pre-processed two-dimensional code image 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 .
6. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 5 is characterized by: 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-check 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 relationship between the labels and use the union-find method to merge the two labels: union(L(x-1, y), L(x, y-1)); S223, second traversal: For each pixel I(x, y), if I(x, y) = 1, all equivalent labels are unified into one label L(x, y) = find(L(x, y)) according to the equivalence relationship 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 region image after labeling: the label array L is the connected region image I after labeling labeled ′.
7. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 6 is characterized by: In S224, all pixels connected to the current pixel are marked using breadth-first search: 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.
8. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 7 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 perxeptual 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 repaired 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; γ is the weight of the adversarial loss function.
9. The order accurate identification and abnormality repair system based on cigarette QR code according to claim 8 is characterized by: 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 the user to rescan. When the user performs a second scan, the repaired two-dimensional 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.
10. A method for accurately identifying and repairing orders based on cigarette cartons' two-dimensional codes, used in a system for accurately identifying and repairing orders based on cigarette cartons' two-dimensional codes as claimed in any one of claims 1 to 9, characterized in that: The steps include: 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 abnormal 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 two-dimensional 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
Error correcting method
JP2008084455A
Image analysis using a hybrid connected component labeling process
US20090309979A1
Cited By
Commodity full-link management system and method
CN121639224A
A commodity full-link management system and method
CN121639224B