CN117274209B - Bottle body defect detection method, system, medium and electronic equipment - Google Patents
Bottle body defect detection method, system, medium and electronic equipment Download PDFInfo
- Publication number
- CN117274209B CN117274209B CN202311272313.8A CN202311272313A CN117274209B CN 117274209 B CN117274209 B CN 117274209B CN 202311272313 A CN202311272313 A CN 202311272313A CN 117274209 B CN117274209 B CN 117274209B
- Authority
- CN
- China
- Prior art keywords
- line
- position line
- pixel points
- model
- network
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/0002—Inspection of images, e.g. flaw detection
- G06T7/0004—Industrial image inspection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/04—Architecture, e.g. interconnection topology
- G06N3/0464—Convolutional networks [CNN, ConvNet]
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/40—Extraction of image or video features
- G06V10/44—Local feature extraction by analysis of parts of the pattern, e.g. by detecting edges, contours, loops, corners, strokes or intersections; Connectivity analysis, e.g. of connected components
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
- G06V10/762—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using clustering, e.g. of similar faces in social networks
- G06V10/763—Non-hierarchical techniques, e.g. based on statistics of modelling distributions
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
- G06V10/77—Processing image or video features in feature spaces; using data integration or data reduction, e.g. principal component analysis [PCA] or independent component analysis [ICA] or self-organising maps [SOM]; Blind source separation
- G06V10/80—Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level
- G06V10/806—Fusion, i.e. combining data from various sources at the sensor level, preprocessing level, feature extraction level or classification level of extracted features
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V10/00—Arrangements for image or video recognition or understanding
- G06V10/70—Arrangements for image or video recognition or understanding using pattern recognition or machine learning
- G06V10/82—Arrangements for image or video recognition or understanding using pattern recognition or machine learning using neural networks
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/10—Image acquisition modality
- G06T2207/10004—Still image; Photographic image
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20081—Training; Learning
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20084—Artificial neural networks [ANN]
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/30—Computing systems specially adapted for manufacturing
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Software Systems (AREA)
- Evolutionary Computation (AREA)
- Computing Systems (AREA)
- Artificial Intelligence (AREA)
- Health & Medical Sciences (AREA)
- General Health & Medical Sciences (AREA)
- Multimedia (AREA)
- Medical Informatics (AREA)
- Databases & Information Systems (AREA)
- Computational Linguistics (AREA)
- Molecular Biology (AREA)
- General Engineering & Computer Science (AREA)
- Mathematical Physics (AREA)
- Data Mining & Analysis (AREA)
- Life Sciences & Earth Sciences (AREA)
- Biophysics (AREA)
- Biomedical Technology (AREA)
- Probability & Statistics with Applications (AREA)
- Quality & Reliability (AREA)
- Image Analysis (AREA)
Abstract
The invention provides a bottle body defect detection method, a system, a medium and electronic equipment, which comprise the steps of obtaining a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates of boundary frames and corresponding categories, calculating widths and heights of all the boundary frames, clustering by using a K-means++ algorithm according to calculation results to obtain anchor frames, applying the anchor frames obtained by clustering to a configuration file of a YOLOv model, training the YOLOv model by utilizing the training set and the configuration file, obtaining an image to be detected, and detecting the bottle body defect of the image to be detected by using the trained model. The invention adopts a method combining image processing and artificial intelligence, solves the problems of low accuracy, poor robustness and the like of the traditional image processing mode, and obviously improves the accuracy and adaptability of the detection of the defects of the engine oil bottle body.
Description
Technical Field
The invention relates to the technical field of image detection, in particular to a bottle defect detection method, a system, a medium and electronic equipment.
Background
On the body of the container, a series of position lines or graduations are often visible for marking the volume or number of internal objects, typically located on the side or front of the bottle. The presence of the position line enables the user to better and more conveniently grasp the amount and use of the stored object. For the manufacturers of the oil bottles, it is important to ensure that the products with defects in the bottle bodies do not flow into the market, so that the quality and performance of the products can be ensured, the demands of users can be met, the market trust of the users to the brands can be improved, and therefore the defect detection of the bottle bodies is important.
Body inspection generally involves two tasks, position line straightness detection and body flaw point detection. The conventional method for detecting the position line of the bottle body generally adopts an ROI candidate frame to intercept, and detects the position line in a straight line detection mode, while the detection of the flaw point of the bottle body depends on the difference of colors. The traditional bottle body defect detection method is simple and easy to use, but has some limitations. For example, for images in complex background or lighting conditions, selection of candidate boxes and line detection may be affected, resulting in inaccurate detection results.
In addition, the ROI candidate box has a problem of poor robustness. For different shapes and sizes of engine oil bottles, the selection of the appropriate ROI candidate frame requires consideration of the geometry of the bottle body and the relative position of the position lines. If the ROI candidate frame is too small or too large, problems such as inaccurate positioning may occur, and complete information of the position line may not be accurately detected. In addition, the selection of the camera angle may also affect the detection result of the position line, the camera angle is incorrect, for example, deviates from the vertical shooting angle, and the position line may show deformation or perspective effect, so that the straight line detection algorithm cannot accurately identify the characteristics of the position line. Therefore, the traditional algorithm is influenced by the shape and the size of the oil bottle as well as the shooting angle and the shooting position, so that the selection of the ROI candidate frame needs to be continuously adjusted, and the self-adaptive effect cannot be achieved. How to combine innovative technology and method, solve the selection defect of the ROI candidate frame, and the defect detection technology realizing simple operation and efficient operation is the key point of current research.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide a bottle body defect detection method and system.
The bottle body defect detection method provided by the invention comprises the following steps:
the boundary extraction step comprises the steps of obtaining a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates and categories of boundary boxes, and calculating the width and the height of all the boundary boxes;
Clustering by using a K-means++ algorithm according to the calculation result to obtain an anchor frame;
The configuration step is that the anchor frames obtained by clustering are applied to the configuration file of YOLOv model;
Training the YOLOv model by using the training set and the configuration file;
and the detection step is to acquire an image to be detected, and detect the bottle body defect of the image to be detected by using a trained model.
Further, the YOLOv model includes:
The input end is used for preprocessing input data, including Mosaic data enhancement, random cutting, random rotation, random overturning or random brightness adjustment, so as to obtain enhancement data;
A backbone network connected to the input end for extracting the characteristic part of the enhanced data, wherein the backbone network uses CSPDARKNET network and comprises a plurality of CSP modules, each CSP module comprises two continuous convolution layers, a residual error connection layer and a small target detection layer;
The neck network is connected with the main network and used for fusing the characteristic information of different scales, and the neck network adopts BiFPN structures and performs weighted fusion on the characteristic parts of different scales according to the importance of the characteristic parts;
And the head network is connected with the neck network and outputs the detection result as a boundary box and category prediction information.
Further, the method further comprises the following steps:
and a label processing step, converting the training set into an acceptable format.
Further, the clustering step includes:
Step 1, extracting the width and the height of all the sounding boxes in the training set to form a matrix or a list;
step 2, determining the number of clusters, namely the number of anchor frames, according to the requirement;
Step 3, selecting a sample as a first clustering center;
Step 4, calculating the shortest distance between each sample and the currently selected cluster center for the rest samples, and selecting the next cluster center according to the weight of the shortest distance, wherein the probability that the samples with the longer distance are selected as the next cluster center is higher;
step 5, each sample is distributed to the cluster to which the nearest cluster center belongs;
step 6, for each cluster, calculating the average value of all samples in the cluster to be used as a new cluster center;
Step 7, repeating the steps 4 to 6 until the stopping condition is met;
And 8, after the iteration is completed, obtaining final cluster centers, wherein each cluster center represents one cluster, distributing samples to the clusters to which the nearest cluster center belongs, and taking the cluster centers as the standard of an anchor frame.
Further, the step 4 includes:
calculating the shortest distance between each sample and the current clustering center;
calculating the probability of each sample being selected as the next cluster center, wherein 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;
the probability distribution is used to select the next cluster center.
Further, the detecting step includes:
the AI model target processing step comprises the steps of adopting a trained model to detect a position line area of an image to be detected and whether a flaw exists, judging the image to be defective when the flaw exists, and cutting out the position line area when the flaw does not exist;
The image processing step comprises the steps of detecting the edge of a position line by utilizing an edge detection algorithm, obtaining two contour lines of the position line, carrying out color screening to obtain a black background and two white contour lines of the position line, respectively obtaining pixel points of the two contour lines of the position line, processing the pixel points to obtain a middle line between the two contour lines of the position line, obtaining a straight line according to the two pixel points at the head and the tail of the middle line, obtaining the sum of distances from all the pixel points on the middle line to the straight line formed by the two pixel points at the head and the tail of the middle line, judging whether the bending degree of the position line is in a preset range according to the sum of the distances after the distance is obtained, and judging that the position line is good if the bending degree is in the preset range, otherwise judging that the position line is bad.
Further, the image processing step further includes:
And solving the variance of the abscissa of all the pixel points on the central bit line, judging the dispersion of all the pixel points, judging whether the inclination degree of the position line is in a preset range or not according to the dispersion, and if the inclination degree is in the preset range, judging the position line as good, otherwise judging the position line as defective.
According to the invention, a bottle defect detection system comprises:
The boundary extraction module is used for acquiring a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates and categories of boundary boxes, and the width and the height of all the boundary boxes are calculated;
the clustering module is used for clustering by using a K-means++ algorithm according to the calculation result to obtain an anchor frame;
the configuration module is used for applying the anchor frames obtained by clustering to the configuration file of the YOLOv model;
training the YOLOv model by using the training set and the configuration file;
and the detection module is used for acquiring an image to be detected and detecting the bottle body defect of the image to be detected by using the trained model.
According to the present invention, there is provided a computer-readable storage medium storing a computer program which, when executed by a processor, implements the steps of the body defect detection method.
According to the invention, the electronic equipment comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, wherein the computer program realizes the steps of the bottle body defect detection method when being executed by the processor.
Compared with the prior art, the invention has the following beneficial effects:
Compared with the prior art, the method can converge more quickly and obtain better clustering results. The clustering centers are selected by introducing probability weights, so that diversity among samples is increased, and the selection of the initial clustering centers is more robust and accurate.
The invention adopts K-means++ algorithm to select the initial clustering center and improve the clustering effect, thereby enabling the size of the anchor frame selected during the initialization of the network training to be more in line with the size of the real marking frame in the data set. The method is characterized in that a small target detection layer is introduced into a backbone network of a YOLOv model, an improved network starts to fuse an extracted characteristic diagram with deep characteristics from a layer 2 of the backbone network, the improvement mainly aims at solving the problem that an original model is missed due to too small flaw points on the front side of a machine oil bottle and too close flaw point colors and bottle colors, a small target detection layer is added on the basis of the YOLOv model, and the sensitivity of the model to small targets is enhanced by increasing the resolving power of the model to the small characteristics.
The invention adopts a method combining image processing and artificial intelligence, solves the problems of low accuracy, poor robustness and the like of the traditional image processing mode, and obviously improves the accuracy and adaptability of the detection of the defects of the engine oil bottle body.
Drawings
Other features, objects and advantages of the present invention will become more apparent upon reading of the detailed description of non-limiting embodiments, given with reference to the accompanying drawings in which:
FIG. 1 is an overall workflow diagram of a method for detecting a bottle body defect according to the present invention;
FIG. 2 is a flow chart of the detection portion of the present invention;
fig. 3 is a schematic structural diagram of a backbone network;
FIG. 4 is a schematic diagram of the SPP module;
FIG. 5 is a schematic diagram of the structure of the Focus module;
fig. 6 is a schematic structural diagram of a Conv module;
FIG. 7 is a schematic diagram of the structure of the C3 module;
fig. 8 is a schematic diagram of the structure of the neck network.
Detailed Description
The present invention will be described in detail with reference to specific examples. The following examples will assist those skilled in the art in further understanding the present invention, but are not intended to limit the invention in any way. It should be noted that variations and modifications could be made by those skilled in the art without departing from the inventive concept. These are all within the scope of the present invention.
Example 1
As shown in fig. 1, a method for detecting defects of a bottle body includes:
1. Preparing the data set-the data set needs to be prepared first. The data set should contain annotated images and corresponding labels, which typically contain object bounding box coordinates and class information, and secondly the whole data set is divided into training, validation and test sets. The training set is used for training the model, the verification set is used for adjusting the super parameters of the model and selecting the model, and the test set is used for evaluating the performance of the model.
2. And extracting the width and the height of the bounding box, namely traversing all the marked bounding boxes in the training set, and calculating the width and the height of each bounding box.
3. And clustering to obtain an anchor frame, wherein the anchor frame is clustered by using a K-means++ algorithm. In consideration of accuracy and stability for small target detection tasks, in addition, the preset anchor frame YOLOv is generated based on the COCO dataset and is not suitable for an autonomously constructed dataset. Therefore, K-means++ is used for clustering, and a final anchor frame is obtained according to a final clustering result. The cluster center is selected herein as the width and height of the anchor box.
The K-means++ algorithm has a better initial selection strategy, can converge more quickly and obtain a better clustering result. The clustering centers are selected by introducing probability weights, so that diversity among samples is increased, and the selection of the initial clustering centers is more robust and accurate.
The K-means++ algorithm is adopted to select an initial clustering center, and the clustering effect is improved, so that the size of the anchor frame selected during the initialization of the network training is more consistent with the size of the real marking frame in the data set. The method is characterized in that a small target detection layer is introduced into a backbone network of a YOLOv model, an improved network starts to fuse an extracted characteristic diagram with deep characteristics from a layer 2 of the backbone network, the improvement mainly aims at solving the problem that an original model is missed due to too small flaw points on the front side of a bottle body and too close flaw point colors and bottle body colors, a small target detection layer is added on the basis of a YOLOv model, and the sensitivity of the model to the small target is enhanced by increasing the resolving power of the model to the small characteristics.
4. The anchor boxes are applied to the YOLOv model-the resulting anchor boxes are applied to the configuration file of the YOLOv model for a priori box settings in the training or inference process.
5. And (3) training set label processing, namely converting labels into a format acceptable by a model according to the format of the training set, and converting the model into an xml format.
6. Model training-using the prepared training set and model configuration file, training YOLOv the model. The model mainly comprises an input end, a main network, a neck network and a head network, and is respectively responsible for processing an input image, extracting features, fusing features and outputting detection results.
The input processes the input data set, including a series of preprocessing steps. The preprocessing step mainly comprises the steps of Mosaic data enhancement, random cutting, random rotation, random overturning and random brightness adjustment, and a plurality of enhanced training samples can be generated through preprocessing, so that the diversity of the training data is increased, and the generalization capability of the model is improved.
Fig. 3 is a schematic diagram of a backbone network, which is a part of extracting information features of an input image, using CSPDARKNET networks, and the structure includes a plurality of CSP modules, each of which is composed of two consecutive convolution layers and a residual connection. This residual connection facilitates the transfer of gradients and the flow of information, making the network easier to train and optimize. Aiming at the problems that the detection of the tiny blemishes of the body of the engine oil bottle is difficult, and the color of the blemishes is too close to that of the body, the original model is missed, a small target detection layer is added in the model, namely a convolution layer is inserted behind a backbone network CSP module, so that the perception capability of the tiny blemishes is improved. The backbone network processes the input image through a series of convolution layers and pooling layers, gradually extracting high-level semantic features in the image. The convolution and pooling layers capture the context information and local details of the object, helping the model to better understand the image content. Through the feature extraction of a plurality of layers, the backbone network can be gradually enhanced from low-level image features to high-level semantic features, and rich feature representation capability is provided. Fig. 4 is a schematic structural view of the SPP module in fig. 3, fig. 5 is a schematic structural view of the Focus module, fig. 6 is a schematic structural view of the Conv module, and fig. 7 is a schematic structural view of the C3 module.
Fig. 8 is a schematic structural diagram of a neck network, in which the neck network originally adopts PANet structures to fuse feature information of different scales, but features generated by different network levels show obvious differences as the neural network level deepens. In order to improve the accuracy of the model on small target detection and acquire more detail information from high-level features, a BiFPN structure is introduced into the model, and a weighted feature fusion mechanism is introduced into BiFPN, so that the weighted fusion of feature images with different scales can be carried out according to the importance of the feature images, and the quality of the feature images is improved. Each level in BiFPN structure can self-adaptively aggregate the characteristic information from the upper direction and the lower direction, and realize efficient bidirectional cross-scale connection and weighted characteristic diagram fusion.
The head network is responsible for outputting a detection result, and outputting a target detection result in the input image as a boundary box and category prediction information.
7. Model evaluation, namely evaluating the model by using a test set after training.
8. And (3) detecting products, namely acquiring an image to be detected, and detecting bottle body defects of the image to be detected by using a trained model.
As shown in fig. 2, the model returns the identification result of the flaw, the position line, and the coordinate information. If the identification result of the flaw is within the set condition, directly judging that the product is defective; if the identification result of the flaw does not meet the condition, cutting the position line area of the image according to the position line area coordinate information returned by the model, carrying out global threshold processing on the obtained image after cutting, wherein the threshold is selected based on a two-dimensional histogram of the image, and after global threshold segmentation, some tiny noise point distribution exists, small particle noise is removed by adopting open operation, adhesion among partial objects is broken, a clearer position line area is obtained, then, the edge of the position line is detected by utilizing a sobel edge detection algorithm, two contour lines of the position line are obtained, and color screening is carried out to obtain a black background and two white position line contour lines; respectively obtaining pixel points of two white position line outlines, processing the pixel points to obtain a line between the two position line outlines (conveniently understood to be simply called a median line, if the position line is not bent and is straight, the line is similar to the median line between the two position line outlines, but if the position line is bent, the line is similar to the bent median line), then firstly obtaining a straight line according to the two pixel points at the head and the tail of the median line, and obtaining the sum of distances from all the pixel points on the median line to the straight line formed by the two pixel points at the head and the tail of the median line, judging whether the bending degree of the position line is within an acceptable range according to the sum of the distances after the distance is obtained, judging whether the bending degree of the position line is within the acceptable range, otherwise judging the line to be a defective product (because if the bending degree is not large, the straight line formed by the head and the tail of the median line is basically coincident, and the bending degree is large, the two straight lines deviate to a large extent, and the sum of distances is large), but another defect missed detection exists, namely the inclined straight state of the position line and the fourth point below are supplemented, so that another method is needed to supplement, namely the variance solving is carried out on the horizontal coordinates of all the pixel points on the position line, the dispersion degree of all the pixel points is judged, if the position line is in the inclined straight state, the dispersion degree of the horizontal coordinates of all the pixel points on the position line is very large, namely the variance is large, the situation is filtered through the method, and whether the situation is in a good product range or not is judged through the sum of the distances from all the pixel points on the position line to the first pixel points and the last pixel points of the position line and the dispersion value, and if the situation is not in the range, the position line is bent, and the situation is judged to be a bad product.
The above variance solving process includes:
Assuming that the abscissa of all pixels on the median is x 1,x2,x3,…,xn, the variance formula of the group of pixel abscissas is expressed as Where Var (X) represents the variance of the pixel X, Σ represents the summation symbol, xi represents the i-th data point in the pixel X, μ represents the mean of the pixel X, and N represents the number of pixel X.
The AI is used to detect the bottle blemish and the target area of the position line, because in the production line, the acquisition position of the bottle image may not be fixed due to various unstable factors such as sensor triggering and photographing delay, etc., which brings difficulty to the traditional image processing method. On the one hand, the engine oil bottle position line region can be locked by adopting a method based on deep learning, so that the limitation of the position fixability of the ROI frame in the traditional image processing method is overcome. The method based on deep learning not only can automatically identify and lock the position line area, but also can adjust the size of the marking frame according to the distance of the image, can adapt to image acquisition of different distances and angles, and ensures accurate detection of the position line area. The position line area is locked by adopting a method based on deep learning, so that the system for detecting the defects of the body of the oil bottle is more flexible and accurate. The method can effectively cope with the change of the image acquisition position, and provides an accurate target area for the subsequent position line curvature identification.
On the other hand, aiming at the defect type of the bottle body flaw point, the illumination intensity of the industrial environment site is generally unstable, and the acquisition quality of the image is influenced. Second, the photographing angle of the camera is fixed, and the shape of the bottle itself is rugged. In the classical image processing method, the color difference is used to detect the flaw points, so that some flaw points are difficult to be effectively detected in an environment with too strong or too dark illumination. However, the flaw point detection method based on deep learning is not affected by illumination, so long as the method can overcome the difficulty caused by unstable illumination intensity and the shape specificity of the engine oil bottle in the industrial environment on site on a certain distance in the visible area, and a reliable solution is provided for accurate detection of flaw points.
The subsequent recognition of the bending degree of the position line is calculated and detected by using an image processing method, on one hand, because the advanced learning-based AI model has ambiguity on the judgment standard of whether the position line is bent, the advanced learning-based AI model usually needs a large amount of labeling data to train when processing image data so as to learn and distinguish the characteristics of different shapes and modes. However, in the context of curvature assessment of a location line, the decision criteria may be relatively complex or subjective, making it difficult to train the model with extensive labeling data. In contrast, the image processing method can utilize technologies such as geometry, feature extraction and the like to analyze geometric features of the shape of the line, and technologies such as edge detection, contour analysis and the like to identify and judge the bending degree of the line, and can accurately calculate and detect the position line. The two are combined for use, so that the respective advantages can be fully exerted.
When the curvature of the position line is judged, the operation is performed according to the straight line formed by the head and tail pixel points of the middle positions of the two obtained contour lines, on one hand, the pixel points of the middle positions are selected, compared with the pixel points on the two sides or the edge of the position line, the pixel points of the middle positions have stability, and the integral curvature condition of the position line can be reflected more accurately. On the other hand, because in an actual image, two contour lines may be affected by noise, incompleteness after image processing, and the like, a partial region has a discontinuous or inaccurate portion. The pixel points at the first and the last positions in the middle are selected for judgment, so that local inaccuracy can be smoothed and corrected to a certain extent, and the overall curvature judging capability of the position line is improved.
The method comprises the steps of identifying the curvature of a position line, judging the curvature of the position line by two methods, firstly obtaining a straight line according to coordinates of first and last two pixel points on the middle contour line, then calculating the sum of distances from other pixel points on the middle contour line to the straight line, judging whether the position line is curved according to the sum of distances from the point to the straight line, and if another curvature condition is missed only according to the condition, namely that the two contour lines of the position line are inclined and straight, solving variance by using the abscissa of all pixel points of the middle contour line, and judging again according to the discrete degree of the abscissa of the pixel points of the middle contour line, so that the inclined and straight condition of the position line can be enclosed.
Example 2
The invention also provides a bottle body defect detection system which can be realized by executing the flow steps of the bottle body defect detection method, namely, the bottle body defect detection method can be understood as a preferred implementation mode of the bottle body defect detection system by a person skilled in the art.
A bottle defect detection system, comprising:
The boundary extraction module is used for obtaining a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates and categories of boundary boxes, and the width and the height of all the boundary boxes are calculated.
And the clustering module is used for clustering by using a K-means++ algorithm according to the calculation result to obtain an anchor frame.
And a configuration module, wherein the anchor frames obtained by clustering are applied to the configuration file of the YOLOv model.
And a training module for training the YOLOv model by using the training set and the configuration file.
And the detection module is used for acquiring an image to be detected and detecting the bottle body defect of the image to be detected by using the trained model.
Example 3
A bottle body defect detection device comprises a belt conveyor, an industrial personal computer, a PLC, a camera, a light source, a bottle clamping conveyor, a photoelectric sensor, a rejecting mechanism, a motor and the like.
The engine oil bottles are conveyed to the positions of the sensors through the belt conveyor, the sensors trigger the cameras to shoot, after shooting is completed, images are transmitted to the industrial personal computer to be subjected to image analysis and judgment, the industrial personal computer outputs the identification result to the PLC, the PLC sends control signals to the rejection mechanism, and the rejection mechanism performs blowing rejection on unqualified products.
The belt conveyor and the bottle clamping conveyor form a conveying module which is mainly responsible for conveying products to be detected, wherein the products are firstly conveyed through the belt conveyor, pass through an image acquisition area, and then are conveyed to an industrial personal computer for image processing analysis and output to a PLC (programmable logic controller), the PLC sends a control signal to a rejecting mechanism, and the rejecting mechanism rejects unqualified products, so that the aim of product sorting is achieved.
The camera and the light source form an image acquisition module which is responsible for image acquisition, and when the product reaches the position of the sensor, the camera acquires an image and transmits the image to the industrial personal computer for further identification.
In this hardware system, the camera should be fixed in a proper position to ensure that the captured image of the front side of the bottle is complete and can cover the area of the front side of the bottle. In addition, the light source is required to be positioned on the same parallel plane as the camera and is positioned on the right side of the camera and is close to the sensor, and adverse influence factors such as shadows, light reflection and the like can be effectively reduced through the arrangement, uniform illumination conditions are provided, and definition and quality of images are ensured.
The industrial personal computer, the photoelectric sensor, the rejection mechanism and the PLC form a control module which is responsible for the overall operation control of the system. When the belt conveyor transmits the product to the image acquisition module, the photoelectric sensor sends out a signal, the camera starts to acquire images and transmits the images to the industrial personal computer, the industrial personal computer processes the images and transmits the identification result to the PLC, and the PLC sends out instructions to the rejection mechanism according to the signal. The defect recognition algorithm in the industrial personal computer adopts the bottle body defect detection method described in the embodiment 1.
The rejecting mechanism performs blowing rejection on products passing through the bottle clamping conveyor according to the received instructions, and focuses air flow onto the products mainly through the nozzles so as to rapidly and accurately remove defective bottles from the production line.
The cloud server can be used for forming a data storage module, and is mainly used for cloud storage of data, uploading local bottle body defect detection identification data to the cloud, facilitating later analysis and visualization, improving the production flow of products and increasing the yield of the products.
In other embodiments, a computer readable storage medium storing a computer program is provided, which when executed by a processor implements the steps of the method for detecting a bottle body defect.
In other embodiments, an electronic device is provided that includes a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program implementing the steps of the method for detecting a bottle body defect when executed by the processor.
Those skilled in the art will appreciate that the invention provides a system and its individual devices, modules, units, etc. that can be implemented entirely by logic programming of method steps, in addition to being implemented as pure computer readable program code, in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. Therefore, the system and the devices, modules and units thereof provided by the invention can be regarded as a hardware component, and the devices, modules and units for realizing various functions included in the system can be regarded as structures in the hardware component, and the devices, modules and units for realizing various functions can be regarded as structures in the hardware component as well as software modules for realizing the method.
The foregoing describes specific embodiments of the present application. It is to be understood that the application is not limited to the particular embodiments described above, and that various changes or modifications may be made by those skilled in the art within the scope of the appended claims without affecting the spirit of the application. The embodiments of the application and the features of the embodiments may be combined with each other arbitrarily without conflict.
Claims (7)
1. A method for detecting a bottle defect, comprising:
the boundary extraction step comprises the steps of obtaining a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates and categories of boundary boxes, and calculating the width and the height of all the boundary boxes;
Clustering by using a K-means++ algorithm according to the calculation result to obtain an anchor frame;
The configuration step is that the anchor frames obtained by clustering are applied to the configuration file of YOLOv model;
Training the YOLOv model by using the training set and the configuration file;
a detection step, the detection step comprising:
The AI model target processing step comprises the steps of adopting a trained model to detect a position line area of an image to be detected and whether a flaw exists, judging the image to be a defective product if the identification result of the flaw is within a set condition, and cutting out the position line area if the identification result of the flaw does not meet the condition;
The image processing step comprises the steps of carrying out global threshold processing on the cut position line area, wherein the threshold is selected based on a two-dimensional histogram of an image, carrying out global threshold segmentation, adopting open operation to remove particle noise, disconnecting adhesion between partial objects, then utilizing a sobel edge detection algorithm to detect the position line edge, obtaining two contour lines of the position line, carrying out color screening to obtain a black background and two white position line contour lines, respectively obtaining pixel points of the two white position line contour lines, processing the pixel points to obtain a median line between the two position line contour lines, on one hand, solving a straight line according to the two pixel points at the head and the tail of the median line, solving the sum of distances from all pixel points on the median line to the straight line formed by the two pixel points at the head and the tail of the median line, judging whether the bending degree of the position line is in an acceptable range according to the sum of the distances, and if the bending degree of the position line is in the acceptable range, judging the position line is in a defective state, and if the two pixel points on the median line are in the range, judging the straight line is in a state of the fact that the two pixel points on the median line is in a straight line if the two pixel points are in a range of the two-of the range, and if the two pixel points on the median line are in a state of the straight line;
wherein the YOLOv model includes:
An input end;
A backbone network connected to the input end for extracting the characteristic part of the enhanced data, wherein the backbone network uses CSPDARKNET network and comprises a plurality of CSP modules, each CSP module comprises two continuous convolution layers, a residual error connection layer and a small target detection layer;
The neck network is connected with the main network and used for fusing the characteristic information of different scales, and the neck network adopts BiFPN structures and performs weighted fusion on the characteristic parts of different scales according to the importance of the characteristic parts;
And the head network is connected with the neck network and outputs the detection result as a boundary box and category prediction information.
2. The method for detecting a bottle defect according to claim 1, further comprising:
and a label processing step, converting the training set into an acceptable format.
3. The method of claim 1, wherein the step of clustering comprises:
Step 1, extracting the width and the height of all the sounding boxes in the training set to form a matrix or a list;
step 2, determining the number of clusters, namely the number of anchor frames, according to the requirement;
Step 3, selecting a sample as a first clustering center;
Step 4, calculating the shortest distance between each sample and the currently selected cluster center for the rest samples, and selecting the next cluster center according to the weight of the shortest distance, wherein the probability that the samples with the longer distance are selected as the next cluster center is higher;
step 5, each sample is distributed to the cluster to which the nearest cluster center belongs;
step 6, for each cluster, calculating the average value of all samples in the cluster to be used as a new cluster center;
Step 7, repeating the steps 4 to 6 until the stopping condition is met;
And 8, after the iteration is completed, obtaining final cluster centers, wherein each cluster center represents one cluster, distributing samples to the clusters to which the nearest cluster center belongs, and taking the cluster centers as the standard of an anchor frame.
4. A body defect detection method according to claim 3, wherein step 4 comprises:
calculating the shortest distance between each sample and the current clustering center;
calculating the probability of each sample being selected as the next cluster center, wherein 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;
the probability distribution is used to select the next cluster center.
5. A bottle defect detection system, comprising:
The boundary extraction module is used for acquiring a training set, wherein the training set comprises images of a bottle body and labels, the labels comprise coordinates and categories of boundary boxes, and the width and the height of all the boundary boxes are calculated;
the clustering module is used for clustering by using a K-means++ algorithm according to the calculation result to obtain an anchor frame;
the configuration module is used for applying the anchor frames obtained by clustering to the configuration file of the YOLOv model;
training the YOLOv model by using the training set and the configuration file;
a detection module, the detection module comprising:
AI model target processing, namely detecting a position line area of an image to be detected and whether a flaw exists by adopting a trained model, judging the image to be defective if the identification result of the flaw is within a set condition, and cutting out the position line area if the identification result of the flaw does not meet the condition;
The image processing comprises the steps of performing global threshold processing on the cut position line area, selecting a threshold value based on a two-dimensional histogram of an image, performing global threshold segmentation, removing particle noise by adopting open operation, breaking adhesion between partial objects, detecting the edge of the position line by using a sobel edge detection algorithm, obtaining two contour lines of the position line, and performing color screening to obtain a black background and two white position line contour lines; on one hand, solving a straight line according to the two pixel points at the head and the tail of the middle line, solving the sum of the distances from all the pixel points on the middle line to the straight line formed by the two pixel points at the head and the tail of the middle line, judging whether the bending degree of the position line is in an acceptable range or not according to the sum of the distances after the distance is solved, judging the position line is good or not, otherwise, judging the position line is bad, on the other hand, solving the variance of the transverse coordinates of all the pixel points on the middle line, judging the dispersion of all the pixel points, filtering the situation if the position line is in an oblique state, judging whether the position line is in the range or not according to the sum of the distances from all the pixel points on the middle line to the straight line formed by the two pixel points at the head and the tail of the middle line and the dispersion value, and judging whether the position line is in the range or not if the position line is not in the range;
wherein the YOLOv model includes:
An input end;
A backbone network connected to the input end for extracting the characteristic part of the enhanced data, wherein the backbone network uses CSPDARKNET network and comprises a plurality of CSP modules, each CSP module comprises two continuous convolution layers, a residual error connection layer and a small target detection layer;
The neck network is connected with the main network and used for fusing the characteristic information of different scales, and the neck network adopts BiFPN structures and performs weighted fusion on the characteristic parts of different scales according to the importance of the characteristic parts;
And the head network is connected with the neck network and outputs the detection result as a boundary box and category prediction information.
6. A computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the steps of the bottle defect detection method of any one of claims 1 to 4.
7. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the computer program when executed by the processor implements the steps of the method for detecting a bottle defect according to any one of claims 1 to 4.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311272313.8A CN117274209B (en) | 2023-09-27 | 2023-09-27 | Bottle body defect detection method, system, medium and electronic equipment |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202311272313.8A CN117274209B (en) | 2023-09-27 | 2023-09-27 | Bottle body defect detection method, system, medium and electronic equipment |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN117274209A CN117274209A (en) | 2023-12-22 |
| CN117274209B true CN117274209B (en) | 2025-05-13 |
Family
ID=89214000
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202311272313.8A Active CN117274209B (en) | 2023-09-27 | 2023-09-27 | Bottle body defect detection method, system, medium and electronic equipment |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN117274209B (en) |
Families Citing this family (4)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119006874B (en) * | 2024-06-21 | 2025-10-17 | 丰巢网络技术有限公司 | Clothes identification method, device, equipment and medium |
| CN120726272A (en) * | 2025-05-12 | 2025-09-30 | 鞍山市安泰安全技术有限公司 | A belt tear detection model and its construction method |
| CN120708202B (en) * | 2025-06-13 | 2026-01-27 | 四川星问数智科技有限公司 | Wine bottle type detection system and detection method based on image recognition |
| CN120495308B (en) * | 2025-07-18 | 2025-10-21 | 海豚乐智科技(成都)有限责任公司 | Dead pixel detection method and system combining space domain analysis and time domain analysis |
Family Cites Families (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN105259252B (en) * | 2015-10-15 | 2018-09-21 | 浙江大学 | Ultrasonic phase array detects polyethylene electric-melting connector defect type automatic identifying method |
| CN111661590B (en) * | 2020-06-08 | 2021-10-26 | 天地(常州)自动化股份有限公司 | Method for detecting tearing damage of conveying belt of mining belt conveyor |
| CN113688723B (en) * | 2021-08-21 | 2024-03-19 | 河南大学 | A pedestrian target detection method in infrared images based on improved YOLOv5 |
-
2023
- 2023-09-27 CN CN202311272313.8A patent/CN117274209B/en active Active
Non-Patent Citations (2)
| Title |
|---|
| "基于YOLOv5s 改进的机油瓶表面缺陷检测方法";李文辰等;《计算机测量与控制》;20240913;第1-12页 * |
| "机油瓶表面缺陷智能检测方法研究与实现";张亚慧;《中国优秀硕士学位论文全文数据库》;20240312;第1-72页 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN117274209A (en) | 2023-12-22 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN117274209B (en) | Bottle body defect detection method, system, medium and electronic equipment | |
| CN109816644B (en) | An automatic detection system for bearing defects based on multi-angle light source images | |
| CN107617573B (en) | Logistics code identification and sorting method based on multitask deep learning | |
| Anagnostopoulos et al. | A license plate-recognition algorithm for intelligent transportation system applications | |
| CN113592845A (en) | Defect detection method and device for battery coating and storage medium | |
| CN104866862B (en) | A kind of method of belt steel surface area-type defect recognition classification | |
| CN115082683A (en) | Injection molding defect detection method based on image processing | |
| CN109550712A (en) | A kind of chemical fiber wire tailfiber open defect detection system and method | |
| CN113221889A (en) | Anti-interference recognition method and device for chip characters | |
| CN107389701A (en) | A kind of PCB visual defects automatic checkout system and method based on image | |
| CN114972356B (en) | Plastic product surface defect detection and identification method and system | |
| CN105809121A (en) | Multi-characteristic synergic traffic sign detection and identification method | |
| CN111695373B (en) | Zebra stripes positioning method, system, medium and equipment | |
| CN113077450B (en) | Cherry grading detection method and system based on deep convolutional neural network | |
| CN116228678A (en) | Automatic identification and processing method of chip packaging defects | |
| CN120355688B (en) | A machine vision-based intelligent detection method and system for surface defects of artificial boards | |
| CN117214178A (en) | Intelligent identification method for appearance defects of package on packaging production line | |
| WO2022227103A1 (en) | Intelligent detection and mark system and method for parts | |
| CN114445707A (en) | Intelligent visual fine detection method for defects of bottled water labels | |
| CN119722588A (en) | A circuit board defect detection system based on machine learning | |
| CN117092129A (en) | A product label detection method based on machine vision multi-level features | |
| CN111950556A (en) | A detection method of number plate printing quality based on deep learning | |
| CN119784754A (en) | Electronic device inspection system based on computer vision | |
| CN111950357A (en) | A fast identification method of marine debris based on multi-feature YOLOV3 | |
| KR20190119801A (en) | Vehicle Headlight Alignment Calibration and Classification, Inspection of Vehicle Headlight Defects |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |