Bottle cap defect detection method and system based on artificial intelligence
Through the artificial intelligence-based bottle cap detection method, the hierarchical feature extractor and the mixed Gaussian discrimination module are used to solve the problems of scarcity of defect samples and low model recognition accuracy in traditional detection methods, achieve efficient bottle cap anomaly detection, and reduce The false detection rate and labor cost are reduced.
Patent Information
- Application Number
- CN202410548544.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-06
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-05-06
AI Technical Summary
In the bottle cap manufacturing process, traditional image processing algorithms have slow detection speeds, complex operations, and poor generalization. They also rely on manual detection, which is subjective and costly. This results in a sparse number of defect samples, low model recognition accuracy, and inability to effectively detect small defects. Target flaws.
Adopting an artificial intelligence-based bottle cap detection method, through a hierarchical feature extractor and a mixed Gaussian discriminant module, the EfficientNetV1 pre-trained network and Gaussian mixture model are used for pixel-by-pixel probability density estimation, combined with robust covariance determinant and minimum robust Mahalanobis distance Calculation to achieve abnormal detection of bottle caps and reduce missed detection and misdetection of small target defects.
There is no need to manually label abnormal samples, which reduces labor and time costs, improves the generalization ability of the model, enhances the learning ability of multi-modal features of normal samples, effectively reduces the probability of false detection, and improves the recognition of multiple abnormal forms. Accuracy.
Smart Images

