A method and system for visually detecting defects in food packaging bottles

By calculating the gradient amplitude discreteness, scratch difference index and curvature volatility coefficient of the surface of food packaging bottles, combined with the significance index, the accurate detection of convex defects is achieved, and the high misjudgment rate and calculation in traditional methods are solved. The problem of low efficiency improves the accuracy and robustness of the detection.

CN118864468BActive Publication Date: 2024-12-31XIAN FOUNDER PLASTIC PROD MFG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411345246.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-26
Publication Date
2024-12-31
Estimated Expiration
2044-09-26

AI Technical Summary

Technical Problem

The small convex defects on food packaging bottles are difficult to accurately detect, resulting in poor detection accuracy. Traditional methods are easily affected by light in image processing, resulting in high misjudgment rate and low calculation efficiency.

Method used

The visual detection method is used to calculate the gradient amplitude discreteness, scratch difference index and curvature volatility coefficient through grayscale image processing, and the convex defect area is selected based on the significance index, and the neural network model is used for detection.

Benefits of technology

It improves the accuracy of convex defect detection, reduces the misjudgment rate of non-convex areas, improves the robustness and computing efficiency of detection, and can process large-scale data in a short time to ensure detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118864468B_ABST
    Figure CN118864468B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of visual defect detection, and specifically to a method and system for visual defect detection of food packaging bottles, the method comprising: collecting a grayscale image of a food packaging bottle to be detected; calculating the discreteness of the gradient amplitude of the defective area, thereby screening out the area to be detected; calculating the scratch difference index of the area to be detected; calculating the curvature volatility coefficient of the area to be detected; combining the discreteness of the gradient amplitude, the scratch difference index and the curvature volatility coefficient, calculating the significance index of the area to be detected; and using the significance index to detect the convex points of the food packaging bottle. The present application aims to improve the accuracy of the detection of convex point defects of food packaging bottles.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of visual defect detection, and in particular to a method and system for visual detection of defects in food packaging bottles. Background Art

[0002] Food packaging bottles are an important part of food as a commodity. They can protect food from contamination by external factors during the circulation process and maintain the hygiene and quality of food. Food packaging bottles are generally plastic products. During the molding process of such plastic products, due to the influence of different processing equipment, different molding performance, mold cavity structure and material rheology, the appearance quality of the parts often has various defects, such as scratches, pits, convex points, etc. These defects will affect the product qualification rate, reduce production efficiency and even cause food safety accidents.

[0003] Especially for convex spots with smaller areas, they are not easy to find on food packaging bottles compared with scratches and pit defects. That is, convex spot defects are prone to have poor significance of defect characteristics in the defect area on the food packaging bottles, which will lead to poor accuracy in detecting convex spot defects in food packaging bottles. Summary of the invention

[0004] In order to solve the above technical problems, the present application provides a method and system for visual inspection of food packaging bottle defects. The technical solutions adopted are as follows:

[0005] In a first aspect, an embodiment of the present application provides a method for visually detecting defects in food packaging bottles, the method comprising the following steps:

[0006] Collect the grayscale image of the food packaging bottle to be inspected;

[0007] The connected domains that meet the preset area threshold range in the grayscale image to be detected are screened out, and the defective areas are screened out based on the area and shape characteristics of the connected domains;

[0008] Based on the gradient amplitudes of the inner and outer pixel points near the edge of each defect area, the discreteness of the gradient amplitude of the defect area is calculated, thereby screening out the area to be detected;

[0009] Calculate the scratch difference index of the area to be detected based on the width of the area to be detected, the Fourier descriptor of the edge pixels and the gradient amplitude distribution;

[0010] Based on the curvature distribution of the pixel point neighborhood in the area to be detected, the curvature fluctuation coefficient of the area to be detected is calculated;

[0011] Combining the discreteness of gradient amplitude, scratch difference index and curvature fluctuation coefficient, the significance index of the area to be detected is calculated;

[0012] The significance index is used to detect the convex points of food packaging bottles.

[0013] Preferably, the method for screening defective areas comprises:

[0014] The selected connected domain is used to obtain a binary image by using a local threshold method; the connected domain where the foreground part in the binary image is located is marked;

[0015] The area of ​​each marked connected domain and the goodness of fit are combined into a feature array;

[0016] The feature arrays of all marked connected domains are clustered, and the defect area is obtained based on the clustering results.

