A method, apparatus, equipment and medium for detecting label defects
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-15
- Publication Date
- 2026-08-11
AI Technical Summary
现有针对复杂标签缺陷的红外检测技术,可以检测出标签面积缺损,透光率不均,边缘缺口等,但其检测方法单一、获取数据量少,无法有效的对标签面上全部缺陷进行检测;而用图像特征及模板匹配技术,由于标签种类多样,针对每种标签都要进行预设置,并且预设置复杂,不仅算法运算量较大,而且会导致识别速度低下,特别是断纱,错梭等特征不明显的缺陷更加难以识别
[0037]As can be seen, this application provides a label defect detection method, including acquiring a label image to be detected, performing area defect detection on the label image to obtain a first detection result; calculating the region complexity of the label image to obtain various complexities, filtering out complex regions from the label image according to each complexity, and masking the complex regions to obtain a masked label image; inputting the masked label image into a preset defect detection model to obtain a second detection result; performing image processing on the complex regions to obtain processed complex region images, comparing the processed complex region images with a preset template image to obtain a third detection result; performing label tilt detection on the label image to obtain a fourth detection result; and determining a label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result. This application utilizes image feature detection and deep learning neural network methods to segment complex information such as text and images in the label, uses a YOLOv5 model improved with a focal loss function to predict the masked image, and uses similarity to match and identify complex images, narrowing the matching region and improving the detection rate. By utilizing image feature detection techniques, a detection method targeting large and small edges, label tilt, and boundary damage is designed, which can effectively improve the efficiency of label defect detection. In particular, for complex and variable label detection, it can increase the accuracy of label defect detection. The fusion of multiple recognition methods allows for a more comprehensive discovery of various label defects. Multiple optimization algorithms reduce the amount of data, reduce the complexity of label defect detection, and significantly improve the computing speed.
Smart Images

Figure CN115829992B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image recognition, and in particular to a method, apparatus, device, and medium for detecting label defects. Background Technology
[0002] Existing label defects include dirt, broken yarn, misprints, mis-weaving, gaps, uneven edges, and label tilt. For simple materials, such as solid-color clothing and fabrics without text, current technologies often employ deep neural networks to learn a network model of the defects before detection. For labels containing a large amount of text or images, infrared light penetration detection is used, illuminating the label from top to bottom and identifying defects by detecting the bottom area where light is transmitted. Alternatively, image feature and template matching techniques are used to further determine the defect location through image matrix calculations. Existing infrared detection technologies for complex label defects can detect label area defects, uneven light transmittance, and edge gaps, but their detection methods are limited and the amount of data acquired is small, making it impossible to effectively detect all defects on the label surface. Image feature and template matching techniques, due to the diverse types of labels, require pre-setting for each label, which is complex and computationally intensive, leading to slow recognition speeds, especially for defects with subtle features such as broken yarn and mis-weaving. Traditional deep neural networks are not very effective for label-type fabrics with complex information such as a large amount of text and images, and have a high misjudgment rate and error rate.
[0003] As can be seen from the above, how to improve the efficiency, increase the accuracy, and reduce the complexity of label defect detection is a problem that needs to be solved in this field. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a label defect detection method, apparatus, device, and medium that can improve the efficiency of label defect detection, increase the accuracy of label defect detection, and reduce the complexity of label defect detection. The specific solution is as follows:
[0005] Firstly, this application discloses a label defect detection method, including:
[0006] Acquire the label image to be detected, and perform area defect detection on the label image to obtain a first detection result;
[0007] The region complexity of the label image is calculated to obtain various complexities. Complex regions are selected from the label image according to the complexities and the complex regions are masked to obtain a masked label image. The masked label image is input into a preset defect detection model to obtain a second detection result.
[0008] The complex region is processed to obtain a processed complex region image. The processed complex region image is then compared and detected with a preset template image to obtain a third detection result.
[0009] Label tilt detection is performed on the label image to obtain a fourth detection result. Based on the first detection result, the second detection result, the third detection result, and the fourth detection result, a label defect detection result is determined.
[0010] Optionally, acquiring the label image to be detected includes:
[0011] All label images are acquired using a preset camera, and a background is added to all the label images to obtain all label images with backgrounds.
[0012] The label images carrying background panels are segmented according to the region of interest to obtain each label image to be detected.
[0013] Optionally, the step of performing area defect detection on the label image to obtain a first detection result includes:
[0014] The label image is compressed to obtain a one-dimensional label image. Then, the one-dimensional label image is subjected to edge background expansion, image binarization, noise point removal and edge detection operations to determine the boundary inflection points and the number of boundary inflection points.
[0015] Determine whether the number of boundary inflection points is odd. If the number of boundary inflection points is odd, then perform area loss calculation based on the boundary inflection points and using a fitted regular polygon algorithm to obtain a first detection result containing the label area loss region.
[0016] Optionally, the calculation of region complexity for the label image to obtain various complexities includes:
[0017] The label image is smoothed by convolution using Gaussian filtering to obtain a smoothed image. The rectangular gradient and direction of the smoothed image are calculated to obtain the magnitude of each gradient. Then, non-maximum suppression is performed on each gradient magnitude to obtain a gradient image.
[0018] The region complexity of the label image is calculated based on the gradient image to obtain the various complexities.
[0019] Optionally, the step of performing image processing on the complex region to obtain a processed complex region image, and comparing the processed complex region image with a preset template image to obtain a third detection result, includes:
[0020] The complex region is filtered, binarized, and edge detected to obtain a processed complex region image; wherein the processed complex region image is a complex region image or a minimum bounding rectangle image.
[0021] The processed complex region image is compared with a preset template image using a perceptual hash algorithm to obtain a third detection result.
[0022] Optionally, the step of performing label tilt detection on the label image to obtain a fourth detection result includes:
[0023] The processed complex region image is extracted to obtain the center point, and the label boundary vertical line is determined so that the actual position of the label can be determined based on the center point and the label boundary vertical line.
[0024] Determine whether the actual position of the label has shifted to obtain the fourth detection result.
[0025] Optionally, after determining the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result, the method further includes:
[0026] The determination time of the label defect detection result is obtained, and it is determined whether the determination time is less than a preset time threshold. If the determination time is less than the preset time threshold, a delay compensation operation is performed, and it is determined whether the label defect detection is completed.
[0027] If the label defect detection is not completed, multi-threading is started to continue the label defect detection until it is completed, and the completion time is recorded. Then, the preset time threshold is modified using the least squares method to obtain a new preset time threshold.
[0028] Secondly, this application discloses a label defect detection device, comprising:
[0029] An area defect detection module is used to acquire a label image to be detected and to perform area defect detection on the label image to obtain a first detection result;
[0030] The complexity calculation module is used to calculate the regional complexity of the label image to obtain various complexities, filter out complex regions from the label image according to the complexities, and mask the complex regions to obtain a masked label image. The masked label image is then input into a preset defect detection model to obtain a second detection result.
[0031] The comparison and detection module is used to perform image processing on the complex region to obtain a processed complex region image, and to compare and detect the processed complex region image with a preset template image to obtain a third detection result.
[0032] The label tilt detection module is used to perform label tilt detection on the label image to obtain a fourth detection result, and to determine the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result.
[0033] Thirdly, this application discloses an electronic device, including:
[0034] Memory, used to store computer programs;
[0035] A processor is used to execute the computer program to implement the aforementioned label defect detection method.
[0036] Fourthly, this application discloses a computer storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed label defect detection method.
[0037] As can be seen, this application provides a label defect detection method, including acquiring a label image to be detected, performing area defect detection on the label image to obtain a first detection result; calculating the region complexity of the label image to obtain various complexities, filtering out complex regions from the label image according to each complexity, and masking the complex regions to obtain a masked label image; inputting the masked label image into a preset defect detection model to obtain a second detection result; performing image processing on the complex regions to obtain processed complex region images, comparing the processed complex region images with a preset template image to obtain a third detection result; performing label tilt detection on the label image to obtain a fourth detection result; and determining a label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result. This application utilizes image feature detection and deep learning neural network methods to segment complex information such as text and images in the label, uses a YOLOv5 model improved with a focal loss function to predict the masked image, and uses similarity to match and identify complex images, narrowing the matching region and improving the detection rate. By utilizing image feature detection techniques, a detection method targeting large and small edges, label tilt, and boundary damage is designed, which can effectively improve the efficiency of label defect detection. In particular, for complex and variable label detection, it can increase the accuracy of label defect detection. The fusion of multiple recognition methods allows for a more comprehensive discovery of various label defects. Multiple optimization algorithms reduce the amount of data, reduce the complexity of label defect detection, and significantly improve the computing speed. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0039] Figure 1 This is a flowchart of a label defect detection method disclosed in this application;
[0040] Figure 2 This is a specific example diagram of a label defect detection method disclosed in this application;
[0041] Figure 3 This is a specific example diagram of a label defect detection method disclosed in this application;
[0042] Figure 4 This is a specific example diagram of a label defect detection method disclosed in this application;
[0043] Figure 5 This is a flowchart of a label defect detection method disclosed in this application;
[0044] Figure 6 This is a specific example diagram of a label defect detection method disclosed in this application;
[0045] Figure 7 This is a specific example diagram of a label defect detection method disclosed in this application;
[0046] Figure 8 This is a flowchart illustrating a label defect detection method disclosed in this application.
[0047] Figure 9 This is a schematic diagram of the structure of a label defect detection device disclosed in this application;
[0048] Figure 10 This application provides a structural diagram of an electronic device. Detailed Implementation
[0049] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0050] Existing label defects include dirt, broken yarn, misprints, mis-weaving, gaps, uneven edges, and label tilt. For simple materials, such as solid-color clothing and fabrics without text, current technologies often employ deep neural networks to learn a network model of the defects before detection. For labels containing a large amount of text or images, infrared light penetration detection is used, illuminating the label from top to bottom and identifying defects by detecting the bottom area where light is transmitted. Alternatively, image feature and template matching techniques are used to further determine the defect location through image matrix calculations. Existing infrared detection technologies for complex label defects can detect label area defects, uneven light transmittance, and edge gaps, but their detection methods are limited and the amount of data acquired is small, making it impossible to effectively detect all defects on the label surface. Image feature and template matching techniques, due to the diverse types of labels, require pre-setting for each label, which is complex and computationally intensive, leading to slow recognition speeds, especially for defects with subtle features such as broken yarn and mis-weaving. Traditional deep neural networks are ineffective for label-type fabrics containing complex information such as large amounts of text and images, exhibiting high false positive and error rates. Therefore, improving the efficiency, accuracy, and complexity of label defect detection are unresolved issues in this field.
[0051] See Figure 1 As shown in the figure, an embodiment of the present invention discloses a label defect detection method, which may specifically include:
[0052] Step S11: Obtain the label image to be detected, and perform area defect detection on the label image to obtain the first detection result.
[0053] In this embodiment, all label images are acquired using a preset camera, and a background is added to all the label images to obtain all label images with backgrounds. The label images with backgrounds are then segmented according to the region of interest to obtain individual label images to be detected. After acquiring the label images to be detected, the label images are compressed to obtain one-dimensional label images. Then, edge background expansion, image binarization, noise removal, and edge detection operations are performed on the one-dimensional label images to determine boundary inflection points and the number of boundary inflection points. It is determined whether the number of boundary inflection points is odd. If the number of boundary inflection points is odd, an area defect region calculation operation is performed based on the boundary inflection points and using a fitted regular polygon algorithm to obtain a first detection result containing the label area defect region.
[0054] In this embodiment, continuous label rolls are acquired, and information about the front of each label is obtained using an RGB (Red, Green, Blue) camera. A background plate contrasting with the label color is placed at the bottom of each label. The continuous label rolls are segmented by setting a Region of Interest (ROI). Defects in the outer border and label area defects are identified for each segment. Specifically, the three-dimensional image is compressed into a one-dimensional image, and then boundary background expansion is performed. This operation segments the continuous fabric. A threshold is set for image binarization to remove noise points. Edge detection is then performed, boundary inflection points are calculated, and the boundary is fitted as an approximate polygon with its area calculated. Boundary defects are determined by the inflection points. The area defect of the label is determined by fitting the regular polygon to the actual graphic and comparing the area defect region. The implementation effect is as follows: Figure 2 As shown.
[0055] The polygon fitting algorithm employs the Douglas-Peucker algorithm and an iterative endpoint fitting algorithm. This method reduces the number of points by fitting the curve to a series of points. Specifically, it is as follows: Figure 3 As shown, the specific process is as follows: First, draw the chord of the curve between any two points (such as A and B) in the image; Second, obtain the point C that is farthest from the chord between points A and B; Third, obtain the distance h of point C from the chord. If h is less than the threshold, the point between points A and B is omitted, and the AB curve is fitted to this chord. Otherwise, use point C to segment AB, and then repeat the operation of steps one to three for AC and BC respectively; Fourth, (4) when all line segments are processed, connect the line segments to obtain the total fitted polygon. This application designs a double threshold judgment method. First, take 1% of the contour perimeter as the first threshold, and fit it into a closed rectangle with an inflection point of 4 through the fitting polygon algorithm. Then take 10% of the first threshold as the second threshold, and perform the fitting polygon algorithm again to improve the detection accuracy and judge whether there are extra inflection points. If the number of extra inflection points is odd, there is a gap. At the same time, the difference between the fitted closed rectangle area and the actual contour area is used to obtain the actual label defect area.
[0056] Step S12: Calculate the regional complexity of the label image to obtain each complexity, filter out complex regions from the label image according to each complexity, and mask the complex regions to obtain a masked label image. Input the masked label image into a preset defect detection model to obtain a second detection result.
[0057] In this embodiment, after obtaining the masked label image, the masked image is input into a pre-trained YOLOv5 model improved based on the focal loss function to obtain its defect information. A pre-trained model is used to identify various labels. Since the special characteristics of some special labels can cause misjudgments, a defect filter is used to filter out defects appearing in these areas. The focal loss function is formed by improving the cross-entropy loss function, and its specific form is as follows:
[0058]
[0059]
[0060]
[0061] Wherein, p t It represents the degree of proximity of category y, p t The larger the value, the more accurate the classification; γ > 0 is a moderating factor. y represents the predicted probability; y is the label corresponding to 1 or 0; the defect filter adopts a region inclusion method. If a defect appears in a pre-defined region, it is ignored; otherwise, it is displayed normally. This method can avoid misjudging untrained features.
[0062] Step S13: Perform image processing on the complex region to obtain a processed complex region image, and compare the processed complex region image with a preset template image to obtain a third detection result.
[0063] In this embodiment, after obtaining the processed complex region image, filtering, binarization, and edge detection are performed on the complex region to obtain a processed complex region image; wherein, the processed complex region image is a complex region image or a minimum bounding rectangle image; the processed complex region image is compared and detected with a preset template image using a perceptual hash algorithm to obtain a third detection result. In this embodiment, filtering, binarization, and edge detection are performed on the image within the complex region to further obtain the minimum bounding rectangle of the image or text within the complex region, and the implementation effect is as follows. Figure 4 As shown, Figure 4 The first image is the grayscale image after grayscale fusion, the second image is the smoothed image after Gaussian filtering, the third image is the image after calculating gradient and direction and non-maximum suppression, and the fourth image shows the identified complex regions.
[0064] Step S14: Perform label tilt detection on the label image to obtain a fourth detection result, and determine the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result.
[0065] In this embodiment, after determining the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result, the method further includes: obtaining the determination time of the label defect detection result, and determining whether the determination time is less than a preset time threshold. If the determination time is less than the preset time threshold, a delay completion operation is performed, and it is determined whether the label defect detection is completed. If the label defect detection is not completed, multi-threading is started to continue executing the label defect detection until the label defect detection is completed, and the completion time is recorded. Then, the preset time threshold is modified using the least squares method to obtain a new preset time threshold.
[0066] In this embodiment, during continuous pipeline operation, the processor's real-time state changes due to varying data volumes, resulting in significant differences in processing time for each frame. To address this, multithreading and thread time management are employed to increase latency and control the execution time to be as consistent as possible, ensuring the pipeline operates normally. Specifically, the pipeline first steps to a label and then takes an image of that label. After acquiring the label's front image, image processing is performed under timer monitoring, controlling the processing time to be within a preset time threshold. If the processing time is less than this threshold, the delay is compensated; otherwise, a new thread is started to continue image processing, and the main thread is released, allowing the program to proceed to the next step. The pipeline then continues to step to the next label, ensuring that the time spent in a single step equals the threshold time. The threshold time is dynamically adjustable by recording the complete processing time for each step. The least squares method – Gauss-Newton iteration method – is used to perform nonlinear fitting on the processing time for each step, obtaining a minimum intermediate time that corresponds to the sum of squared residuals for each step, which is then used as the new threshold time. This method ensures that the processing time is as consistent as possible, preventing significant variations and avoiding additional latency that could reduce efficiency. The least squares method with a forgetting factor is used to recursively apply the formula for each time step, as follows:
[0067]
[0068] Where θ is the input parameter vector, φ is the data vector, and λ is the forgetting factor, which is generally 0.95 < λ < 1.
[0069] In this embodiment, a label image to be detected is acquired, and area defect detection is performed on the label image to obtain a first detection result. The region complexity of the label image is calculated to obtain various complexities. Complex regions are selected from the label image based on these complexities, and these complex regions are masked to obtain a masked label image. The masked label image is input into a preset defect detection model to obtain a second detection result. Image processing is performed on the complex regions to obtain processed complex region images. The processed complex region images are compared with a preset template image to obtain a third detection result. Label tilt detection is performed on the label image to obtain a fourth detection result. Based on the first detection result, the second detection result, the third detection result, and the fourth detection result, a label defect detection result is determined. This application utilizes image feature detection and deep learning neural network methods to segment complex information such as text and images in the label. A YOLOv5 model improved with a focal loss function is used to predict the masked image. Similarity is used to match and identify complex images, narrowing the matching region and improving the detection rate. By utilizing image feature detection techniques, a detection method targeting large and small edges, label tilt, and boundary damage is designed, which can effectively improve the efficiency of label defect detection. In particular, for complex and variable label detection, it can increase the accuracy of label defect detection. The fusion of multiple recognition methods allows for a more comprehensive discovery of various label defects. Multiple optimization algorithms reduce the amount of data, reduce the complexity of label defect detection, and significantly improve the computing speed.
[0070] See Figure 5 As shown in the figure, an embodiment of the present invention discloses a label defect detection method, which may specifically include:
[0071] Step S21: Obtain the label image to be detected, and perform area defect detection on the label image to obtain the first detection result.
[0072] Step S22: Perform convolution smoothing on the label image using Gaussian filtering to obtain a smoothed image. Calculate the rectangular gradient and direction of the smoothed image to obtain the magnitude of each gradient. Then, perform non-maximum suppression on each gradient magnitude to obtain a gradient image. Calculate the region complexity of the label image based on the gradient image to obtain the complexity of each region.
[0073] Step S23: Select complex regions from the label images according to the complexity levels, and mask the complex regions to obtain masked label images. Input the masked label images into a preset defect detection model to obtain a second detection result.
[0074] In this embodiment, after filtering out complex regions from the label image according to their respective complexities, the complex regions are masked to reduce the complexity of image recognition. Specifically, Gaussian filtering and image convolution are first used to smooth the image and reduce image noise (for fabric labels with strong graininess, the smoothing of label graininess is achieved by changing the standard deviation of the Gaussian filter and the size of the window). Figure 6 As shown, the image on the left shows fabric with a grainy texture, while the image on the right shows smoothed fabric. The gradient and direction of the image rectangle are then calculated, and non-maximum suppression is applied to the gradient magnitude. Based on the obtained gradient image, its regional complexity is calculated, and complex regions of the label image are selected according to their complexity. These complex regions are then masked using single-data filling, with the effect shown below. Figure 4 As shown. The two-dimensional Gaussian function for Gaussian filtering is:
[0075]
[0076] Based on the value of σ, the weight matrix for different window sizes can be obtained. Then, normalization can be performed to obtain the Gaussian convolution kernel. For example, a convolution kernel with σ = 1.5 and a blur radius of 1 is:
[0077]
[0078] Image smoothing can be achieved by convolving the image with this kernel. In images with high graininess or noise, increasing the kernel radius and changing the Gaussian filter standard deviation can achieve better smoothing results. The image is then subjected to gradient calculations in the X and Y directions using the Sobel operator, specifically as follows:
[0079]
[0080]
[0081] Among them, G x It is the gradient image in the x-direction, G y It is the gradient image in the y-direction, where I is a grayscale image, and the gradient image G can be calculated. xy :
[0082]
[0083] Then, non-maximum pixel gradient suppression is used to obtain the final edge image. Pooling is introduced for complex region extraction. This process is similar to convolution; the obtained gradient image is passed through a 3×3 filter with a stride of 2, the mean is calculated, and the mean is output to a new image. Figure 7As shown, this method preserves gradient information while eliminating image noise and reduces image data volume by 75%. Then, by selecting high-value regions in the pooled image and remapping them onto the original image, complex regions with large gradient values can be obtained. This method significantly improves computational speed.
[0084] Step S24: Perform image processing on the complex region to obtain a processed complex region image, and compare the processed complex region image with a preset template image to obtain a third detection result.
[0085] In this embodiment, a perceptual hash algorithm is used to compare the image with a pre-defined template image. The similarity score determines whether defects such as text errors, dirt, or misprints exist in the image. The similarity calculation uses a modified mean hash algorithm, widely used in encryption. In image similarity calculation, the process is as follows: First, the image is scaled to a fixed size, which is 0.8 times the maximum size. Then, the average value of the image is taken, and each pixel is compared to the average value. If the average is greater, it is 1; otherwise, it is 0. The sequence of 1s and 0s is the hash value, and the hash value of the baseline image is defined as the baseline hash value. Subsequent images only need to have their hash values compared to the baseline hash value. This method has the following properties: Fixed data volume: The hash value length is fixed and does not change with the size of the image area; Sensitive to differences: When there are differences between the images, the hash value will also change significantly; Small data volume: It is not necessary to save the entire image; only the extracted hash values need to be saved and compared.
[0086] Step S25: Extract the center point from the processed complex region image and determine the label boundary vertical line so as to determine the actual position of the label based on the center point and the label boundary vertical line. Then, determine whether the actual position of the label has shifted to obtain the fourth detection result.
[0087] In this embodiment, defects such as large / small edges and label tilt are identified in the label. Specifically, the center point of the smallest rectangle is extracted, and perpendicular lines are drawn from the top and bottom boundaries of the label to obtain the actual position of the image (or text) within the label. Whether the position has shifted is determined, indirectly indicating whether the label has large / small edge defects. The difference between the rotation angle of the smallest rectangle and the rotation angle of the boundary rectangle indicates whether the image or text is tilted, thus determining whether the actual position of the label has shifted.
[0088] Step S26: Determine the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result.
[0089] The specific process for this application is as follows: Figure 8 As shown, the pipeline first steps to a label, then takes a picture of the label's front image. Image processing is then performed under timer monitoring, with the processing time controlled within a dynamic threshold time. If the processing time is less than this threshold, a delay is implemented to compensate for the delay; otherwise, a new thread is started to continue image processing, and the main thread is released, allowing the program to proceed to the next step. The pipeline then continues to step to the next label, ensuring that the time spent in each step equals the threshold time. It then determines whether label defect detection is complete. If not, multiple threads are started to continue label defect detection until it is completed, and the completion time is recorded. Finally, the least squares method is used to modify the preset time threshold to obtain a new preset time threshold.
[0090] In this embodiment, a label image to be detected is acquired, and area defect detection is performed on the label image to obtain a first detection result. The region complexity of the label image is calculated to obtain various complexities. Complex regions are selected from the label image based on these complexities, and these complex regions are masked to obtain a masked label image. The masked label image is input into a preset defect detection model to obtain a second detection result. Image processing is performed on the complex regions to obtain processed complex region images. The processed complex region images are compared with a preset template image to obtain a third detection result. Label tilt detection is performed on the label image to obtain a fourth detection result. Based on the first detection result, the second detection result, the third detection result, and the fourth detection result, a label defect detection result is determined. This application utilizes image feature detection and deep learning neural network methods to segment complex information such as text and images in the label. A YOLOv5 model improved with a focal loss function is used to predict the masked image. Similarity is used to match and identify complex images, narrowing the matching region and improving the detection rate. By utilizing image feature detection techniques, a detection method targeting large and small edges, label tilt, and boundary damage is designed, which can effectively improve the efficiency of label defect detection. In particular, for complex and variable label detection, it can increase the accuracy of label defect detection. The fusion of multiple recognition methods allows for a more comprehensive discovery of various label defects. Multiple optimization algorithms reduce the amount of data, reduce the complexity of label defect detection, and significantly improve the computing speed.
[0091] See Figure 9 As shown in the figure, an embodiment of the present invention discloses a label defect detection device, which may specifically include:
[0092] The area defect detection module 11 is used to acquire the label image to be detected and perform area defect detection on the label image to obtain a first detection result;
[0093] Complexity calculation module 12 is used to calculate the regional complexity of the label image to obtain each complexity, filter out complex regions from the label image according to each complexity, and mask the complex regions to obtain a masked label image. The masked label image is then input into a preset defect detection model to obtain a second detection result.
[0094] The comparison and detection module 13 is used to perform image processing on the complex region to obtain a processed complex region image, and to compare and detect the processed complex region image with a preset template image to obtain a third detection result.
[0095] The label tilt detection module 14 is used to perform label tilt detection on the label image to obtain a fourth detection result, and to determine the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result.
[0096] In this embodiment, a label image to be detected is acquired, and area defect detection is performed on the label image to obtain a first detection result. The region complexity of the label image is calculated to obtain various complexities. Complex regions are selected from the label image based on these complexities, and these complex regions are masked to obtain a masked label image. The masked label image is input into a preset defect detection model to obtain a second detection result. Image processing is performed on the complex regions to obtain processed complex region images. The processed complex region images are compared with a preset template image to obtain a third detection result. Label tilt detection is performed on the label image to obtain a fourth detection result. Based on the first detection result, the second detection result, the third detection result, and the fourth detection result, a label defect detection result is determined. This application utilizes image feature detection and deep learning neural network methods to segment complex information such as text and images in the label. A YOLOv5 model improved with a focal loss function is used to predict the masked image. Similarity is used to match and identify complex images, narrowing the matching region and improving the detection rate. By utilizing image feature detection techniques, a detection method targeting large and small edges, label tilt, and boundary damage is designed, which can effectively improve the efficiency of label defect detection. In particular, for complex and variable label detection, it can increase the accuracy of label defect detection. The fusion of multiple recognition methods allows for a more comprehensive discovery of various label defects. Multiple optimization algorithms reduce the amount of data, reduce the complexity of label defect detection, and significantly improve the computing speed.
[0097] In some specific embodiments, the area defect detection module 11 may specifically include:
[0098] The label image acquisition module is used to acquire all label images using a preset camera and add a background to all the label images to obtain all label images with backgrounds.
[0099] The segmentation module is used to segment all the label images carrying background boards according to the region of interest to obtain each label image to be detected.
[0100] In some specific embodiments, the area defect detection module 11 may specifically include:
[0101] The compression module is used to compress the label image to obtain a one-dimensional label image, and then perform edge background expansion, image binarization, noise point removal and edge detection operations on the one-dimensional label image to determine the boundary inflection points and the number of boundary inflection points.
[0102] The judgment module is used to determine whether the number of boundary inflection points is odd. If the number of boundary inflection points is odd, the module calculates the area of the missing region based on the boundary inflection points and using a fitted regular polygon algorithm to obtain a first detection result containing the area of the missing label region.
[0103] In some specific embodiments, the complexity calculation module 12 may specifically include:
[0104] The convolution smoothing module is used to perform convolution smoothing on the label image using Gaussian filtering to obtain a smoothed image, calculate the rectangular gradient and direction of the smoothed image to obtain the magnitude of each gradient, and then perform non-maximum suppression operation on each gradient magnitude to obtain a gradient image.
[0105] The complexity calculation module is used to calculate the region complexity of the label image based on the gradient image to obtain the various complexities.
[0106] In some specific embodiments, the comparison and detection module 13 may specifically include:
[0107] The complex region image determination module is used to perform filtering, binarization, and edge detection processing on the complex region to obtain a processed complex region image; wherein, the processed complex region image is a complex region image or a minimum bounding rectangle image;
[0108] The comparison and detection module is used to compare and detect the processed complex region image with a preset template image using a perceptual hash algorithm to obtain a third detection result.
[0109] In some specific embodiments, the label tilt detection module 14 may specifically include:
[0110] The center point extraction module is used to extract the center point from the processed complex region image and determine the label boundary vertical line so as to determine the actual position of the label based on the center point and the label boundary vertical line.
[0111] The fourth detection result determination module is used to determine whether the actual position of the label has shifted, so as to obtain the fourth detection result.
[0112] In some specific embodiments, the label tilt detection module 14 may specifically include:
[0113] The delay completion module is used to obtain the determination time of the label defect detection result and determine whether the determination time is less than a preset time threshold. If the determination time is less than the preset time threshold, a delay completion operation is performed, and it is determined whether the label defect detection is completed.
[0114] The time threshold modification module is used to start multi-threaded execution of label defect detection if label defect detection is not completed, until label defect detection is completed, and record the completion time. Then, the preset time threshold is modified using the least squares method to obtain a new preset time threshold.
[0115] Figure 10 This is a schematic diagram of an electronic device provided in an embodiment of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the label defect detection method performed by the electronic device disclosed in any of the foregoing embodiments.
[0116] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0117] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.
[0118] The operating system 221 manages and controls the various hardware devices on the electronic device 20 and the computer program 222 to enable the processor 21 to perform calculations and processing on the data 223 in the memory 22. The operating system 221 can be Windows, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the label defect detection method executed by the electronic device 20 as disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the label defect detection device from external devices, as well as data collected by its own input / output interface 25.
[0119] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0120] Furthermore, embodiments of this application also disclose a computer-readable storage medium storing a computer program, which, when loaded and executed by a processor, implements the label defect detection method steps disclosed in any of the foregoing embodiments.
[0121] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0122] The present invention provides a detailed description of a label defect detection method, apparatus, device, and storage medium. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.
Claims
1. A method for detecting label defects, characterized in that, include: Acquire the label image to be detected, and perform area defect detection on the label image to obtain a first detection result; The region complexity of the label image is calculated to obtain various complexities. Complex regions are selected from the label image according to the complexities and the complex regions are masked to obtain a masked label image. The masked label image is input into a preset defect detection model to obtain a second detection result. The preset defect detection model is a YOLOv5 model improved using the focal loss function; The complex region is processed to obtain a processed complex region image. The processed complex region image is then compared and detected with a preset template image to obtain a third detection result. The label image is subjected to label tilt detection to obtain a fourth detection result. Based on the first detection result, the second detection result, the third detection result, and the fourth detection result, the label defect detection result is determined. The region complexity calculation of the label image is performed to obtain various complexities, including: performing convolution smoothing processing on the label image using Gaussian filtering to obtain a smoothed image; calculating the rectangular gradient and direction of the smoothed image to obtain the gradient magnitude; then performing non-maximum suppression operation on each gradient magnitude to obtain a gradient image; and calculating the region complexity of the label image based on the gradient image to obtain various complexities.
2. The label defect detection method according to claim 1, characterized in that, The process of acquiring the label image to be detected includes: All label images are acquired using a preset camera, and a background is added to all the label images to obtain all label images with backgrounds. The label images carrying background panels are segmented according to the region of interest to obtain each label image to be detected.
3. The label defect detection method according to claim 1, characterized in that, The step of performing area defect detection on the label image to obtain a first detection result includes: The label image is compressed to obtain a one-dimensional label image. Then, the one-dimensional label image is subjected to edge background expansion, image binarization, noise point removal and edge detection operations to determine the boundary inflection points and the number of boundary inflection points. Determine whether the number of boundary inflection points is odd. If the number of boundary inflection points is odd, then perform area loss calculation based on the boundary inflection points and using a fitted regular polygon algorithm to obtain a first detection result containing the label area loss region.
4. The label defect detection method according to claim 1, characterized in that, The process of performing image processing on the complex region to obtain a processed complex region image, and comparing the processed complex region image with a preset template image to obtain a third detection result, includes: The complex region is filtered, binarized, and edge detected to obtain a processed complex region image; wherein the processed complex region image is a complex region image or a minimum bounding rectangle image. The processed complex region image is compared with a preset template image using a perceptual hash algorithm to obtain a third detection result.
5. The label defect detection method according to claim 1, characterized in that, The step of performing label tilt detection on the label image to obtain a fourth detection result includes: The processed complex region image is extracted to obtain the center point, and the label boundary vertical line is determined so that the actual position of the label can be determined based on the center point and the label boundary vertical line. Determine whether the actual position of the label has shifted to obtain the fourth detection result.
6. The label defect detection method according to any one of claims 1 to 5, characterized in that, After determining the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result, the method further includes: The determination time of the label defect detection result is obtained, and it is determined whether the determination time is less than a preset time threshold. If the determination time is less than the preset time threshold, a delay compensation operation is performed, and it is determined whether the label defect detection is completed. If the label defect detection is not completed, multi-threading is started to continue the label defect detection until it is completed, and the completion time is recorded. Then, the preset time threshold is modified using the least squares method to obtain a new preset time threshold.
7. A label defect detection device, characterized in that, include: An area defect detection module is used to acquire a label image to be detected and to perform area defect detection on the label image to obtain a first detection result; The complexity calculation module is used to calculate the regional complexity of the label image to obtain various complexities, filter out complex regions from the label image according to the complexities, and mask the complex regions to obtain a masked label image. The masked label image is then input into a preset defect detection model to obtain a second detection result. The preset defect detection model is a YOLOv5 model improved using the focal loss function; The comparison and detection module is used to perform image processing on the complex region to obtain a processed complex region image, and to compare and detect the processed complex region image with a preset template image to obtain a third detection result. The label tilt detection module is used to perform label tilt detection on the label image to obtain a fourth detection result, and to determine the label defect detection result based on the first detection result, the second detection result, the third detection result, and the fourth detection result; The region complexity calculation of the label image is performed to obtain various complexities, including: performing convolution smoothing processing on the label image using Gaussian filtering to obtain a smoothed image; calculating the rectangular gradient and direction of the smoothed image to obtain the gradient magnitude; then performing non-maximum suppression operation on each gradient magnitude to obtain a gradient image; and calculating the region complexity of the label image based on the gradient image to obtain various complexities.
8. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the label defect detection method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the label defect detection method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and device for detecting surface defects of object
CN111696095A
Label defect detection method based on template comparison
CN113850756A