Figure CN118657974A
Abstract
Description
Technical Field
[0001] The invention relates to a bottle cap defect detection method and system based on artificial intelligence, and relates to the field of industrial product manufacturing detection. Background Art
[0002] The industrial manufacturing sector attaches great importance to the quality pass rate of products. In the production process of industrial products, every part is crucial. Problems in any link may lead to substandard product quality, which in turn affects the availability of the product. Especially in the bottle cap manufacturing process, if there are defects such as scratches, missing meat, stains, etc., it will directly affect product quality and sales, and even cause food safety accidents, leading to unforeseen consequences. Traditional image processing algorithms have slow detection speeds and need to design corresponding algorithms for each defect. The operation is complex and the generalization is poor. In addition, some defects rely on professional detection and have a certain degree of subjectivity.
[0003] When detecting bottle cap defects based on supervised deep learning methods, a large number of abnormal defect samples are required. However, supervised learning has some problems. First, on the actual production line, the number of defect samples is scarce and the acquisition cost is high. Usually, defect samples need to be manually produced, but it is impossible to fully simulate the characteristics of real defect samples, resulting in insufficient learning of the network model during training. When image samples that have not been learned in the training set appear, the model recognition accuracy is low. Second, supervised learning requires all abnormal samples to be labeled before network training. In the task of bottle cap anomaly detection, the number of defect samples is often as high as tens of thousands, and manual labeling is prone to errors, and there are problems such as low efficiency and long time consumption. The unsupervised anomaly detection model that has emerged in recent years effectively avoids the tediousness of manual labeling, but the distribution of normal samples on the production line is variable, and the existing model cannot fully learn the feature distribution relationship, resulting in a large number of false detections of positive samples, and the model has a worrying detection rate for small target defects. Therefore, the unsupervised anomaly detection model has not been applied in the industrial scenario of bottle cap anomaly detection. Summary of the invention
[0004] The purpose of the present invention is to overcome the problems in the prior art, such as small number of defective samples, high acquisition cost, low model recognition accuracy, etc., and to provide a bottle cap detection method and system based on artificial intelligence:
[0005] The objective of the present invention is achieved through the following technical solutions:
[0006] A bottle cap detection method based on artificial intelligence comprises the following steps:
[0007] S1. Take images of bottle caps in the production plant, build a bottle cap dataset, and perform corresponding preprocessing methods on the dataset;
[0008] S2. Input the preprocessed and enhanced normal image into the MGAD network model to obtain the learned positive sample feature distribution; the MGAD model includes: using a hierarchical feature extractor to extract the convolutional last layer features of the 3rd, 4th and 5th modules of the pre-trained network EfficientNetV1 and inputting them into the distribution learning stage; integrating the Gaussian mixture model (GMM) strategy in the mixed Gaussian discriminant module to perform pixel-by-pixel probability density estimation, designing a weight allocation mechanism to give the same proportion of extraction probability to different categories of feature distributions, and fully considering the morphological appearance of various normal samples; introducing the robust covariance determinant (MCD) method to calculate and save the Gaussian distribution of positive samples, and realizing bottle cap anomaly detection through the minimum robust Mahalanobis distance calculation method in the inference calculation;
[0009] S3. Input the image to be detected into the bottle cap anomaly detection model MGAD to obtain an anomaly segmentation map of the relevant image.
[0010] Furthermore, in the step S1, the data set is subjected to a corresponding preprocessing method, and the image preprocessing method includes:
[0011] The image is corrected for the bottle cap posture according to the bottle cap LOGO area; the corrected bottle cap image is cropped for the bottle cap area through template matching.
[0012] Furthermore, the specific steps of correcting the bottle cap posture of the image according to the bottle cap LOGO area are as follows:
[0013] An image is randomly selected from the bottle cap dataset, and the LOGO area of the bottle cap is framed to obtain the shape features of the bottle cap; after the LOGO area is selected, the template matching algorithm is used to match the LOGO area with the entire image to be processed to find the area most similar to the template; in the template matching process, the algorithm used is:
[0014]
[0015] in, and are the pixel values of the template area and the image area respectively; the rigid transformation is described by the combination of rotation matrix and translation vector to correct the position and posture of the bottle cap image; firstly, the difference between the shape model and the image center of gravity is calculated to determine the translation vector :
[0016]
[0017] in, and Represent the center of gravity of the shape model, and Represents the center of gravity of the image; the rotation matrix is obtained by calculating the difference between the angle of the shape model and the angle of the image :
[0018]
[0019] in, is the angle difference between the shape model and the image;
[0020] Finally, by combining the translation vector and the rotation matrix, we get the complete rigid transformation parameters relative to the image:
[0021]
[0022] Through this process, the image is accurately rotated, so that the image is accurately adjusted and positioned according to the position and angle information of the shape model while keeping its shape and content unchanged.
[0023] In this way, the rotation and translation transformations are completed for each image according to the above operations to achieve the alignment of the bottle cap LOGO.
[0024] Furthermore, the corrected bottle cap image is used for bottle cap area cropping through template matching. Specifically, based on the normalized cross correlation (NCC) template matching principle, a template image is first selected from the bottle cap data set, and two circular contours are selected along the outer and inner sides of the bottle cap in the image, and the circular contour at the middle junction is subtracted as a matching template. The local features of the template image are extracted and the pixel value of each feature point is calculated to create an NCC model; in the template matching process, the corrected bottle cap image is matched with the created NCC model; specifically, the NCC matching operation is performed on the corrected image, and the similarity between the image and the template is calculated at each position. This similarity is measured by comparing the correlation between the pixel values of the template image and the image to be matched at each position; the NCC algorithm aligns the template image and the image to be matched, compares them at different positions, and then finds the position where the correlation is maximized as the best matching position; for a given template image and the image to be matched , the NCC matching operation calculation formula is:
[0025]
[0026] in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched, respectively. The larger the value of, the more similar the two images are;
[0027] By performing NCC-based template matching, the position most similar to the template can be accurately found in the rectified bottle cap image, thereby achieving precise positioning of the bottle cap area; finally, based on the matching results, the bottle cap area can be cropped out to complete the area extraction operation of the bottle cap image.
[0028] Furthermore, the preprocessed and enhanced normal image is input into the MGAD network model to obtain the learned positive sample feature distribution and calculate the abnormality score, including:
[0029] The preprocessed image is input into the hierarchical feature extractor, and three middle-level convolutional feature maps are selected. , , Combining input hierarchical feature concatenation module ) becomes the embedding vector :
[0030]
[0031] in, It is a hierarchical feature concatenation module, which operates through a sliding window Preprocess the feature map to ensure consistent dimensions; The operation algorithm is:
[0032]
[0033] Said Operation Pair Feature Map Resampling and region extraction are performed to achieve scale and dimension consistency; the processed feature maps are connected in series Forming the embedding vector , the algorithm is:
[0034]
[0035] Among them, each To resize and normalize the feature maps, the concatenation operation generates a comprehensive feature representation by stacking these feature maps; the feature map set obtained by the pre-trained neural network It constitutes a multi-level feature expression of the input image from local detail structure information to global semantic structure.
[0036] Furthermore, the Gaussian mixture model (GMM) strategy is integrated in the mixed Gaussian discriminant module (MGD) to perform pixel-by-pixel probability density estimation, and the feature set extracted from N training images in the cth channel at a specific position (i, j) of the image is The analysis is performed and it is assumed to follow a mixture distribution consisting of several single Gaussian distributions;
[0037] Features Group distribution , represents the different distribution of the current features; among them, represents the mth distribution, whose probability distribution is given by the following formula:
[0038]
[0039] in, represents the probability of the mth Gaussian distribution being selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively. The entire GMM is expressed as A linear combination of single Gaussian distributions, namely:
[0040]
[0041] in, Represents the probability distribution of GMM;
[0042] If there is a set of feature data , the goal is to construct the likelihood function L, which represents the probability of the observed data occurring under the current distribution; specifically, the likelihood function is constructed as follows:
[0043]
[0044] Calculate the posterior probability to get the probability that each point comes from each Gaussian distribution for:
[0045]
[0046] Under the premise of the maximum likelihood function, by Taking the derivative and setting it equal to 0, we get for:
[0047]
[0048] For variables Derivative, through the constraints using Lagrange method to find the maximum formula is:
[0049]
[0050] According to the large value, we can get The algorithm is:
[0051]
[0052] By changing the variable Taking the derivative and setting it equal to 0, we get for:
[0053]
[0054] Introducing boundary threshold , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution. is a set of k means, judging for all and , whether it satisfies:
[0055]
[0056] in: Respectively represent the elements in the set S, represents the absolute difference between two elements, that is, their distance. and When the difference between When established, this paper believes that the two means represent two independent Gaussian distributions in the data, and the algorithm is:
[0057]
[0058]
[0059] On the contrary, if the above formula is satisfied, it means that the two means represent a single Gaussian distribution; in this case, choose the one with a larger weight The Gaussian distribution of the position The representative is:
[0060]
[0061] Shared Satisfy on the channel Group mixed Gaussian distribution, set a distribution number threshold ,like , then the feature of the pixel at (i, j) is a mixed Gaussian distribution.
[0062] Furthermore, in the core set selection stage, the feature set is filtered by MGD. is used in the MCD method; it is necessary to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum:
[0063]
[0064] Among them, the sample proportion parameter Decided from The proportion of samples selected from the core set ;
[0065] In the robust covariance estimation stage, we calculate The sample mean on and the covariance matrix , the estimation reflects the statistical characteristics of the selected subset and is used for the subsequent calculation of the anomaly score. The algorithm is:
[0066]
[0067]
[0068] Furthermore, when calculating the covariance matrix When , a regularization term I (identity matrix) and regularization parameter Ensure that it is full rank and reversible;
[0069] Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, robust Mahalanobis distance Calculated as:
[0070]
[0071] At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Sub-robust Mahalanobis distance, defining the minimum distance as the anomaly score :
[0072]
[0073] Then normalize the Mahalanobis distance to the interval [0,255], and the algorithm is:
[0074]
[0075] Finally, the anomaly score of each pixel in the test image is calculated to determine the anomaly location.
[0076] In some embodiments, a method performed by a computer system is disclosed for implementing one or more functions.
[0077] According to some embodiments, a computing system includes a processor and a memory storing instructions, which when executed cause one or more processors to perform the methods described herein. According to some embodiments, an electronic device includes one or more processors, and a memory storing one or more programs; the one or more programs are configured to be executed by the one or more processors, and the one or more programs include instructions for performing or causing the operations of any method described herein to be performed.
[0078] The beneficial effects of the present invention are:
[0079] 1. Only normal images are needed for training without collecting abnormal images. There is no need to annotate training samples at the pixel level, which reduces manpower and time costs, can identify multiple abnormal forms, and enhances the generalization ability of the model.
[0080] 2. A hierarchical feature extractor was designed, using the EfficientNetV1 model as a pre-trained network, extracting the features of the 3rd, 4th, and 5th convolutional layers as network input, and using the representation capabilities of each layer of the convolutional neural network to model the Gaussian space, fully understanding the semantic information of the image and reducing the missed detection of small target defects;
[0081] 3. In the feature learning stage, block processing is adopted, a mixed Gaussian discriminant module is proposed, and the Gaussian mixture model (GMM) strategy is integrated to perform pixel-by-pixel probability density estimation. A weight distribution mechanism is designed to emphasize the role of low-frequency features in Gaussian space, thereby enhancing the model's ability to learn the multimodal features of normal samples and effectively reducing the probability of false detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] Figure 1 The rotation positioning original image based on shape template matching provided in the embodiment of the present invention;
[0083] Figure 2 A schematic diagram of a template based on shape template matching provided in an embodiment of the present invention;
[0084] Figure 3 The target original image based on shape template matching provided by the embodiment of the present invention;
[0085] Figure 4 A schematic diagram of a target after rotation based on shape template matching provided in an embodiment of the present invention;
[0086] Figure 5 A schematic diagram of a bottle cap positioning template based on ncc template matching provided in an embodiment of the present invention;
[0087] Figure 6A schematic diagram of a bottle cap positioning target after positioning based on ncc template matching provided in an embodiment of the present invention;
[0088] Figure 7 A framework diagram of the artificial intelligence-based anomaly detection model MGAD provided in an embodiment of the present invention;
[0089] Figure 8 A framework diagram of a DFE hierarchical feature extractor provided in an embodiment of the present invention;
[0090] Fig. 9 A schematic diagram of pixel-by-pixel Gaussian distribution provided by an embodiment of the present invention;
[0091] Fig.10 This is a diagram of anomaly detection results provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0092] The technical solution of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0093] See also Figure 1 , select the LOGO area of the bottle cap to obtain the shape features of the bottle cap. After selecting the LOGO area, Figure 2 , using the template matching algorithm, the LOGO area is matched with the entire image to be processed to find the area that is most similar to the template. During the template matching process, the algorithm used can calculate the matching score according to the following formula:
[0094]
[0095] in, and Represent the pixel values of the template area and the image area respectively. Then, the combination of the rotation matrix and the translation vector is used to describe the rigid transformation to correct the position and posture of the bottle cap image. First, the difference between the shape model and the image center of gravity is calculated to determine the translation vector:
[0096]
[0097] in, and Represent the center of gravity of the shape model, and Indicates the center of gravity of the image.
[0098] Second, the rotation matrix is obtained by calculating the difference between the angle of the shape model and the angle of the image:
[0099]
[0100] in, Represents the angular difference between the shape model and the image.
[0101] Finally, by combining the translation vector and the rotation matrix, we get the complete rigid transformation parameters:
[0102]
[0103] in, Represents the rigid transformation parameters of the shape model relative to the image. Through this process, the image is accurately rotated, so that the image is accurately adjusted and positioned according to the position and angle information of the shape model while keeping the shape and content unchanged.
[0104] In this way, Figure 3 As shown, we perform the rotation and translation transformation on each image according to the above operations to achieve Figure 4 The bottle cap logo alignment image is shown.
[0105] Furthermore, the rectified bottle cap image is used to crop the bottle cap region through template matching. Specifically, based on the normalized cross correlation (NCC) template matching principle, a template image is first selected from the bottle cap dataset, such as Figure 5 As shown, two circular contours are selected along the outer and inner sides of the bottle cap in the image, and the circular contour at the middle junction is selected as the matching template. The local features of the template image are extracted and the pixel value of each feature point is calculated to create an NCC model. In the template matching process, the corrected bottle cap image is matched with the created NCC model. Specifically, the NCC matching operation is performed on the corrected image, and the similarity between the image and the template is calculated at each position. This similarity is measured by comparing the correlation between the pixel values of the template image and the image to be matched at each position. The NCC algorithm aligns the template image and the image to be matched, compares them at different positions, and then finds the position where the correlation is maximized as the best matching position. For a given template image and the image to be matched , the NCC calculation formula is as follows:
[0106]
[0107] in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched, respectively. The larger the value of , the more similar the two images are.
[0108] By performing NCC-based template matching, the position most similar to the template can be accurately found in the rectified bottle cap image, thereby achieving precise positioning of the bottle cap area. Finally, based on the matching results, the bottle cap area can be cropped, such as Figure 6 As shown, the region extraction operation on the bottle cap image is completed.
[0109] Further, in step S2, the normal image after preprocessing and enhancement is input into Figure 7 In the MGAD network model shown, the learned positive sample feature distribution is obtained and the anomaly score is calculated. Figure 7 (a) is a deep feature extractor, which connects the input image into a multi-layer feature vector through a pre-trained network. (b) represents the feature distribution of the training image, which consists of a single Gaussian and a mixed Gaussian distribution. (c) The mixed Gaussian discriminant module (MGD) is used to identify the number of distributions. (d) The robust mean and covariance are calculated based on the MCD algorithm and saved as the MCD distribution matrix. The test image is extracted through DFS, passed to the MMAHS module in (e) and the MCD distribution matrix to calculate the minimum robust Mahalanobis distance, and the output is an anomaly map. Specifically include:
[0110] a. Input the preprocessed image into a hierarchical feature extractor, such as Figure 8 As shown, three mid-level convolutional feature maps are selected , , Combining input hierarchical feature concatenation module ) becomes the embedding vector :
[0111]
[0112] in, Represents a hierarchical feature concatenation module, operated by a sliding window Preprocess the feature map to ensure consistent dimensions. Operations can be defined as:
[0113]
[0114] It represents the feature map Resampling and region extraction are performed to achieve scale and dimension consistency. The processed feature maps are connected in series Forming the embedding vector ,Right now:
[0115]
[0116] Among them, each To resize and normalize the feature maps, the concatenation operation generates a comprehensive feature representation by stacking these feature maps.
[0117] A collection of feature maps obtained through pre-trained neural networks It constitutes a multi-level feature expression of the input image from local detail structure information to global semantic structure.
[0118] b. Figure 7 As shown in (c), the Gaussian mixture model (GMM) strategy is integrated in the mixed Gaussian discriminant module (MGD) to perform pixel-by-pixel probability density estimation, as shown in Fig. 9 As shown, the feature set extracted from N training images in the cth channel at a specific image position (i, j) is The analysis is performed and it is assumed that it follows a mixture distribution composed of several single Gaussian distributions.
[0119] Features Group distribution , represents the different distribution of the current features. Among them, represents the mth distribution, whose probability distribution is given by the following formula:
[0120]
[0121] In the above formula, represents the probability of the mth Gaussian distribution being selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively. The entire GMM is expressed as A linear combination of single Gaussian distributions, namely:
[0122]
[0123] in, Represents the probability distribution of GMM;
[0124] Now there is a set of feature data , the goal is to construct a likelihood function L, which represents the probability of the observed data occurring under the current distribution. Specifically, the likelihood function is constructed as follows:
[0125]
[0126] This can be done by calculating the posterior probability to get the likelihood that each point came from each Gaussian distribution:
[0127]
[0128] Under the premise of the maximum likelihood function, by Taking the derivative and setting it equal to 0, we get Right now:
[0129]
[0130] Likewise for variables Derivative, use the Lagrange method to find the maximum formula through the constraints:
[0131]
[0132] According to the large value, we can get The calculation formula is as follows:
[0133]
[0134] Similarly, by changing the variable Taking the derivative and setting it equal to 0, we can get Right now:
[0135]
[0136] In this process, a boundary threshold is introduced , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution. is a set of k means, judging for all and , whether it satisfies:
[0137]
[0138] in: Respectively represent the elements in the set S, represents the absolute difference between two elements, that is, their distance. and When the difference between When established, this paper believes that the two means represent two independent Gaussian distributions in the data, namely:
[0139]
[0140]
[0141] On the contrary, if the above formula is satisfied, it means that the two means represent a single Gaussian distribution. In this case, this paper chooses the one with a larger weight The Gaussian distribution of is used as the representative of this position, that is:
[0142]
[0143] Shared Satisfy on the channel Group mixed Gaussian distribution, set a distribution number threshold ,like , this paper believes that the feature of the pixel at (i, j) is a mixed Gaussian distribution.
[0144] c. In the core set selection stage, the feature set after MGD screening is used in the MCD method. It is necessary to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum:
[0145]
[0146] Among them, the sample proportion parameter Decided from The proportion of samples selected to form the core set .
[0147] In the robust covariance estimation stage, we calculate The sample mean on and the covariance matrix ,These estimates reflect the statistical properties of the selected subset and are used in the subsequent calculation of anomaly scores.
[0148]
[0149]
[0150] In calculating the covariance matrix When , a regularization term I (identity matrix) and regularization parameter Make sure it is full rank and reversible.
[0151] Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, the robust Mahalanobis distance is calculated as follows:
[0152]
[0153] At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Subrobust Mahalanobis distance, defining the minimum distance as the anomaly score:
[0154]
[0155] Next, the Mahalanobis distance is normalized to the interval [0,255], denoted as:
[0156]
[0157] Fig.10 Shown from left to right are: original image, anomaly score heat map, mixture of original image and heat map, binary segmentation result, and original image segmentation result. In the heat map, blue to red indicates the severity of the anomaly.
[0158] The above is only a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present invention, and should be within the scope of protection of the claims attached to the present invention.
Claims
1. A bottle cap defect detection method based on artificial intelligence, It is characterized in that The following steps are involved: S1. Take images of bottle caps in the production plant, build a bottle cap dataset, and preprocess the dataset; S2. Input the preprocessed and enhanced normal image into the MGAD network model to obtain the learned positive sample feature distribution; wherein, the MGAD model includes: using a hierarchical feature extractor to extract the convolutional last layer features of the 3rd, 4th, and 5th modules of the pre-trained network EfficientNetV1 and inputting them into the distribution learning stage; integrating the Gaussian mixture model GMM strategy in the mixed Gaussian discriminant module to perform pixel-by-pixel probability density estimation, designing a weight allocation mechanism to give the same proportion of extraction probability to different categories of feature distributions, according to the morphological appearance of normal samples; introducing the robust covariance determinant MCD method to calculate and save the Gaussian distribution of positive samples, and realizing bottle cap anomaly detection through the minimum robust Mahalanobis distance calculation method; S3. Input the image to be detected into the bottle cap anomaly detection model MGAD to obtain an anomaly segmentation map of the image.
2. The bottle cap defect detection method based on artificial intelligence according to claim 1, It is characterized in that In the step S1, the data set is preprocessed accordingly, and the image preprocessing is: the image is corrected for the bottle cap posture according to the bottle cap LOGO area, and the bottle cap area is cropped by template matching on the corrected bottle cap image.
3. The bottle cap defect detection method based on artificial intelligence according to claim 2, It is characterized in that The specific steps of correcting the bottle cap posture according to the bottle cap LOGO area of the image are as follows: An image is selected from the bottle cap data set, and the LOGO area of the bottle cap is framed to obtain the shape features of the bottle cap; after the LOGO area is selected, the LOGO area is matched with the entire image to be processed by using a template matching algorithm to find the area most similar to the template; In the template matching process Score, the algorithm used is: ; in, and are the pixel values of the template area and the image area respectively; Use a combination of rotation matrix and translation vector to describe the rigid transformation to correct the position of the bottle cap image; first calculate the difference between the shape model and the image center of gravity to determine the translation vector : and Represent the center of gravity of the shape model, and Represents the center of gravity of the image; by calculating the difference between the angle of the shape model and the angle of the image , get the rotation matrix , Combine the translation vector and the rotation matrix to get the complete rigid transformation parameters relative to the image , the algorithm is: 。 4. The bottle cap defect detection method based on artificial intelligence according to claim 3, It is characterized in that The bottle cap region is cropped by using template matching on the corrected bottle cap image. Specifically, a template image is selected from the bottle cap data set, and local features and pixel values of each feature point are extracted; an NCC model is created, and an NCC matching operation is performed on the corrected image to calculate the similarity between the image and the template, wherein: For the template image, is the image to be matched, and the NCC matching operation calculation formula is: ; in, represents the pixel value of the template image, Indicates that the image to be matched is at position The pixel value at and Represent the average pixel values of the template image and the image to be matched respectively.
5. The bottle cap defect detection method based on artificial intelligence according to claim 1, It is characterized in that In step S2, the normal image after preprocessing and enhancement is input into the MGAD network model to obtain the learned positive sample feature distribution and calculate the abnormality score. The specific steps include: The preprocessed image is input into the hierarchical feature extractor, and three middle-layer convolutional feature maps are selected and combined to input into the hierarchical feature concatenation module. Become an embedding vector; the hierarchical feature concatenation module operates through a sliding window Preprocess the feature map to ensure consistent dimensions.
6. The bottle cap defect detection method based on artificial intelligence according to claim 5, It is characterized in that In step S2, the Gaussian mixture model GMM strategy is integrated in the mixed Gaussian discriminant module MGD to perform pixel-by-pixel probability density estimation, and the feature set extracted from N training images in the cth channel at a specific position (i, j) of the image is The analysis is performed and it is assumed to follow a mixture distribution consisting of several single Gaussian distributions; Features Group distribution , represents the different distribution of the current features; among them, represents the mth distribution, whose probability distribution is given by the following formula: ; in, represents the probability of the mth Gaussian distribution being selected, represents the probability density function of the mth Gaussian distribution, and are the mean vector and covariance matrix of the distribution respectively, and the entire GMM is expressed as A linear combination of single Gaussian distributions, namely: ; in, Represents the probability distribution of GMM; If there is a set of feature data , the goal is to construct the likelihood function L, which represents the probability of the observed data occurring under the current distribution; the likelihood function is constructed as: ; Calculate the posterior probability to get the probability that each point comes from each Gaussian distribution for: ; Under the premise of the maximum likelihood function, by Taking the derivative and setting it equal to 0, we get for: ; For variables Derivative, through the constraints using Lagrange method to find the maximum formula is: ; According to the large value, we can get The algorithm is: ; By changing the variable Taking the derivative and setting it equal to 0, we get for: ; Introducing boundary threshold , the auxiliary GMM algorithm will not misclassify a single Gaussian distribution as a mixed Gaussian distribution. is a set of k means, judging for all and , whether it satisfies: ; in: Respectively represent the elements in the set S, Represents the absolute difference between two elements, that is, their distance; when two means and When the difference between When it holds, the two means represent two independent Gaussian distributions in the data, and the algorithm is: ; ; If satisfied, indicate and The mean is represented by a single Gaussian distribution, so the one with a larger weight is selected The Gaussian distribution of the position The representative algorithm is: ; Shared Satisfy on the channel Group mixed Gaussian distribution, set a distribution number threshold ,like , then the feature of the pixel at (i, j) is a mixed Gaussian distribution.
7. The bottle cap defect detection method based on artificial intelligence according to claim 6, It is characterized in that In step S2, in the core set selection stage, the feature set after MGD screening It was used in the MCD method; Need to find a subset ,Depend on The sample consists of a proportion of , so that its covariance determinant is Minimum: ; Among them, the sample proportion parameter Decided from The proportion of samples selected from the core set ; In the robust covariance estimation stage, we calculate The sample mean on and the covariance matrix , the algorithm is: ; 。 8. The bottle cap defect detection method based on artificial intelligence according to claim 7, It is characterized in that In calculating the covariance matrix When using a regularization term I and regularization parameter Ensure that it is full rank and reversible; Based on robust feature set , calculate the Mahalanobis distance to measure the feature points of the test sample and normal distribution The distance between them, robust Mahalanobis distance The algorithm is: ; At each pixel (i, j), if there is Heavy Gaussian distribution, calculation Sub-robust Mahalanobis distance, defining the minimum distance as the anomaly score , the algorithm is: ; Then normalize the Mahalanobis distance to the interval [0,255], and the algorithm is: ; Finally, the anomaly score of each pixel in the test image is calculated to determine the anomaly location.
9. An artificial intelligence-based bottle cap defect detection system, It is characterized in that The system is used to perform the method according to any one of claims 1-8.
10. A readable storage medium storing instructions, It is characterized in that The instructions, when executed by one or more processors of a machine, cause the processors to perform a method according to any one of claims 1-8.
Citation Information
Patent Citations
Industrial product surface defect detection method based on deep learning and Gaussian mixture
CN113421223A
Industrial product appearance anomaly detection method and system based on two-stage learning
CN114862857A
Hybrid industrial part defect detection algorithm
CN115222650A
Surface defect detection method based on deep learning and global difference information
CN116228754A
Industrial packaging bottle cap production defect visual detection method based on lightweight improved YOLOv5s
CN116485715A
Cited By
Deep learning method and system for printed circuit board defect identification
CN119399563A
Deep learning method and system for printed circuit board defect recognition
CN119399563B
Visual detection system and detection method for abnormal light transmission defect of camera hole
CN120525881A
