Bottle defect detection method, system, medium and electronic equipment

Through the improvement of K-Means++ clustering and YOLOv5 model, the accuracy and robustness of traditional detection methods under complex conditions are solved, and more efficient and flexible bottle defect detection is achieved.

CN117274209BActive Publication Date: 2025-05-13SHANGHAI SECOND POLYTECHNIC UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311272313.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-27
Publication Date
2025-05-13
Estimated Expiration
2043-09-27

AI Technical Summary

Technical Problem

The traditional bottle defect detection method has inaccurate detection results under complex background or lighting conditions. The ROI candidate box is poorly selected, making it difficult to adapt to oil bottles of different shapes and sizes, and is greatly affected by the shooting angle.

Method used

The K-Means++ algorithm is used for clustering, and the anchor box is obtained, and it is applied to the configuration file of the YOLOv5 model. Combined with Mosaic data enhancement and small object detection layer, the model's resolution ability of small features is improved.

Benefits of technology

The accuracy and robustness of clustering results are improved, the sensitivity of the model to small targets is enhanced, and the accuracy and adaptability of oil bottle body defect detection is significantly improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117274209B_ABST
    Figure CN117274209B_ABST
Patent Text Reader

Abstract

The present invention provides a bottle body defect detection method, system, medium and electronic device, including: obtaining a training set, the training set including an image and a label of the bottle body, the label including the coordinates of the bounding box and the corresponding category, and calculating the width and height of all bounding boxes; clustering using the K-Means++ algorithm according to the calculation result to obtain an anchor box; applying the anchor box obtained by clustering to the configuration file of the YOLOv5 model; training the YOLOv5 model using the training set and the configuration file; obtaining an image to be detected, and using the trained model to perform bottle body defect detection on the image to be detected. The present invention adopts a method combining image processing and artificial intelligence, solves the problems of low accuracy and poor robustness of traditional image processing methods, and significantly improves the accuracy and adaptability of oil bottle body defect detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image detection technology, and in particular to a bottle body defect detection method, system, medium and electronic equipment. Background Art

[0002] On the container bottle, you can often see a series of position lines or scales to mark the capacity or quantity of the internal objects, which are usually located on the side or front of the bottle. The existence of position lines allows users to better and more conveniently grasp the amount and dosage of the stored objects. For motor oil bottle manufacturers, it is crucial to ensure that products with defects in the bottle do not enter the market. This can not only ensure the quality and performance of the product and meet the needs of users, but also enhance the market trust of users in the brand. Therefore, it is crucial to detect defects in the bottle.

[0003] Bottle inspection generally includes two tasks: position line straightness detection and bottle defect point detection. Among them, the traditional bottle position line detection method usually uses ROI candidate frame interception and uses straight line detection to detect the position line, while the bottle defect point detection relies on color difference for detection. Although the traditional bottle defect detection method is simple and easy to use, it also has some limitations. For example, for images with complex backgrounds or lighting conditions, the selection of candidate frames and straight line detection may be affected, resulting in inaccurate detection results.

[0004] In addition, the ROI candidate frame has the problem of poor robustness. For oil bottles of different shapes and sizes, the selection of a suitable ROI candidate frame needs to consider the geometric shape of the bottle body and the relative position of the position line. If the ROI candidate frame is too small or too large, problems such as inaccurate positioning may occur, and the complete information of the position line may not be accurately detected. In addition, the choice of camera angle will also affect the detection results of the position line. If the camera angle is incorrect, such as deviating from the vertical shooting angle, the position line may appear deformed or perspective, resulting in the straight line detection algorithm being unable to accurately identify the characteristics of the position line. Therefore, the traditional algorithm is affected by the shape, size, shooting angle and position of the oil bottle, which leads to the need for continuous adjustment of the selection of the ROI candidate frame and the inability to achieve adaptive effects. How to combine innovative technologies and methods to solve the drawbacks of ROI candidate frame selection and realize defect detection technology with simple operation and efficient operation is the focus of current research. Summary of the invention