[0017] Preferably, the obtaining of defect areas based on clustering results includes:

[0018] Calculate the mean of the feature array in each cluster in the clustering results;

[0019] The ratio of the area mean in the mean of the feature array to the goodness of fit mean is calculated, and all connected domains in the clustering cluster where the minimum ratio in the clustering result is located are recorded as defect areas.

[0020] Preferably, the method for screening the area to be detected includes:

[0021] A window of a preset size is set as the center for the edge pixel point of each defect area;

[0022] The pixels in the window that belong to the defect area are recorded as internal pixels, and the pixels that do not belong to the defect area are recorded as external pixels;

[0023] Based on the difference in gradient amplitude distribution between internal pixels and external pixels in the window, the gradient amplitude difference of each window is obtained;

[0024] The mean of the gradient amplitude differences of all windows in each defect area is taken as the gradient amplitude discreteness of the corresponding defect area;

[0025] The defect area with a discrete gradient amplitude greater than a preset threshold is recorded as the area to be detected.

[0026] Preferably, the method for obtaining the gradient amplitude difference of each window includes:

[0027] Get the average value of the gradient amplitude of the internal pixel points in the window and the average value of the gradient amplitude of the external pixel points;

[0028] Calculate the cumulative sum of the differences between the gradient amplitudes of all internal pixels in the window and the average gradient amplitudes of the internal pixels;

[0029] Calculate the cumulative sum of the differences between the gradient amplitudes of all external pixels in the window and the average gradient amplitudes of the external pixels;

[0030] The sum of the two accumulated sums is taken as the gradient magnitude difference of each window.

[0031] Preferably, the method for calculating the scratch difference index of the area to be detected includes:

[0032] Obtain the maximum width of the area to be detected, the average value of the Fourier descriptor of the edge pixels, and the average value of the gradient amplitude of the edge pixels;

[0033] The preset weight coefficients are set for the maximum width, the average value of the Fourier descriptor, and the mean value of the gradient amplitude, and weighted summation is performed;

[0034] The inverse of the weighted sum is used as the scratch difference index of the area to be detected.

[0035] Preferably, the method for calculating the curvature fluctuation coefficient of the area to be detected includes:

[0036] For a preset neighborhood of each pixel point in the area to be detected, two vectors of the same length are randomly generated from the curvature of the pixel points in the preset neighborhood, and the Pearson correlation coefficient between the two vectors is calculated;

[0037] Get the average curvature value of the pixel points in the preset neighborhood, and use the sign function to get the return value of the average curvature value;

[0038] The ratio of the return value of each pixel point to the Pearson correlation coefficient is calculated, and the average of the ratios of all pixels in the area to be detected is taken as the curvature volatility coefficient of the area to be detected.

[0039] Preferably, the significance index of the area to be detected is obtained by multiplying the gradient amplitude discreteness, the scratch difference index and the curvature fluctuation coefficient of the area to be detected.

[0040] Preferably, the detection of convex points of food packaging bottles by using the significance index comprises:

[0041] The significance index of each area to be detected in the grayscale image of the food packaging bottle to be detected is used as the input of the neural network model, and the position of the convex defect is output.

[0042] In a second aspect, an embodiment of the present application further provides a food packaging bottle defect visual detection system, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein when the processor executes the computer program, the steps of any one of the above-mentioned methods for visually detecting food packaging bottle defects are implemented.

[0043] This application has at least the following beneficial effects:

[0044] This application analyzes the differences in texture, morphology, and optics of scratches, pits, and convex spots on the surface of food packaging bottles, and constructs a gradient amplitude discreteness. This index takes into account the discreteness of the amplitudes of scratches, pits, and convex spots on the surface of food packaging bottles, and then preliminarily locates and segments the area containing convex spot defects based on this index, avoiding the influence of the grayscale value and external illumination of the image in the image processing process of traditional methods. Its beneficial effect is that the gradient amplitude discreteness is used to reduce the ratio of non-convex spot areas being misjudged as convex spot defects, thereby improving the robustness of detection. A scratch difference index is constructed, which comprehensively considers the correlation between the scratch area and the non-scratched area in the food packaging bottle image, as well as the width of the scratch area and the amplitude change of the scratch edge pixel points, avoiding the problem of low recognition accuracy caused by the single feature extraction of traditional detection methods. Its beneficial effect is that it has a high sensitivity to scratch defects that may occur in the production process of food packaging bottles, and can effectively distinguish scratches from convex spot defects. By constructing the curvature volatility coefficient, the index takes into account the change characteristics of the average curvature of the pixel points in the pit and convex defect area, introduces the sign function and the Pearson correlation coefficient, and quantifies the change characteristics of this curvature, avoiding the problem of long data processing time required by traditional detection when processing images. Its beneficial effect is that the calculation can be completed in a shorter time, ensuring high computing efficiency in the case of large-scale data processing, thereby improving the detection accuracy, solving the problem that the defect area on the food packaging bottle is prone to poor significance of defect features, and improving the significance of defect features in the defect area. Finally, the convex point significance index is used as the input feature of the neural network model for model training, and the surface convex points of the food packaging bottle are detected based on the trained defect detection model, thereby improving the accuracy of convex point defect detection of food packaging bottles. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0046] Figure 1 A flowchart of a method for visually detecting defects in food packaging bottles provided in one embodiment of the present application;

[0047] Figure 2 A flow chart of a method for obtaining the difference in gradient amplitude of each window provided in one embodiment of the present application;

[0048] Figure 3 A flow chart of a method for calculating the curvature fluctuation coefficient of a region to be detected provided in one embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to further explain the technical means and effects adopted by the present application to achieve the predetermined invention purpose, the following is a detailed description of a food packaging bottle defect visual detection method and system proposed in the present application, its specific implementation, structure, features and effects, in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.

[0050] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs.

[0051] The specific scheme of a food packaging bottle defect visual inspection method and system provided by the present application is described in detail below with reference to the accompanying drawings.

[0052] An embodiment of the present application provides a method and system for visually inspecting defects in food packaging bottles.

[0053] Specifically, a method for visually inspecting food packaging bottle defects is provided as follows. Figure 1 , the method comprises the following steps:

[0054] The first step is to collect the grayscale image of the food packaging bottle to be inspected.

[0055] The image of the food packaging bottle to be inspected is collected by an industrial camera to obtain an RGB spatial image. The values ​​of the three channels R, G, and B in the RGB image at the same pixel position are weighted averaged to obtain a grayscale image F.

[0056] There will be some noise in the process of camera shooting and picture transmission, which will affect the subsequent image processing. Therefore, one embodiment of the present application uses median filtering to preprocess the grayscale image F to obtain a grayscale image H, wherein median filtering is a well-known technology and the specific process is not repeated. In other embodiments of the present application, Gaussian filtering, mean filtering, etc. can also be used to preprocess the grayscale image F.

[0057] Before the video packaging bottle is packaged, it is difficult to identify its defects because the color of the food packaging bottle is single and the bottle is generally transparent. In order to make the surface defects of the food packaging bottle more obvious, this embodiment uses histogram equalization to process the grayscale image H to obtain a grayscale image to be detected, wherein histogram equalization is a well-known technology and the specific process is not repeated.

[0058] At this point, the grayscale image of the food packaging bottle to be inspected can be acquired through the above method.

[0059] In the second step, the connected domains that meet the preset area threshold range in the grayscale image to be detected are screened out, and the defective areas are screened out based on the area and shape characteristics of the connected domains.

[0060] This application detects the convex point defects among the three common defects of scratches, pits and convex points on the bottle body in the production of food packaging bottles. Scratches usually appear as thin and long lines in the image, whose width is much smaller than their length. The edges of the scratches are usually sharp, forming a clear contrast with the surrounding area. Due to the directionality of the force, the scratches are generally continuous. Pits are generally dark areas in the image because they capture less light. The edges of the pits are not as sharp as scratches and are slightly blurred. Pits usually appear as irregular circular or elliptical depressions. For convex points, since they reflect more light, they are generally bright spots or bright spots in the image, and the edges are clearer, especially on smooth plastic surfaces. It will produce a reflective effect, and appear as small circular or conical protrusions in the image. Therefore, this application detects whether there are convex point defects on the surface of food packaging bottles based on the differences in the morphology and texture of the three defects of scratches, pits and convex points.

[0061] Based on the above analysis, one embodiment of the present application uses a watershed algorithm to segment the connected domain of the grayscale image to be detected, and uses the segmentation result output by the watershed algorithm as a labeled image. Wherein, 0 in the labeled image represents the background connected domain, and 1 represents the target connected domain. Wherein, the watershed algorithm is a well-known technology, and the specific process is not repeated here. In other embodiments of the present application, a region growing algorithm can also be used to segment the grayscale image to be detected.

[0062] In the marked image, the area of ​​each target connected domain is analyzed. According to the expected size of the food packaging bottle, an area threshold range is set. The target connected domains within the area threshold range are segmented from the marked image and used as food packaging bottle regions. All food packaging bottle regions are extracted from the grayscale image to be detected to form a grayscale image of the food packaging bottle region. In this embodiment, the area threshold range is set to Wherein, S represents the area of ​​the marked image, and the area threshold range is set by the implementer.

[0063] Since the defect areas of scratches and pits are generally larger, while the defect areas of convex points are usually very small, with a diameter not exceeding 0.2 mm, these protrusions are usually distributed more densely and are sharper.

[0064] Therefore, based on the observation of a large number of defective areas, this embodiment converts the grayscale image of the food packaging bottle area into As the input of Sauvola algorithm (local threshold method), the defects on the surface of food packaging bottles are segmented using Sauvola algorithm to obtain a binary image. , wherein the Sauvola algorithm is a well-known technique and will not be described in detail. In other embodiments of the present application, the Otsu method or the like may be used to obtain a binary image. In this embodiment, the window size in the Sauvola algorithm is generally set to 3 3. The dynamic threshold parameter K is set to 0.1, the foreground is marked as 1, and the background is marked as 0.

[0065] Then, the connected domain where the foreground part of the binary image is located is marked, and the area and shape features of the marked connected domain are extracted to screen out scratches, pits and convex points, and subsequent analysis is performed on the defective areas where the convex points may be located.

[0066] The area a and goodness of fit b of each marked connected domain are used as two eigenvalues ​​to form a feature array (a, b). Each connected domain has a feature array. The feature arrays of all connected domains are clustered using a clustering algorithm to obtain several clusters. The mean of the feature array in each cluster is calculated ( ), calculate the ratio of the area mean in the mean of each cluster feature array to the goodness of fit mean, and record all connected domains in the cluster with the minimum ratio as defect areas.

[0067] It should be noted that the defective area is more likely to be the area where the convex point is located. Since the shape of the scratch is long and narrow, the shape of the pit is a sunken approximately circular or elliptical shape, and the convex point defect should be close to a circle in the 2D image, the goodness of fit of the pit and the convex point should be relatively large; at the same time, since the area of ​​the convex point defect is the smallest, the smaller the area mean, the more it can be explained that the area is the area where the convex point is located, thereby distinguishing the convex point and pit areas.

[0068] Among them, the goodness of fit is a well-known technology and will not be described in detail. This embodiment uses the DBSCAN clustering algorithm to cluster the feature array. The DBSCAN clustering algorithm is a well-known technology and will not be described in detail.

[0069] The third step is to calculate the discreteness of the gradient amplitude of the defect area based on the gradient amplitude of the inner and outer pixel points near the edge of each defect area, so as to screen out the area to be detected.

[0070] Furthermore, since the texture of the convex point defect area is usually quite different from that of the normal area on the surface of the food packaging bottle, the gradient amplitude of the inner and outer pixel points at the edge of each defect area is calculated to preliminarily determine whether there is a convex point defect in the defect area.

[0071] Take the edge pixel of each defect area as the center pixel and set a In this embodiment, the size of the window The value is 7. The pixels in each window that belong to the defect area are recorded as internal pixels, and the pixels that do not belong to the defect area are recorded as external pixels. The calculation method for the discreteness of the gradient amplitude of each defect area is: ; Where n1 represents the total number of internal pixels in each window of each defect area, and n2 represents the total number of external pixels in each window of each defect area. is the gradient amplitude of the jth internal pixel point in each window of each defect area, is the gradient amplitude of the kth external pixel point in each window of each defect area, and are the average gradient amplitude of the internal pixels and the average gradient amplitude of the external pixels in each window of each defect area, Indicates the difference in gradient amplitude of each window in each defect area.

[0072] The mean of the gradient amplitude differences of all windows in each defect area is taken as the gradient amplitude discreteness of the corresponding defect area. .

[0073] It should be understood that the gradient amplitude for the internal pixel is , because they are located in the center of the region and far away from the edge, the amplitude is usually low, while the gradient amplitude of the external pixels is Since the edge of the convex area is obvious, the closer to the convex defect, the higher the or The corresponding average and The difference between the two increases significantly, the larger the value of c is, that is, the greater the difference in gradient amplitude is, the The larger it is, the higher the discreteness of the gradient amplitude in the defect area is, and the wider the distribution of the gradient amplitude is, the more likely it is that there will be obvious convex defects.

[0074] Furthermore, we set a threshold , In this embodiment, the value is 2. If the gradient amplitude discreteness of the defect area , then it is considered that the surface defects of the food packaging bottle include convex point defects, otherwise it is considered that the surface defects of the food packaging bottle do not include convex point defects.

[0075] Furthermore, the gradient amplitude is discrete The area is extracted as the area to be detected.

[0076] In this embodiment, the flow chart of the method for obtaining the difference of the gradient amplitude of each window is shown in the attached figure. Figure 2 shown.

[0077] The fourth step is to calculate the scratch difference index of the area to be detected based on the width of the area to be detected, the Fourier descriptor of the edge pixels and the gradient amplitude distribution.

[0078] Furthermore, the present application constructs a scratch difference index based on the characteristics that scratches appear as thin and long lines with directionality and continuity, while bumps appear as bright spots in small local areas with relatively uniform sizes.

[0079] Specifically, the Fourier descriptor of the edge of each area to be detected is extracted to characterize the image information of different pixel points at the edge of each area to be detected. If it is located in the scratch edge area, the frequency spectrum in the corresponding Fourier descriptor is usually concentrated in a specific high-frequency area to show obvious directional bright spots. For protrusions in small local areas, these protrusions often appear as low-frequency or medium-frequency signals in the frequency domain because they are relatively small in size and change slowly.

[0080] At the same time, the maximum width W of the area to be detected is obtained; and the mean value of the gradient amplitude of the edge pixels of the area to be detected is calculated.

[0081] Based on the maximum width of the area to be detected, the mean value of the gradient amplitude of the edge pixels and the Fourier descriptor, the scratch difference index of the area to be detected is determined, and the expression is: ; In the formula, is the scratch difference index of the i-th area to be detected, is the average value of the Fourier descriptor of the i-th region to be detected, is the maximum width of the i-th region to be detected, is the mean value of the gradient amplitude of the i edge pixels of the area to be detected; a, b, c are the corresponding weight coefficients, and in this embodiment, a=0.2, c=0.3, and c=0.5 are set respectively; the specific values ​​of a, b, and c depend on the type of scratch and the actual scene. If the shape of the scratch is complex, the weight of the Fourier descriptor can be increased; if the width of the scratch is important, the weight b can be increased; the rougher the edge or the more obvious the scratch, the higher the weight c.

[0082] It should be understood that if The larger the value is, the Fourier descriptor shows that the area to be detected is a high-frequency component. The high-frequency component indicates that the area is more likely to be a scratch edge area with obvious directional bright spots. The larger the diameter, the larger the diameter of the edge contour of the i-th area to be detected. The larger the diameter, the more likely it is that the area has a longer scratch. The larger the value is, the larger the average amplitude of the pixels on the edge of the i-th detection area is. The gradient amplitude reflects the sharpness and change speed of the edge. For scratches, the edge is usually sharper, so the larger the gradient amplitude is, the more likely the area is a scratch area. The smaller the area, the more likely it is that the area is a scratch area. The larger the value, the more likely the area is a bump defect area.

[0083] The fifth step is to calculate the curvature fluctuation coefficient of the area to be detected based on the curvature distribution of the pixel neighborhood in the area to be detected.

[0084] Furthermore, based on the different texture and optical characteristics of the pits and convex points, the curvature of each pixel in the area to be detected is obtained.

[0085] Further, for pixel point i in the area to be detected, the curvature values ​​of the pixel points in its preset neighborhood are collected, and two vectors of the same length are randomly generated. The higher the similarity of the two vectors, the closer the curvatures in the eight neighborhoods of the pixel point are, and the smoother the curvature changes. In this embodiment, the eight neighborhoods of pixel point i are taken, and other neighborhoods can also be selected in other embodiments of the present application.

[0086] In this embodiment, the Pearson correlation coefficient is used as the similarity between two vectors. The Pearson correlation coefficient is a well-known technology and will not be described in detail.

[0087] According to the uniformity of the curvature distribution in the neighborhood of all pixels in the area to be detected and the value of the curvature, the curvature fluctuation coefficient of the area to be detected is calculated, and the expression is: ;

[0088] In the formula, is the curvature fluctuation coefficient of the area to be detected, and N is the total number of pixels in the area to be detected; is the similarity between the two vectors of the i-th pixel in the area to be detected, is the average curvature value of the preset neighborhood of the i-th pixel in the area to be detected, sgn is the sign function, the return value is +1 for positive numbers, -1 for negative numbers, and 0 for zero. To prevent the denominator from being set to 0, the parameter is set to 0.01 in this embodiment.

[0089] It should be noted that if the similarity between the two vectors randomly generated by curvature in the neighborhood of a pixel point is higher, it means that the change of the average curvature in the area is relatively gentle and continuous, that is, The closer it is to 1. In addition, for a surface, the curvature of each pixel on each surface describes the degree of concavity of each pixel. If the curvature is positive, the point on the surface is convex, and if the curvature is negative, the surface is concave at that point. That is, when When it is 0, The closer the value is to 0, the more likely it is that the area is a flat area. When is 1, The closer the value is to 1, the greater the possibility that the area is a convex point area; When it is -1, it means that the region is more likely to be a pit region.

[0090] Combining the concave and convex conditions of the neighborhood of each pixel in the area to be detected and the curvature distribution stability characteristics of its neighborhood, the curvature fluctuation coefficient of the area to be detected can be reflected. The larger it is, the greater the curvature fluctuation in the area to be detected and the more likely it is a pit.

[0091] In this embodiment, the flow chart of the calculation method of the curvature fluctuation coefficient of the area to be detected is as shown in the attached figure. Figure 3 shown.

[0092] The sixth step is to calculate the significance index of the area to be detected by combining the gradient amplitude discreteness, scratch difference index and curvature fluctuation coefficient.

[0093] Based on the above-obtained gradient amplitude discreteness, scratch difference index, and curvature fluctuation coefficient indices of the area to be detected, the significance index of the area to be detected where convex point defects on the surface of the food packaging bottle may exist is calculated, specifically:

[0094] The product of the gradient amplitude discreteness, scratch difference index and curvature fluctuation coefficient of the area to be detected is used as the significance index of the area to be detected.

[0095] It should be understood that the greater the value of the gradient amplitude discreteness, scratch difference index, and curvature volatility index, the greater the significance index. The larger the value, the more likely the defect area is a convex defect area of ​​a food packaging bottle. Set a threshold , the initial value is set to the significance index The 95th percentile of the data, taking into account the differences between different batches of food packaging bottles, the specific implementers should adjust the threshold size adaptively based on the comparison of historical data and real-time data. The defect area is used as the convex defect area of ​​the food packaging bottle.

[0096] The seventh step is to detect the convex points of the food packaging bottles using the significance index.

[0097] Furthermore, an image dataset containing convex point defects of food packaging bottles is collected, and Labelmg is used to annotate the images, and corresponding defect category labels are assigned to them. Then, the method in this embodiment is used to calculate the significance index of each defect area in each image.

[0098] This embodiment selects the SSD neural network model, takes the significance index of the area where the convex point defects of all images are located as the input of the model, uses the Adam algorithm as the model optimization algorithm, uses the cross entropy function as the loss function of the model, and the model output is the location of the convex point defect.

[0099] In other embodiments of the present application, a convolutional neural network model may also be used for model training. The model training processes of the SSD neural network model and the convolutional neural network model are both well-known technologies and will not be described in detail.

[0100] The trained model is then deployed in the actual convex defect detection system in food packaging bottles to realize defect detection of food packaging bottles.

[0101] Based on the same inventive concept as the above method, an embodiment of the present application also provides a food packaging bottle defect visual detection system, including a memory, a processor, and a computer program stored in the memory and running on the processor, and when the processor executes the computer program, the steps of a food packaging bottle defect visual detection method described in any one of the above methods are implemented.

[0102] The various embodiments in the present application are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.

[0103] It should be noted that, unless otherwise specified and limited, terms such as "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a circuit structure, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such article or device. In the absence of further restrictions, an element defined by the sentence "including one..." does not exclude the existence of other identical elements in the article or device including the element. In addition, the term "and\or" used herein includes any and all combinations of one or more related listed items.

[0104] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not invented by the present application.

[0105] It should be understood that the present application is not limited to the exact construction that has been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof.

Claims

