Method and system for detecting defects in a screening barcode based on visual images
Patent Information
- Application Number
- CN202610877734.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-17
- Publication Date
- 2026-09-11
AI Technical Summary
然而,现有基于图像生成的检测方法仍然存在一些不足之处:首先,通用的生成模型(如变分自编码器VAE)在设计上侧重于建立多模态、高不确定性的数据分布,将其直接应用于具有低熵、强结构、高对比度特性的条码图像时,会出现潜层空间被压缩、信息丢失以及重构结果趋于平均化的问题,导致对条码细微缺陷的检测能力不足;其次,现有方法通常仅依赖输入图像与重构图像之间的简单重构误差(如像素级均方误差MSE)来判定缺陷,其筛选阈值设定主观且敏感,难以在实际生产中平衡漏检率和误检率,稳定性不佳
本发明采用无监督学习方法,在训练阶段仅需使用正常条码样本,无需收集各类缺陷样本,也无需进行任何像素级的缺陷标注,从根本上解决了工业场景中缺陷样本获取困难、类型分布不均、标注成本高昂且一致性差的痛点;模型在训练时仅学习正常样本的数据分布与生成模式,在推理阶段,任何偏离该分布的数据都会导致高重构误差而被有效检出;当条码的印刷工艺、视觉结构或成像条件发生变更时,仅需重新采集好品样本进行模型训练即可完成系统迁移,无需重新定义缺陷规则或人工调试检测参数,显著降低了系统维护成本和部署周期;
Smart Images