[0005] In view of the defects in the prior art, an object of the present invention is to provide a bottle defect detection method and system.

[0006] A bottle defect detection method provided by the present invention comprises:

[0007] Boundary extraction step: obtaining a training set, the training set including the image and label of the bottle body, the label including the coordinates and category of the bounding box, and calculating the width and height of all bounding boxes;

[0008] Clustering step: Based on the calculation results, use the K-Means++ algorithm to perform clustering and obtain anchor boxes;

[0009] Configuration steps: Apply the clustered anchor boxes to the configuration file of the YOLOv5 model;

[0010] Training step: training the YOLOv5 model using the training set and the configuration file;

[0011] Detection step: obtain the image to be detected, and use the trained model to perform bottle body defect detection on the image to be detected.

[0012] Furthermore, the YOLOv5 model includes:

[0013] At the input end, the input data is preprocessed, including mosaic data enhancement, random cropping, random rotation, random flipping or random brightness adjustment, to obtain enhanced data;

[0014] A backbone network is connected to the input end to extract the feature part of the enhanced data. The backbone network uses a CSPDarknet53 network and includes multiple CSP modules. Each CSP module includes two consecutive convolutional layers, a residual connection layer, and a small target detection layer.

[0015] The neck network is connected to the backbone network and fuses feature information of different scales. The neck network uses a BiFPN structure and performs weighted fusion of feature parts of different scales according to the importance of the feature parts.

[0016] The head network is connected to the neck network and outputs the detection results as bounding boxes and category prediction information.

[0017] Furthermore, it also includes:

[0018] Label processing step: convert the training set into an acceptable format.

[0019] Furthermore, the clustering step includes:

[0020] Step 1: Extract the width and height of all bounding boxes in the training set and form a matrix or list;

[0021] Step 2: Determine the number of clusters, that is, the number of anchor boxes, as needed;

[0022] Step 3: Select a sample as the first cluster center;

[0023] Step 4: For the remaining samples, calculate the shortest distance between each sample and the currently selected cluster center, and select the next cluster center according to the weight of the shortest distance. The farther the distance, the higher the probability of being selected as the next cluster center.

[0024] Step 5: Assign each sample to the cluster to which its closest cluster center belongs;

[0025] Step 6: For each cluster, calculate the average value of all samples in the cluster as the new cluster center;

[0026] Step 7: Repeat steps 4 to 6 until the stop condition is met;

[0027] Step 8: After the iteration is completed, the final cluster center is obtained. Each cluster center represents a cluster. The samples are assigned to the cluster to which the nearest cluster center belongs, and these cluster centers are used as the benchmarks of the anchor boxes.

[0028] Further, the step 4 comprises:

[0029] Calculate the shortest distance between each sample and the current cluster center;

[0030] Calculate the probability of each sample being selected as the next cluster center. The probability calculation is to normalize the shortest distance between each sample and the selected cluster center to obtain the probability distribution of the distance;

[0031] Use a probability distribution to select the next cluster center.

[0032] Furthermore, the detection step includes:

[0033] AI model target processing steps: Use the trained model to detect the position line area of ​​the image to be detected and whether there are defect points. If there are defect points, it is determined to be a defective product. If there are no defect points, the position line area is cropped out;

[0034] Image processing steps: Use edge detection algorithm to detect the edge of the position line, obtain two contour lines of the position line, and then perform color screening to obtain a black background and two white contour lines of the position line; obtain pixel points of the two position line contours respectively, process the pixel points to obtain the median line between the two position line contours, obtain a straight line based on the two pixel points at the beginning and end of the median line, and calculate the sum of the distances from all pixel points on the median line to the straight line formed by the two pixel points at the beginning and end of the median line. After the distance is calculated, determine whether the curvature of the position line is within the preset range based on the sum of the distances. If it is within the preset range, it is judged as a good product, otherwise it is judged as a defective product.

[0035] Furthermore, the image processing step further includes:

[0036] The variance of the horizontal coordinates of all pixel points on the median line is solved to determine the discreteness of all pixel points. Based on the discreteness, it is determined whether the inclination of the position line is within the preset range. If it is within the preset range, it is determined to be a good product, otherwise it is determined to be a defective product.

[0037] A bottle defect detection system provided by the present invention comprises:

[0038] Boundary extraction module: obtain a training set, the training set includes bottle images and labels, the labels include the coordinates and categories of the bounding boxes, and calculate the width and height of all bounding boxes;

[0039] Clustering module: Based on the calculation results, use the K-Means++ algorithm to perform clustering and obtain anchor boxes;

[0040] Configuration module: Apply the clustered anchor boxes to the configuration file of the YOLOv5 model;

[0041] Training module: training the YOLOv5 model using the training set and the configuration file;

[0042] Detection module: obtain the image to be detected, and use the trained model to perform bottle body defect detection on the image to be detected.

[0043] According to a computer-readable storage medium storing a computer program provided by the present invention, the steps of the bottle body defect detection method are implemented when the computer program is executed by a processor.

[0044] An electronic device provided according to the present invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the steps of the bottle body defect detection method are implemented when the computer program is executed by the processor.

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

[0046] Compared with the prior art, the present invention can converge faster and obtain better clustering results. It introduces probability weights to select cluster centers, thereby increasing the diversity between samples and making the selection of initial cluster centers more robust and accurate.

[0047] The present invention adopts K-Means++ algorithm to select the initial cluster center, improves the clustering effect, and makes the size of the anchor frame selected when the network training is initialized more consistent with the size of the real label frame in the data set. A small target detection layer is introduced into the backbone network of the YOLOv5 model. The improved network starts to fuse the extracted feature map with the deep features from the second layer of the backbone network. The improvement in this part is mainly aimed at the problem that the defect point on the front side of the oil bottle is too small and the color of the defect point is too close to the color of the bottle body, which leads to the original model missing detection. A small target detection layer is added on the basis of the YOLOv5 model, and the model's sensitivity to small targets is enhanced by increasing the model's ability to resolve small features.

[0048] The present invention adopts a method that combines image processing with artificial intelligence, which solves the problems of low accuracy and poor robustness of traditional image processing methods, and significantly improves the accuracy and adaptability of oil bottle body defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0050] Figure 1 The overall workflow diagram of the bottle body defect detection method of the present invention;

[0051] Figure 2 It is a flow chart of the detection part of the present invention;

[0052] Figure 3 A schematic diagram of the structure of the backbone network;

[0053] Figure 4 It is a structural diagram of the SPP module;

[0054] Figure 5 This is a schematic diagram of the structure of the Focus module;

[0055] Figure 6 It is a structural diagram of the Conv module;

[0056] Figure 7 It is a schematic diagram of the structure of the C3 module;

[0057] Figure 8 Schematic diagram of the neck network structure. DETAILED DESCRIPTION

[0058] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.

[0059] Example 1

[0060] like Figure 1 As shown, a bottle defect detection method includes:

[0061] 1. Prepare the dataset: First, you need to prepare the dataset. The dataset should contain annotated images and corresponding labels. The labels usually contain the coordinates of the object's bounding box and category information. Secondly, divide the entire dataset into training set, validation set, and test set. The training set is used to train the model, the validation set is used to adjust the model's hyperparameters and perform model selection, and the test set is used to evaluate the model's performance.

[0062] 2. Extract bounding box width and height: Traverse all the annotated bounding boxes in the training set and calculate the width and height of each bounding box.

[0063] 3. Perform clustering and obtain anchor boxes: Use K-Means++ algorithm for clustering. Considering the accuracy and stability of small target detection tasks, in addition, the preset anchor boxes of YOLOv5 are generated based on the COCO dataset and are not suitable for self-constructed datasets. Therefore, K-Means++ is used for clustering, and the final anchor box is obtained based on the final clustering results. This paper selects the cluster center as the width and height of the anchor box.

[0064] The K-Means++ algorithm has a better initial selection strategy, which can converge faster and obtain better clustering results. It introduces probability weights to select cluster centers, thereby increasing the diversity among samples and making the selection of initial cluster centers more robust and accurate.