1. A method for visually detecting defects in food packaging bottles, characterized in that: The method comprises the following steps: Collect the grayscale image of the food packaging bottle to be inspected; The connected domains that meet the preset area threshold range in the grayscale image to be detected are screened out, and the defective areas are screened out based on the area and shape characteristics of the connected domains; Based on the gradient amplitudes of the inner and outer pixel points near the edge of each defect area, the discreteness of the gradient amplitude of the defect area is calculated, thereby screening out the area to be detected; Calculate the scratch difference index of the area to be detected based on the width of the area to be detected, the Fourier descriptor of the edge pixels and the gradient amplitude distribution; Based on the curvature distribution of the pixel point neighborhood in the area to be detected, the curvature fluctuation coefficient of the area to be detected is calculated; Combining the discreteness of gradient amplitude, scratch difference index and curvature fluctuation coefficient, the significance index of the area to be detected is calculated; Detect convex points on food packaging bottles using the significance index; The screening method of the area to be detected includes: A window of a preset size is set as the center for the edge pixel point of each defect area; The pixels in the window that belong to the defect area are recorded as internal pixels, and the pixels that do not belong to the defect area are recorded as external pixels; Based on the difference in gradient amplitude distribution between internal pixels and external pixels in the window, the gradient amplitude difference of each window is obtained; The mean of the gradient amplitude differences of all windows in each defect area is taken as the gradient amplitude discreteness of the corresponding defect area; The defect area with a discrete gradient amplitude greater than a preset threshold is recorded as the area to be detected; The method for calculating the scratch difference index of the area to be detected includes: Obtain the maximum width of the area to be detected, the average value of the Fourier descriptor of the edge pixels, and the average value of the gradient amplitude of the edge pixels; The preset weight coefficients are set for the maximum width, the average value of the Fourier descriptor, and the mean value of the gradient amplitude, and weighted summation is performed; The inverse of the weighted sum is used as the scratch difference index of the area to be detected; The calculation method of the curvature fluctuation coefficient of the area to be detected includes: For a preset neighborhood of each pixel point in the area to be detected, two vectors of the same length are randomly generated from the curvature of the pixel points in the preset neighborhood, and the Pearson correlation coefficient between the two vectors is calculated; Get the average curvature value of the pixel points in the preset neighborhood, and use the sign function to get the return value of the average curvature value; Calculate the ratio of the return value of each pixel point to the Pearson correlation coefficient, and take the average of the ratios of all pixels in the area to be detected as the curvature volatility coefficient of the area to be detected; The significance index of the region to be detected is obtained by multiplying the gradient amplitude discreteness, scratch difference index and curvature fluctuation coefficient of the region to be detected; The method for obtaining the gradient amplitude difference of each window includes: Get the average value of the gradient amplitude of the internal pixel points in the window and the average value of the gradient amplitude of the external pixel points; Calculate the cumulative sum of the differences between the gradient amplitudes of all internal pixels in the window and the average gradient amplitudes of the internal pixels; Calculate the cumulative sum of the differences between the gradient amplitudes of all external pixels in the window and the average gradient amplitudes of the external pixels; The sum of the two accumulated sums is taken as the gradient magnitude difference of each window.

2. A method for visually inspecting food packaging bottle defects as claimed in claim 1, characterized in that: The method for screening defective areas comprises: The selected connected domain is used to obtain a binary image by using a local threshold method; the connected domain where the foreground part in the binary image is located is marked; The area of ​​each marked connected domain and the goodness of fit are combined into a feature array; The feature arrays of all marked connected domains are clustered, and the defect area is obtained based on the clustering results.

3. A method for visually inspecting food packaging bottle defects as claimed in claim 2, characterized in that: The obtaining of defect areas based on clustering results includes: Calculate the mean of the feature array in each cluster in the clustering results; The ratio of the area mean in the mean of the feature array to the goodness of fit mean is calculated, and all connected domains in the clustering cluster where the minimum ratio in the clustering result is located are recorded as defect areas.

4. A method for visually inspecting food packaging bottle defects as claimed in claim 1, characterized in that: The method of detecting convex points of food packaging bottles by using the significance index comprises: The significance index of each area to be detected in the grayscale image of the food packaging bottle to be detected is used as the input of the neural network model, and the position of the convex defect is output.

5. A food packaging bottle defect visual inspection system, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, the steps of the method for visually detecting defects in food packaging bottles as described in any one of claims 1 to 4 are implemented.