Figure CN122737014A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of barcode defect detection technology, and in particular to a barcode defect detection method and system based on visual image generation and screening. Background Technology
[0002] In the industrial printing process, barcodes serve as a key carrier for product traceability and information management, making surface quality inspection crucial. Traditional barcode defect detection methods mainly fall into two categories: algorithms based on traditional image processing and detection methods based on deep learning.
[0003] Traditional image processing algorithms (such as thresholding, projection analysis, blob analysis, and bar-space structure analysis) are effective in specific scenarios. However, these methods typically rely on simplistic assumptions and extensive manual adjustments. Their detection parameters are highly sensitive to lighting conditions, printing processes, image quality, and material variations, resulting in poor generalization ability. A production workshop often needs to set multiple sets of detection parameters for different production lines or products. When new defect types emerge or the imaging environment changes, traditional algorithms are prone to failure and struggle to adapt quickly. Furthermore, under high-precision detection requirements, balancing missed and false detections of minute defects is extremely difficult in parameter setting, making it hard to meet the stability requirements of industrial production.
[0004] Deep learning-based methods, especially generative models such as convolutional autoencoders (CAEs), have provided new approaches for unsupervised or self-supervised defect detection. However, existing image generation-based detection methods still have some shortcomings: First, general generative models (such as variational autoencoders, VAEs) are designed to establish multimodal, high-uncertainty data distributions. When directly applied to barcode images with low entropy, strong structure, and high contrast characteristics, problems such as compression of latent space, information loss, and the tendency of reconstruction results to become averaged occur, resulting in insufficient detection capability for subtle defects in barcodes. Second, existing methods usually rely solely on the simple reconstruction error (such as pixel-level mean square error, MSE) between the input image and the reconstructed image to determine defects. The setting of the screening threshold is subjective and sensitive, making it difficult to balance the false negative rate and false positive rate in actual production, resulting in poor stability.
[0005] Therefore, how to provide a barcode defect detection method that can maintain high sensitivity to minor defects in barcodes, adapt to complex and ever-changing industrial scenarios, and have stable and controllable detection performance is a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] The technical problem to be solved by the present invention is: in order to overcome the defects of the prior art, the present invention provides a barcode defect detection method and system based on visual image generation and screening, which combines an improved convolutional autoencoder image generation network with traditional image processing algorithms to improve the detection capability and versatility of online barcode defect detection.
[0007] The technical solution adopted by this invention to solve its technical problem is: a barcode defect detection method based on visual image generation and screening, characterized by comprising the following steps: S1. Obtain the barcode image to be detected and preprocess it to generate a standard barcode image that meets the model input requirements; S2. Input the standard barcode image into an improved convolutional autoencoder BarCode-CAE model to generate a reconstructed image; calculate the composite anomaly score between the standard barcode image and the reconstructed image. ; S3, Combined outlier scores The image is compared with a dynamic threshold T obtained through statistical modeling to classify the barcode image to be detected as a high-confidence good product, a high-confidence bad product, or a sample to be determined. S4. For undetermined samples, obtain the corresponding non-standard barcode image and use a defect detection module based on traditional image processing algorithms for secondary detection to finally determine its attributes.
[0008] By employing a collaborative architecture that combines generative network coarse screening with traditional algorithm fine judgment, efficient and stable detection of barcode defects can be achieved.
[0009] Furthermore, the BarCode-CAE model in S2 includes an encoder and a decoder. The encoder is used to extract low-dimensional latent features from a normal barcode image, and the decoder is used to reconstruct the image from the low-dimensional latent features. The encoder and decoder are jointly trained end-to-end by minimizing the loss function L.
[0010] The encoder is responsible for learning the normal pattern of a normal barcode, and the decoder is used to reconstruct the image from the compressed features. Through end-to-end joint training, the model is able to reconstruct normal samples well, but has difficulty reconstructing defective samples, so as to achieve defect detection.
[0011] Furthermore, the expression for the loss function L is: , , in, Standard input image for barcode With reconstructed image The pixel reconstruction loss term is the mean squared error between the two sides. To minimize the variance of pixel values in each column of the reconstructed image and constrain the horizontal consistency of pixel distribution, a horizontal consistency loss term is used. This is a vertical edge enhancement loss term that enhances the vertical edge strength of the reconstructed image by convolving the Sobel vertical edge detection kernel with the image. and These are the preset weighting coefficients.
[0012] By introducing horizontal consistency loss and vertical edge enhancement loss By incorporating the low-entropy and strong-structure prior knowledge of barcodes into the model, the problem of the general generative model tending to be averaged and the indivisibility of subtle defects can be solved.
[0013] Furthermore, the composite anomaly score in S2 The calculation formula is: , in, The value is obtained by performing a sliding window calculation on the residual image between the standard barcode image and the reconstructed image, and taking the maximum value among all windows; The structural similarity index between the input image and the reconstructed image; and These are the preset weighting coefficients.
[0014] The combination of weighted sliding window local MSE and global SSIM can more comprehensively measure reconstruction quality compared to single pixel error.
[0015] Furthermore, the method for generating the dynamic threshold T in S3 is as follows: During the training or validation phase of the BarCode-CAE model, collect composite anomaly scores for all normal sample images. The mean of a Gaussian distribution is obtained by fitting it with the maximum likelihood estimation method. and standard deviation The dynamic threshold was calculated based on statistical rules. , where k is a coefficient preset according to the desired detection sensitivity.
[0016] Fit a Gaussian distribution using the outlier scores of a large number of normal samples, and then... The principle of threshold calculation makes the defect judgment threshold statistically based and scenario-adaptive, solving the problems of subjective, sensitive, and difficult-to-balance missed and false detections in traditional methods.
[0017] Furthermore, the specific classification of the barcode images to be detected in S3 is as follows: If the composite anomaly score of the barcode image to be detected If so, it is classified as a high-confidence good product; If the composite anomaly score of the barcode image to be detected If so, it is classified as a high-confidence defective product; If the composite anomaly score of the barcode image to be detected If so, it is classified as an undetermined sample; in, and These are the upper and lower threshold floating parameters for classifying good and bad products, respectively.
[0018] By setting and Two boundaries are used to divide the detection results into high-confidence good products, high-confidence bad products, and undetermined samples, so that only samples that the model is uncertain will enter the secondary detection of the traditional algorithm, thus optimizing the balance between efficiency and accuracy.
[0019] Furthermore, the defect detection module in S4, based on traditional image processing algorithms, performs the following operations: First, threshold segmentation is performed to separate the bar regions and empty regions of the barcode; then, blob analysis is performed on individual bars and / or empty regions to detect width anomalies; finally, subtle defects are detected in the bar regions and empty regions through dynamic threshold segmentation.
[0020] Furthermore, the non-standard barcode image used in the secondary detection step of S4 refers to a segmented barcode image that has undergone coarse positioning, fine positioning, and alignment operations, but has not undergone contrast enhancement and scaling processing.
[0021] This ensures that traditional algorithms can perform accurate geometric and texture analysis based on the original image information, avoiding information loss that may occur during preprocessing.
[0022] Furthermore, the preprocessing in S1 includes: The barcode detection module is used to coarsely locate the barcode area in the original image. The coordinates of the four vertices of the barcode area are precisely located using Blob analysis and corner detection methods. The barcode image is rotated and corrected to a horizontal position based on the coordinates of the four vertices, and the image region containing only the barcode is segmented. The segmented barcode image is converted into a grayscale image, and then enhanced with contrast-limited adaptive histogram equalization. Finally, it is uniformly scaled to a preset size to generate the standard barcode image.
[0023] Providing standardized, high-quality input to the model is a prerequisite for the model to effectively learn normal patterns.
[0024] A system for implementing the barcode defect detection method based on visual image generation and screening as described above includes: The data preprocessing module is used to acquire the barcode image to be detected and preprocess it to generate a standard barcode image that meets the model input requirements; The feature learning and reconstruction module includes an improved BarCode-CAE model, which receives standard barcode images and generates corresponding reconstructed images. The composite anomaly score calculation module is used to calculate the composite anomaly score between the standard barcode image and the reconstructed image. ; The statistical decision and mixed detection module is used to utilize a normal sample... The dynamic threshold T obtained by statistical modeling classifies the barcode image to be detected into high-confidence good products, high-confidence bad products, or undetermined samples. For the undetermined samples, a defect detection module based on traditional image processing algorithms is further activated for secondary detection to finally determine their attributes.
[0025] The beneficial effects of this invention are: This invention employs an unsupervised learning method. During the training phase, only normal barcode samples are needed, eliminating the need to collect various defect samples or perform any pixel-level defect annotation. This fundamentally solves the pain points of difficult defect sample acquisition, uneven type distribution, high annotation costs, and poor consistency in industrial scenarios. During training, the model only learns the data distribution and generation pattern of normal samples. During the inference phase, any data deviating from this distribution will lead to high reconstruction errors and be effectively detected. When the barcode printing process, visual structure, or imaging conditions change, system migration can be completed simply by re-collecting good product samples for model training. There is no need to redefine defect rules or manually adjust detection parameters, significantly reducing system maintenance costs and deployment cycle. This invention creatively introduces a horizontal consistency constraint into the loss function of the BarCode-CAE model, targeting the inherent characteristics of barcodes such as low entropy, strong structure, and high contrast. and vertical edge reinforcement constraints This allows the model to focus on structural features that are crucial for decoding; by explicitly encoding the geometric features and structural prior knowledge of the barcode into the network, the network becomes more sensitive to specific types of subtle defects such as blurred bar-space boundaries and slight breaks. At the same time, it provides additional supervision signals for network training, significantly improving the convergence speed and stability of model training, and overcoming the technical shortcomings of general generative models that tend to be averaged in reconstruction and cannot separate subtle defects. This invention employs a weighted sliding window local mean square error. Similarity index with global structure Constructing composite anomaly scores through combination methods The two are weighted and fused to balance local accuracy and global perception. Based on this, the present invention further utilizes a Gaussian distribution fitted with composite anomaly scores from a large number of normal samples, and employs... The rule automatically calculates a dynamic detection threshold with clear statistical significance, so that the setting of the defect judgment threshold no longer depends on subjective experience, but is based on the statistical distribution characteristics of the data. Thus, in actual production, the k value can be flexibly adjusted according to the desired detection sensitivity to accurately balance the false detection rate and the missed detection rate. This invention uses the BarCode-CAE model to quickly screen the vast majority of test samples, classifying them into high-confidence good products, high-confidence bad products, and undetermined samples using dynamic thresholds. Subsequently, only for products falling into the undetermined sample range and deemed unreliable by the model, a defect detection module based on traditional image processing algorithms is activated for secondary fine-tuning. This not only compensates for the limitations of pure generative networks in detecting subtle defects but also reduces the mismatch between missed and false detections caused by poor scene adaptability when using traditional algorithms alone. It achieves a complementary advantage between the high generalization capability of deep learning and the high deterministic accuracy of traditional algorithms, significantly improving the overall robustness and industrial scene adaptability of the barcode defect detection system. Attached Figure Description
[0026] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0027] Figure 1 This is a schematic diagram of the system of the present invention.
[0028] Figure 2 This is a flowchart of the method of the present invention.
[0029] Figure 3 This is an example image of the barcode preprocessed image in the method of the present invention; wherein, Figure 3 (a) is the segmented barcode image. Figure 3 (b) is the standard input image after resizing.
[0030] Figure 4 This is a flowchart of the data preprocessing process in the method of the present invention.
[0031] Figure 5 This is a flowchart of the real-time detection stage in the method of the present invention.
[0032] Figure 6 This is a flowchart of the secondary detection process in the method of this invention.
[0033] Figure 7 This is an example diagram illustrating the model reconstruction effect of the method of the present invention; wherein, Figure 7 (a) is the original product barcode image input to the model. Figure 7 (b) is the reconstructed image output by the model. Figure 7(c) is the original defective product barcode image. Figure 7 (d) is the reconstructed image output by the model. Detailed Implementation
[0034] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0035] In the description of this invention, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential," etc., indicating orientation or positional relationships, are based on the orientation or positional relationships shown in the accompanying drawings and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, features defined with "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.
[0036] In the description of this invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0037] Example 1: like Figure 1 As shown, this embodiment provides a barcode defect detection system based on visual image generation and screening, including a data preprocessing module, a feature learning and reconstruction module, a composite anomaly score calculation module, and a statistical decision and hybrid detection module. The data preprocessing module acquires the barcode image to be detected and preprocesses it to generate a standard barcode image that meets the model input requirements. The feature learning and reconstruction module includes an improved barcode convolutional autoencoder (BarCode-CAE) model. The BarCode-CAE model is trained using a domain knowledge-driven loss function that includes horizontal consistency constraints and vertical edge enhancement constraints. It is used to receive the standard barcode image and generate the corresponding reconstructed image. The composite anomaly score calculation module calculates the composite anomaly score between the standard barcode image and the reconstructed image. The statistical decision and mixed detection module is used to utilize a normal sample... The dynamic threshold T obtained through statistical modeling classifies the barcode image to be detected into high-confidence good products, high-confidence defective products, or undetermined samples. For the undetermined samples, a defect detection module based on traditional image processing algorithms is further activated for secondary detection to ultimately determine their attributes. These modules cooperate and work together to achieve online defect detection of barcodes.
[0038] Example 2: like Figure 2 As shown, this embodiment provides a barcode defect detection method based on visual image generation and screening, mainly including three stages: model training, threshold training, and real-time detection. Before any image is input into the model, it needs to undergo a unified preprocessing process to generate standardized input data. This process also applies to the training samples in the model training stage and the test samples in the real-time detection stage. Figure 4 As shown, the specific steps are as follows: Coarse localization of barcode area: First, the barcode detection module is used to process the original barcode image to be detected, and the approximate area where the barcode is located is detected, thus achieving coarse localization of the barcode area.
[0039] Precise barcode area positioning: Based on coarse positioning, the coordinates of the four vertices of the barcode are accurately located through Blob analysis and corner detection methods, thus achieving precise positioning of the barcode area.
[0040] Barcode Alignment and Segmentation: Based on the located coordinates of the four vertices, the barcode image is rotated and corrected to a horizontal orientation, ensuring that the first principal axis of the barcode is parallel to the X-axis of the image coordinate system. After correction, fine positioning is performed again, and then the image region containing only the barcode is segmented based on the precise vertex coordinates, such as... Figure 3 As shown in (a), the segmented barcode image is displayed.
[0041] Enhancement and Normalization: The segmented barcode image is converted into a grayscale single-channel image, and then contrast-limited adaptive histogram equalization (CLAHE) is applied to enhance the image to highlight the barcode's bar and space structure. Finally, the image is uniformly scaled to a preset size (e.g., 128×128 pixels) to form the standard input image of the barcode, such as... Figure 3 As shown in (b), the standard input image after the above processing is displayed.
[0042] This embodiment provides an improved BarCode-CAE model with convolutional autoencoders. It employs an encoder-decoder structure, where the encoder performs multiple convolutional operations (convolution + batch normalization + ReLU activation) to transform the input 128×128 standard barcode image into a multi-layered latent feature map. Finally, it compresses this latent feature vector into a low-dimensional latent feature vector through a fully connected layer. The encoder's main function is to extract key features from normal barcode images, learning the "normal pattern" of the barcode, including bar / space alternation, width ratio, and start / stop symbol patterns, while simultaneously achieving data dimensionality reduction and noise filtering.
[0043] The decoder consists of transposed convolutional layers, batch normalization, and ReLU activation functions. Its function is to progressively upsample and reconstruct the latent feature vectors generated by the encoder, and finally output a reconstructed image with the same size as the input image through the Sigmoid activation function.
[0044] The encoder and decoder are jointly trained end-to-end by minimizing the following composite loss function L: , in: The pixel reconstruction loss term is calculated using the following formula: Used to calculate the standard input image of the barcode. Rather than reconstructing the image The mean square error between them, where W and H are the width and height of the image, respectively. The horizontal consistency loss term is calculated using the following formula: ,in, This loss term utilizes the structural characteristic of consistent pixel distribution in the horizontal direction of the barcode to suppress horizontal noise in the reconstructed image by minimizing the variance between the pixel value of each column and the mean of the column. The vertical edge enhancement loss term is calculated using the following formula: ,in, The Sobel vertical edge detection kernel utilizes the structural characteristic of barcodes having clear vertical edges, and forces the model to generate barcode images with sharp edges and clear structure through convolution operations. and As a preset weighting coefficient, this embodiment selects... =0.1, =0.05.
[0045] Through the constraints of the aforementioned loss function, the trained encoder can extract robust feature representations of normal samples, while the decoder can accurately reconstruct these normal features.
[0046] In this embodiment, the encoder and decoder of the BarCode-CAE model adopt a symmetrical convolution and transposed convolution structure. The encoder's function is to extract abstract features from the input 128×128 pixel standard barcode image through multiple downsampling operations and compress it into a low-dimensional latent feature vector. Its specific network structure is shown in Table 1.
[0047] Table 1
[0048] In Table 1, B represents the batch size, C represents the number of channels, W represents the width, and H represents the height.
[0049] A 128×128 grayscale barcode image (C=1 channel) is input into the encoder. After the first convolutional layer (4×4 kernel, stride 2), the image size is halved to 64×64, while the number of channels expands to 16, extracting basic edge and texture features. As the network depth increases, the size of the feature map is halved step by step: 64→32→16→8, while the number of channels doubles step by step: 16→32→64→128. Finally, a fully connected layer compresses the 8×8×128=8192-dimensional features into a 128-dimensional latent feature vector. This latent feature vector is a highly abstract representation of the input image in the hidden layer space, encoding the "normal mode" of the barcode.
[0050] The decoder functions in the opposite way to the encoder. It progressively upsamples the 128-dimensional latent feature vector output by the encoder and eventually restores a reconstructed image with the same size as the input. Its specific network structure is shown in Table 2.
[0051] Table 2
[0052] Transposed convolution, also known as deconvolution, is used to upsample feature maps.
[0053] The decoder first uses a fully connected layer to reconstruct the 128-dimensional latent feature vector into an 8×8×128 feature map. Then, through a transposed convolution (4×4 kernel, stride 2), the size of the feature map is doubled to 16×16, and the number of channels is halved to 64. This operation is repeated, with the feature map size doubling step by step from 16 to 32 to 64 to 128, and the number of channels halving step by step from 64 to 32 to 16 to 1. Finally, the output value is mapped to the [0, 1] interval by the Sigmoid activation function, generating a complete 128×128 reconstructed grayscale image.
[0054] In a specific training iteration, assuming a batch size B=32, 32 standard 128×128 images of normal barcodes are fed into the network. The encoder compresses them into 32 128-dimensional latent vectors, and the decoder receives these vectors and attempts to reconstruct the 32 128×128 images. The system calculates the total loss L between these 32 pairs of inputs and reconstructed images. Then, through the backpropagation algorithm and optimizer, the weight parameters of all convolutional and fully connected layers in the encoder and decoder are updated. After tens of thousands of iterations, the loss function L converges to a small value, at which point the model has the ability to accurately reconstruct normal barcode images.
[0055] During or after training the BarCode-CAE model, a statistically significant dynamic threshold T needs to be determined for subsequent real-time detection. The specific process is as follows: Calculate the composite anomaly score for a single image: For each training image (all normal samples), after forward propagation of the model, calculate its composite anomaly score with the reconstructed image. The calculation formula is: . in: This refers to the local MSE score, specifically calculated as follows: For the residual image between the input image and the reconstructed image, a sliding window calculation is performed with a window size of 16×16 and a stride of 8. The maximum local MSE value within all sliding windows is taken as the score for that image. This value is very sensitive to local, subtle defects. It is a global structural similarity measure between the input image and the reconstructed image, used to evaluate the overall similarity between the two images in terms of brightness, contrast, and structure. and As a preset weighting coefficient, this embodiment selects... =0.7, =0.3.
[0056] Fitting a Gaussian distribution: Calculating composite anomaly scores from all normal sample images in the training set. The mean of a Gaussian distribution is obtained by fitting it with the maximum likelihood estimation method. and standard deviation .
[0057] Calculating dynamic thresholds: based on statistics The rule is to set a dynamic detection threshold T, and the calculation formula is as follows: Where k is a preset coefficient based on the desired detection sensitivity. In this embodiment, k can be 3. At this point, the model training phase ends, and the trained BarCode-CAE model and the calculated mean are output. Standard deviation and dynamic threshold T.
[0058] After completing model training and threshold calibration, barcodes on the production line can be detected online in real time, such as... Figure 5 As shown, the specific steps are as follows: Image acquisition and preprocessing: The barcode image to be detected is acquired in real time, and the same preprocessing process as in the training stage is used to obtain the standard input image for the model inference stage.
[0059] Reconstruction and Composite Anomaly Score Calculation: The standard input image is input into the trained BarCode-CAE model to generate the corresponding reconstructed image. Using the same method as in the threshold training phase, the scores of the input image and the reconstructed image are calculated. and And through the weighted sum formula Calculate the final composite outlier score .
[0060] Phased decision-making screening: Calculated... It is compared with the dynamic threshold T, and the upper and lower threshold floating parameters of the preset good and bad product classification are used. and Perform three-interval classification: High-confidence quality products: If If the barcode image to be detected is classified as a high-confidence good product, the detection result of "good product" will be directly output.
[0061] High confidence level defective products: If the barcode image to be detected is classified as a high-confidence defective product, the system can further perform morphological processing (such as erosion, dilation, etc.) on the residual image to locate the specific location of the defect and output the "defective product" detection result.
[0062] Undetermined sample: If This indicates that the BarCode-CAE model has uncertainty in its judgment of the current sample, and the sample is classified as an undetermined sample, requiring a second detection.
[0063] Secondary detection (traditional algorithm for precise judgment): For products classified as pending samples, obtain their corresponding non-standard barcode images. These images refer to segmented barcode images that have undergone coarse positioning, fine positioning, and alignment operations in data preprocessing, but have not undergone contrast enhancement (CLAHE) or size scaling. For example... Figure 6 As shown, the defect detection module based on traditional image processing algorithms will perform the following operations on non-standard images to detect common defects: Threshold segmentation: First, the bar code's bar area and empty area are separated using the threshold segmentation method.
[0064] Width Anomaly Detection: Perform Blob analysis on individual striped areas and / or individual empty areas. If the width of a single striped area is greater than a preset threshold, it is determined to be a contamination defect; if the width of a single empty area is greater than a preset threshold, it is determined to be an ink stripping defect.
[0065] Bright / Dark Defect Detection: Threshold segmentation is performed on the overall striped region to detect bright defects; threshold segmentation is performed on the overall empty region to detect dark defects.
[0066] Filament defects detection: Dynamic threshold segmentation is performed on the entire barcode area, bright candidate areas are extracted and Blob analysis is performed to detect white filament defects; similarly, dark candidate areas are extracted and Blob analysis is performed to detect black filament defects.
[0067] After comprehensive judgment by the above traditional algorithms, the final detection result (good or bad) of the undetermined sample is output, thus completing the entire barcode defect detection process.
[0068] To visually demonstrate the ability of the BarCode-CAE model in this embodiment to reconstruct and repair barcode images, such as... Figure 7 As shown, an example of the model reconstruction effect is given. Figure 7 (a) and Figure 7 (b) Displays the reconstructed data of the barcode-certified products, in which... Figure 7 (a) is the original product barcode image input to the model. Figure 7 (b) is the reconstructed image output by the model. By comparison, it can be seen that for normal barcode samples, the model can accurately learn its texture, bar structure and width ratio, etc., the "normal pattern". The output reconstructed image is highly consistent with the original image, with clear structure, sharp edges and no obvious distortion.
[0069] Figure 7 (c) and Figure 7 (d) shows the reconstructed data of the barcode defective products, in which, Figure 7 (c) is the original defective product barcode image with defects (in the example, the defects are manifested as localized broken bars and dirt). Figure 7 (d) shows the reconstructed image output by the model. Because the model only learned the data distribution of normal samples during training, for defective inputs, its latent feature representation deviates from the "normal pattern," causing the decoder to fail to reconstruct it well. Figure 7 (d) It can be seen that the defect region in the reconstructed image (corresponding to) Figure 7 (c) The broken and dirty areas were significantly blurred, smoothed or completely restored to normal texture, resulting in a significant reconstruction error compared to the original image.
[0070] In summary, this embodiment provides a complete, efficient, and robust barcode defect detection method by combining the BarCode-CAE model incorporating prior knowledge of barcode structure, dynamic threshold decision based on statistical modeling, and traditional image processing algorithms. It effectively solves the problems of parameter sensitivity, poor generalization, difficulty in balancing false negatives and false negatives, and insufficient adaptability to new defects in existing technologies.
[0071] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.
Claims
1. A barcode defect detection method based on visual image generation and screening, characterized in that, Includes the following steps: S1. Obtain the barcode image to be detected and preprocess it to generate a standard barcode image that meets the model input requirements; S2. Input the standard barcode image into an improved convolutional autoencoder BarCode-CAE model to generate a reconstructed image; calculate the composite anomaly score between the standard barcode image and the reconstructed image. ; S3, Combined outlier scores The image is compared with a dynamic threshold T obtained through statistical modeling to classify the barcode image to be detected as a high-confidence good product, a high-confidence bad product, or a sample to be determined. S4. For undetermined samples, obtain the corresponding non-standard barcode image and use a defect detection module based on traditional image processing algorithms for secondary detection to finally determine its attributes.
2. The barcode defect detection method based on visual image generation and screening according to claim 1, characterized in that, The BarCode-CAE model in S2 includes an encoder and a decoder. The encoder is used to extract low-dimensional latent features from a normal barcode image, and the decoder is used to reconstruct the image from the low-dimensional latent features. The encoder and decoder are jointly trained end-to-end by minimizing the loss function L.
3. The barcode defect detection method based on visual image generation and screening according to claim 2, characterized in that, The expression for the loss function L is: , , in, Standard input image for barcode With reconstructed image The pixel reconstruction loss term is the mean squared error between the two sides. To minimize the variance of pixel values in each column of the reconstructed image and constrain the horizontal consistency of pixel distribution, a horizontal consistency loss term is used. This is a vertical edge enhancement loss term that enhances the vertical edge strength of the reconstructed image by convolving the Sobel vertical edge detection kernel with the image. and These are the preset weighting coefficients.
4. The barcode defect detection method based on visual image generation and screening according to claim 1, characterized in that, Composite anomaly score in S2 The calculation formula is: , in, The value is obtained by performing a sliding window calculation on the residual image between the standard barcode image and the reconstructed image, and taking the maximum value among all windows; The structural similarity index between the input image and the reconstructed image; and These are the preset weighting coefficients.
5. The barcode defect detection method based on visual image generation and screening according to claim 1, characterized in that, The method for generating the dynamic threshold T in S3 is as follows: During the training or validation phase of the BarCode-CAE model, collect composite anomaly scores for all normal sample images. The mean of a Gaussian distribution is obtained by fitting it with the maximum likelihood estimation method. and standard deviation The dynamic threshold was calculated based on statistical rules. , where k is a coefficient preset according to the desired detection sensitivity.
6. The barcode defect detection method based on visual image generation and screening according to claim 5, characterized in that, The specific classification of barcode images to be detected in S3 is as follows: If the composite anomaly score of the barcode image to be detected If so, it is classified as a high-confidence good product; If the composite anomaly score of the barcode image to be detected If so, it is classified as a high-confidence defective product; If the composite anomaly score of the barcode image to be detected If so, it is classified as an undetermined sample; in, and These are the upper and lower threshold floating parameters for classifying good and bad products, respectively.
7. The barcode defect detection method based on visual image generation and screening according to claim 1, characterized in that, The defect detection module in S4, based on traditional image processing algorithms, performs the following operations: First, threshold segmentation is used to separate the bar regions and empty regions of the barcode; then, blob analysis is performed on individual bars and / or empty regions to detect width anomalies; finally, subtle defects are detected in the bar regions and empty regions through dynamic threshold segmentation.
8. The barcode defect detection method based on visual image generation and screening according to claim 7, characterized in that, The non-standard barcode image used in the secondary detection step of S4 refers to a segmented barcode image that has undergone coarse positioning, fine positioning, and alignment operations, but has not been subjected to contrast enhancement and scaling processing.
9. The barcode defect detection method based on visual image generation and screening according to claim 1, characterized in that, Preprocessing in S1 includes: The barcode detection module is used to coarsely locate the barcode area in the original image. The coordinates of the four vertices of the barcode area are precisely located using Blob analysis and corner detection methods. The barcode image is rotated and corrected to a horizontal position based on the coordinates of the four vertices, and the image region containing only the barcode is segmented. The segmented barcode image is converted into a grayscale image, and then enhanced with contrast-limited adaptive histogram equalization. Finally, it is uniformly scaled to a preset size to generate the standard barcode image.
10. A system for implementing the barcode defect detection method based on visual image generation and screening as described in any one of claims 1 to 9, characterized in that, include: The data preprocessing module is used to acquire the barcode image to be detected and preprocess it to generate a standard barcode image that meets the model input requirements; The feature learning and reconstruction module includes an improved BarCode-CAE model, which receives standard barcode images and generates corresponding reconstructed images. The composite anomaly score calculation module is used to calculate the composite anomaly score between the standard barcode image and the reconstructed image. ; The statistical decision and mixed detection module is used to utilize a normal sample... The dynamic threshold T obtained by statistical modeling classifies the barcode image to be detected into high-confidence good products, high-confidence bad products, or undetermined samples. For the undetermined samples, a defect detection module based on traditional image processing algorithms is further activated for secondary detection to finally determine their attributes.