[0065] The K-Means++ algorithm is used to select the initial cluster center to improve the clustering effect, so that the size of the anchor box selected during network training initialization is more consistent with the size of the real label box in the data set. A small target detection layer is introduced into the backbone network of the YOLOv5 model. The improved network starts to fuse the extracted feature map with the deep features from the second layer of the backbone network. This part of the improvement is mainly aimed at the problem that the defect point on the front side of the bottle is too small and the color of the defect point is too close to the color of the bottle body, which leads to the original model missing detection. A small target detection layer is added on the basis of the YOLOv5 model to increase the model's ability to resolve small features, thereby enhancing the model's sensitivity to small targets.

[0066] 4. Apply the anchor box to the YOLOv5 model: Apply the obtained anchor box to the configuration file of the YOLOv5 model for setting the prior box during training or inference.

[0067] 5. Training set label processing: According to the format of the training set, the labels are converted into a format acceptable to the model. This model is converted into .xml format.

[0068] 6. Model training: Use the prepared training set and model configuration file to train the YOLOv5 model. The model mainly consists of four parts: input end, backbone network, neck network and head network, which are responsible for input image processing, feature extraction, feature fusion and detection result output respectively.

[0069] The input end processes the input data set, including a series of preprocessing steps. The preprocessing steps mainly include mosaic data enhancement, random cropping, random rotation, random flipping, and random brightness adjustment. Through preprocessing, multiple enhanced training samples can be generated to increase the diversity of training data and improve the generalization ability of the model.

[0070] Figure 3 The schematic diagram of the backbone network structure is the part that extracts the information features of the input image. The CSPDarknet53 network is used. The structure contains multiple CSP modules, each of which consists of two consecutive convolutional layers and a residual connection. This residual connection helps the transfer of gradients and the flow of information, making the network easier to train and optimize. In view of the difficulty in detecting tiny defects on the body of the motor oil bottle and the problem that the color of the defect is too close to the color of the bottle body, which leads to the original model missing the detection, this model adds a small target detection layer, that is, inserting a convolutional layer after the backbone network CSP module to increase the perception of tiny defects. The backbone network processes the input image through a series of convolutional layers and pooling layers, and gradually extracts high-level semantic features in the image. The convolutional layers and pooling layers capture the contextual information and local details of the target, helping the model to better understand the image content. Through multiple levels of feature extraction, the backbone network can gradually enhance from low-level image features to high-level semantic features, providing rich feature representation capabilities. Figure 4 for Figure 3 The structural diagram of the SPP module in Figure 5 This is a schematic diagram of the structure of the Focus module. Figure 6 It is a structural diagram of the Conv module. Figure 7 This is a schematic diagram of the structure of the C3 module.

[0071] Figure 8The figure is a schematic diagram of the neck network structure. The neck network originally used the PANet structure to fuse feature information of different scales, but as the neural network layer deepens, the features generated by different network layers show obvious differences. In order to improve the accuracy of the model in detecting small targets and obtain more detailed information from high-level features, this model introduces the BiFPN structure. BiFPN introduces a weighted feature fusion mechanism, which can perform weighted fusion of feature maps of different scales according to the importance of feature maps, thereby improving the quality of feature maps. Each level in the BiFPN structure can adaptively aggregate feature information from both the upper and lower directions, realizing efficient bidirectional cross-scale connection and weighted feature map fusion.

[0072] The head network is responsible for outputting the detection results, which output the object detection results in the input image as bounding boxes and category prediction information.

[0073] 7. Model evaluation: After training is completed, use the test set to evaluate the model.

[0074] 8. Product inspection: Obtain the image to be inspected, and use the trained model to detect bottle body defects on the image to be inspected.

[0075] like Figure 2As shown, the model will return the identification results of defect points, position lines and coordinate information. If the identification result of the defect point is within the set conditions, the product is directly determined to be a defective product; if the identification result of the defect point does not meet the conditions, the image is cropped according to the coordinate information of the position line area returned by the model, and the image is subjected to global threshold processing after cropping. The threshold is selected based on the two-dimensional histogram of the image. After global threshold segmentation, there are some fine noise distributions. The opening operation is used to remove small particle noise, disconnect the adhesion between some objects, and obtain a clearer position line area. Then, the sobel edge detection algorithm is used to detect the edge of the position line to obtain two contour lines of the position line, and then color screening is performed to obtain a black background and two white position line contour lines; the pixel points of the two white position line contours are obtained respectively, and the above pixel points are processed to obtain a line located between the two position line contours (for convenience, it is referred to as the median line. If the position line is not curved and is straight, it is similar to the median line between the two position line contours, but if the position line is curved, it is similar to the curved median line); next, a line is obtained based on the two pixel points at the beginning and end of the median line Straight line, and calculate the sum of the distances from all the pixels on the median line to the straight line formed by the first and last two pixels of the median line. After the distances are calculated, it is judged whether the curvature of the position line is within the acceptable range according to the sum of the distances. If it is within the acceptable range, it is judged as a good product, otherwise it is judged as a defective product (because if the curvature is not large, the median line and the straight line formed by the first and last two pixels of the median line are basically overlapped, and the large curvature will lead to a large deviation of the two straight lines and a large sum of the distances). However, this will result in another defect being missed, that is, the oblique straightness of the position line. The fourth point has a supplement, so another method is needed to supplement it: on the other hand, the variance of the horizontal coordinates of all pixels on the median line is solved to determine the discreteness of all pixels. If the position line is oblique and straight, the discreteness of the horizontal coordinates of all pixels on the median line is very large, that is, the variance is very large, so this method is used to filter out this situation; by judging the sum of the distances from all pixels on the median line to the straight line formed by the first and last two pixels of the median line and the discrete value, it is judged whether it is within the range of good products. If it is not within the range, the position line is bent and it is judged as a defective product.

[0076] The above variance solution process includes:

[0077] Assume that the horizontal coordinates of all pixels on the median line are x 1 ,x 2 ,x 3 ,…,x n , then the variance formula of the horizontal coordinates of this group of pixels is expressed as Where Var(X) represents the variance of the horizontal coordinate X of the pixel point, Σ represents the summation symbol, Xi represents the i-th data point in the horizontal coordinate of the pixel point, μ represents the mean of the horizontal coordinate of the pixel point, and N represents the number of horizontal coordinates of the pixel point.

[0078] AI is used to detect bottle body defect points and position line target areas because in the production line, due to various unstable factors such as sensor triggering and camera delay, the acquisition position of the bottle image may not be fixed, which brings difficulties to traditional image processing methods. The deep learning-based method can lock the position line area of ​​the engine oil bottle on the one hand, thereby overcoming the limitation of the fixed position of the ROI frame in the traditional image processing method. The deep learning-based method can not only automatically identify and lock the position line area, and adjust the size of the annotation frame according to the distance of the image, but also adapt to image acquisition at different distances and angles to ensure accurate detection of the position line area. The deep learning-based method is used to lock the position line area, making the engine oil bottle body defect detection system more flexible and accurate. Regardless of how the image acquisition position changes, this method can effectively respond and provide an accurate target area for subsequent position line curvature identification.

[0079] On the other hand, for the defect type of bottle body defects, the light intensity in industrial environments is usually unstable, which will affect the quality of image acquisition. Secondly, the camera's shooting angle is fixed, while the shape of the bottle itself is uneven. In the classic image processing method, color differences are used to detect defects, so some defects are difficult to be effectively detected in environments with too strong or too dark light. However, the defect point detection method based on deep learning is not affected by light. As long as it is in the visible area, it can overcome the difficulties caused by the unstable light intensity in industrial environments and the particularity of the shape of the oil bottle to a certain extent, providing a reliable solution for the accurate detection of defects.

[0080] The subsequent recognition of the curvature of the position line is calculated and detected using image processing methods. On the one hand, this is because the AI ​​model based on deep learning has ambiguity in the judgment criteria for whether the position line is curved. When processing image data, the AI ​​model based on deep learning usually requires a large amount of labeled data for training to learn to distinguish the features of different shapes and patterns. However, in judging the curvature of the position line, the judgment criteria may be relatively complex or subjective, and it is difficult to train the model through large-scale labeled data. In contrast, image processing methods can use techniques such as geometry and feature extraction to analyze the geometric features of the shape of the line, as well as edge detection and contour analysis to identify and judge the curvature of the line, and accurately calculate and detect the position line. Combining the two can give full play to their respective advantages.

[0081] When judging the curvature of the position line, the operation is performed based on the straight line formed by the first and last pixel points in the middle position of the two contour lines. On the one hand, the pixel points in the middle position are more stable than the pixel points on both sides or edges of the position line, and can more accurately reflect the overall curvature of the position line. On the other hand, in the actual image, the two contour lines may be affected by noise, incomplete image processing, etc., resulting in discontinuous or inaccurate parts in the local area. By selecting the pixel points at the first and last positions in the middle for judgment, the local inaccuracy can be smoothed and corrected to a certain extent, thereby improving the ability to judge the overall curvature of the position line.

[0082] Two methods are used to identify the curvature of the position line. First, a straight line is obtained based on the coordinates of the first and last two pixel points on the middle contour line. Then the sum of the distances from the remaining pixel points on the middle contour line to the straight line is calculated. The sum of the distances from the points to the straight line is used to determine whether the position line is curved. However, if only this one condition is used, another curvature situation will be missed, that is, the two contours of the position line are oblique and straight. In this case, we use the horizontal coordinates of all the pixel points on the middle contour line to solve the variance, and make another judgment based on the discrete degree of the horizontal coordinates of the pixel points on the middle contour, which can cover the situation where the position line appears oblique and straight.

[0083] Example 2

[0084] The present invention also provides a bottle body defect detection system, which can be implemented by executing the process steps of the bottle body defect detection method, that is, those skilled in the art can understand the bottle body defect detection method as a preferred implementation of the bottle body defect detection system.

[0085] A bottle defect detection system, comprising:

[0086] Boundary extraction module: obtain a training set, the training set includes images and labels of the bottle body, the labels include the coordinates and categories of the bounding boxes, and calculate the width and height of all bounding boxes.

[0087] Clustering module: Based on the calculation results, K-Means++ algorithm is used for clustering to obtain anchor boxes.

[0088] Configuration module: Apply the clustered anchor boxes to the configuration file of the YOLOv5 model.

[0089] Training module: train the YOLOv5 model using the training set and the configuration file.

[0090] Detection module: obtain the image to be detected, and use the trained model to perform bottle body defect detection on the image to be detected.

[0091] Example 3

[0092] A bottle body defect detection device comprises a belt conveyor, an industrial computer, a PLC, a camera, a light source, a bottle clamping conveyor, a photoelectric sensor, a rejection mechanism, a motor and the like.

[0093] The oil bottle is transported to the sensor position through a belt conveyor. The sensor triggers the camera to take pictures. After the shooting is completed, the image is transmitted to the industrial computer for image analysis and judgment. The industrial computer outputs the recognition result to the PLC, and the PLC sends the control signal to the rejection mechanism, which blows and removes unqualified products.

[0094] The belt conveyor and bottle clamping conveyor constitute the conveying module, which is mainly responsible for transmitting the products to be inspected: the products are first conveyed by the belt conveyor, pass through the image acquisition area, and transmit the acquired images to the industrial computer for image processing and analysis and output the results to the PLC. The PLC sends the control signal to the rejection mechanism, and the rejection mechanism rejects the unqualified products, thereby achieving the purpose of product sorting.

[0095] The camera and light source constitute the image acquisition module, which is responsible for image acquisition. When the product reaches the sensor position, the camera captures the image and transmits it to the industrial computer for the next step of identification.

[0096] In this hardware system, the camera should be fixed in a suitable position to ensure that the image of the front side of the oil bottle is complete and covers the entire area of ​​the front side of the oil bottle. In addition, the light source should be in the same parallel plane as the camera and located on the right side of the camera, close to the sensor. This setting can effectively reduce adverse factors such as shadows and reflections, provide uniform lighting conditions, and ensure image clarity and quality.

[0097] The industrial computer, photoelectric sensor, rejection mechanism, and PLC constitute a control module, which is responsible for the overall operation control of the system. When the belt conveyor transfers the product to the image acquisition module, the photoelectric sensor sends a signal, the camera starts to collect images and transmits them to the industrial computer, the industrial computer processes the image and transmits the recognition results to the PLC, and the PLC dispatches instructions to the rejection mechanism according to the signal. The defect recognition algorithm in the industrial computer adopts the bottle body defect detection method described in Example 1.

[0098] The rejection mechanism blows air to reject the products passing through the bottle clamping conveyor according to the instructions received, mainly by focusing the airflow on the product through the nozzle to quickly and accurately remove defective bottles from the assembly line.

[0099] Cloud servers can also be used to form data storage modules, which are mainly used for cloud storage of data. Local bottle defect detection and identification data can be uploaded to the cloud for later analysis and visualization, which can be used to improve product production processes and increase product yields.

[0100] In other embodiments, a computer-readable storage medium storing a computer program is provided, and when the computer program is executed by a processor, the steps of the bottle defect detection method are implemented.

[0101] In other embodiments, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the bottle defect detection method when executed by the processor.

[0102] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.

[0103] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.

Claims

1. A bottle defect detection method, characterized in that: include: Boundary extraction step: obtaining a training set, the training set including the image and label of the bottle body, the label including the coordinates and category of the bounding box, and calculating the width and height of all bounding boxes; Clustering step: Based on the calculation results, use the K-Means++ algorithm to perform clustering and obtain anchor boxes; Configuration steps: Apply the clustered anchor boxes to the configuration file of the YOLOv5 model; Training step: training the YOLOv5 model using the training set and the configuration file; A detection step, the detection step comprising: AI model target processing steps: Use the trained model to detect the position line area of ​​the image to be detected and whether there are defect points. If the recognition result of the defect point is within the set conditions, it is judged as a defective product. If the recognition result of the defect point does not meet the conditions, the position line area is cropped out; Image processing steps: perform global threshold processing on the cropped position line area, the threshold is selected based on the two-dimensional histogram of the image, and after global threshold segmentation, the particle noise is removed by opening operation, the adhesion between some objects is disconnected, and then the edge of the position line is detected by the Sobel edge detection algorithm to obtain two contour lines of the position line, and then color screening is performed to obtain a black background and two white position line contour lines; respectively obtain the pixel points of the two white position line contours, and process the above pixel points to obtain the median line between the two position line contours; on the one hand, a straight line is obtained according to the two pixel points at the beginning and end of the median line, and the Take the sum of the distances from all the pixels on the median line to the straight line formed by the first and last two pixels of the median line. After the distances are calculated, judge whether the curvature of the position line is within the acceptable range based on the sum of the distances. If it is within the acceptable range, it is judged as a good product, otherwise it is judged as a defective product. On the other hand, solve the variance of the horizontal coordinates of all the pixels on the median line to judge the discreteness of all the pixels. If the position line is oblique and straight, filter out the situation. Judge whether the sum of the distances from all the pixels on the median line to the straight line formed by the first and last two pixels of the median line and the discrete value are within the range of good products. If not, the position line is bent and judged as a defective product. Wherein, the YOLOv5 model includes: Input terminal; A backbone network is connected to the input end to extract the feature part of the enhanced data. The backbone network uses a CSPDarknet53 network and includes multiple CSP modules. Each CSP module includes two consecutive convolutional layers, a residual connection layer, and a small target detection layer. The neck network is connected to the backbone network and fuses feature information of different scales. The neck network uses a BiFPN structure and performs weighted fusion of feature parts of different scales according to the importance of the feature parts. The head network is connected to the neck network and outputs the detection results as bounding boxes and category prediction information.

2. The bottle defect detection method according to claim 1, characterized in that: Also includes: Label processing step: convert the training set into an acceptable format.

3. The bottle defect detection method according to claim 1, characterized in that: The clustering steps include: Step 1: Extract the width and height of all bounding boxes in the training set and form a matrix or list; Step 2: Determine the number of clusters, that is, the number of anchor boxes, as needed; Step 3: Select a sample as the first cluster center; Step 4: For the remaining samples, calculate the shortest distance between each sample and the currently selected cluster center, and select the next cluster center according to the weight of the shortest distance. The farther the distance, the higher the probability of being selected as the next cluster center. Step 5: Assign each sample to the cluster to which its closest cluster center belongs; Step 6: For each cluster, calculate the average value of all samples in the cluster as the new cluster center; Step 7: Repeat steps 4 to 6 until the stop condition is met; Step 8: After the iteration is completed, the final cluster center is obtained. Each cluster center represents a cluster. The samples are assigned to the cluster to which the nearest cluster center belongs, and these cluster centers are used as the benchmarks of the anchor boxes.

4. The bottle defect detection method according to claim 3, characterized in that: The step 4 comprises: Calculate the shortest distance between each sample and the current cluster center; Calculate the probability of each sample being selected as the next cluster center. The probability calculation is to normalize the shortest distance between each sample and the selected cluster center to obtain the probability distribution of the distance; Use a probability distribution to select the next cluster center.

5. A bottle defect detection system, characterized in that: include: Boundary extraction module: obtain a training set, the training set includes bottle images and labels, the labels include the coordinates and categories of the bounding boxes, and calculate the width and height of all bounding boxes; Clustering module: Based on the calculation results, use the K-Means++ algorithm to perform clustering and obtain anchor boxes; Configuration module: Apply the clustered anchor boxes to the configuration file of the YOLOv5 model; Training module: training the YOLOv5 model using the training set and the configuration file; A detection module, the detection module comprising: AI model target processing: Use the trained model to detect the position line area of ​​the image to be detected and whether there are defect points. If the recognition result of the defect point is within the set conditions, it is judged as a defective product. If the recognition result of the defect point does not meet the conditions, the position line area is cropped out; Image processing: Perform global threshold processing on the cropped position line area. The threshold is selected based on the two-dimensional histogram of the image. After global threshold segmentation, the opening operation is used to remove particle noise, disconnect the adhesion between some objects, and then use the Sobel edge detection algorithm to detect the edge of the position line to obtain the two contour lines of the position line. Then, color screening is performed to obtain the black background and two white position line contour lines; the pixel points of the two white position line contours are obtained respectively, and the above pixel points are processed to obtain the median line between the two position line contours; on the one hand, a straight line is obtained according to the two pixel points at the beginning and end of the median line, and the The sum of the distances from all the pixels on the median line to the straight line formed by the first and last two pixels of the median line. After the distances are calculated, the sum of the distances is used to determine whether the curvature of the position line is within an acceptable range. If it is within the acceptable range, it is judged as a good product, otherwise it is judged as a defective product. On the other hand, the variance of the horizontal coordinates of all the pixels on the median line is solved to determine the discreteness of all the pixels. If the position line is oblique and straight, this situation is filtered out. By determining the sum of the distances from all the pixels on the median line to the straight line formed by the first and last two pixels of the median line and the discrete value, it is determined whether it is within the range of good products. If it is not within the range, the position line is bent and it is judged as a defective product. Wherein, the YOLOv5 model includes: Input terminal; A backbone network is connected to the input end to extract the feature part of the enhanced data. The backbone network uses a CSPDarknet53 network and includes multiple CSP modules. Each CSP module includes two consecutive convolutional layers, a residual connection layer, and a small target detection layer. The neck network is connected to the backbone network and fuses feature information of different scales. The neck network uses a BiFPN structure and performs weighted fusion of feature parts of different scales according to the importance of the feature parts. The head network is connected to the neck network and outputs the detection results as bounding boxes and category prediction information.

6. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the bottle defect detection method according to any one of claims 1 to 4 are implemented.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the computer program is executed by a processor, the steps of the bottle defect detection method according to any one of claims 1 to 4 are implemented.