An intelligent defect detection method for milk packaging

By performing threshold segmentation, edge chain code analysis and morphological operations on the bottom grayscale image of the outer milk bottle, combining the grayscale uniformity and gradient information of 8 neighborhoods, defect areas are selected, and the texture interference in the prior art is solved The problem of degradation of detection accuracy has achieved more efficient and accurate defect detection.

CN119067923BActive Publication Date: 2025-02-07INST OF ANIMAL SCI & VETERINARY MEDICINE SHANDONG ACADEMY OF AGRI SCI +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411083204.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2025-02-07
Estimated Expiration
2044-08-08

AI Technical Summary

Technical Problem

When detecting defects in the outer packaging of milk, the prior art is disturbed by the texture inside the glass bottle, resulting in a decrease in detection accuracy.

Method used

By obtaining the grayscale image of the bottle bottom, performing threshold segmentation and edge chain code analysis, combining the grayscale uniformity and gradient information of 8 neighborhoods, the target area and defect area are selected, and morphological operations are performed to determine the connecting domain and distribution according to the location Determine whether the outer packaging is qualified.

Benefits of technology

It improves the accuracy and efficiency of milk packaging defect detection and reduces detection errors caused by texture interference.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119067923B_ABST
    Figure CN119067923B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image processing technology, and in particular to an intelligent defect detection method for milk outer packaging, comprising: obtaining a grayscale image of a bottle bottom and obtaining a suspected area, calculating the 8-neighborhood grayscale uniformity of each pixel point of the bottle bottom grayscale image, and then screening out a target area, screening out a number of highlight points in each target area, screening out a number of defective areas in all target areas according to the 8-neighborhood grayscale uniformity and gradient of the highlight points and the surrounding pixels, finding missed defective areas according to defective area characteristics, and judging whether the outer packaging of the bottle bottom is a qualified outer packaging according to the position distribution of all defective areas in the bottle bottom grayscale image. The present invention screens interference information according to the grayscale difference and edge characteristics between regions, and finally determines the defective area, effectively improving the accuracy and efficiency of the prior art in identifying defects in the outer packaging of bottled milk, and reducing the loss of detailed information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to an intelligent defect detection method for milk outer packaging. Background Art

[0002] Glass bottles have good chemical stability and barrier properties. They will not react chemically with milk, which helps to prevent air contamination of milk, blocks the diffusion of flavor substances, and effectively maintains the purity and nutritional content of milk. However, glass bottles are fragile and prone to cracks. If cracked glass bottles are used to package milk, safety hazards may occur, causing the milk to be directly exposed to the air, leading to microbial contamination.

[0003] Since glass has poor adaptability to temperature, is fragile and has poor impact resistance, the most common defects in glass bottles are inappropriate temperature during the dripping process or collisions during transportation and storage that cause bottom wear or gaps. Currently, defect detection of milk packaging is mostly done manually or based on image threshold segmentation and edge detection. However, since there are a lot of textures inside the milk glass bottle, it will interfere with manual detection and image segmentation, which may reduce the accuracy of defect detection of milk packaging. Summary of the invention

[0004] The invention provides an intelligent defect detection method for milk outer packaging to solve the existing problems.

[0005] The present invention provides an intelligent defect detection method for milk outer packaging using the following technical solutions:

[0006] An embodiment of the present invention provides an intelligent defect detection method for milk outer packaging, the method comprising the following steps:

[0007] Obtain a grayscale image of the bottle bottom; perform threshold segmentation on the grayscale image of the bottle bottom to obtain suspected areas; obtain an edge chain code sequence for each suspected area;

[0008] According to the gradient amplitude and gray value of all pixels in the bottle bottom gray image, the 8-neighborhood gray uniformity of each pixel in the bottle bottom gray image is obtained; according to the 8-neighborhood gray uniformity of all pixels in the bottle bottom gray image and the edge chain code sequence of each suspected area, the target area is screened out from all suspected areas in the bottle bottom gray image;

[0009] According to the grayscale values ​​of all pixels in each target area, several highlight points are screened out on all edge lines in each target area; according to the grayscale uniformity and gradient of the 8-neighborhood of the highlight point and its surrounding pixels, several defect areas are screened out in all target areas;

[0010] Perform morphological operations on all defective areas to obtain several possible connected domains; select several defective areas from the several possible connected domains;

[0011] According to the position distribution of all defective areas in the grayscale image of the bottle bottom, it is determined whether the outer packaging of the bottle bottom is qualified.

[0012] Furthermore, the specific calculation formula for obtaining the 8-neighborhood grayscale uniformity of each pixel point in the bottle bottom grayscale image according to the gradient amplitude and grayscale value of all pixels in the bottle bottom grayscale image is:

[0013]

[0014] In the formula, q i represents the grayscale uniformity of the 8-neighborhood of the i-th pixel of the bottle bottom grayscale image; t i represents the sum of the gradient amplitudes of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom; h i Represents the mean of the grayscale values ​​of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom; Represents the mean grayscale value of all pixels in the grayscale image of the bottle bottom; s i Represents the variance of the grayscale values ​​of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom.

[0015] Furthermore, the method of screening out the target area from all the suspected areas in the bottle bottom grayscale image according to the 8-neighborhood grayscale uniformity of all pixels in the bottle bottom grayscale image and the edge chain code sequence of each suspected area includes the following specific steps:

[0016] According to the 8-neighborhood grayscale uniformity of all pixels in the grayscale image of the bottle bottom, the degree to which each suspected area meets the defect characteristics is obtained;

[0017] Among all the suspected regions of the grayscale image of the bottle bottom, the suspected region whose degree of conformity to the defect feature is greater than a preset degree threshold of the defect feature is recorded as the target region.

[0018] Furthermore, the specific calculation formula for obtaining the degree to which each suspected area meets the defect characteristics based on the 8-neighborhood grayscale uniformity of all pixels in the bottle bottom grayscale image is:

[0019]

[0020] In the formula, p j Indicates the degree to which the jth suspected area meets the defect characteristics; v j represents the number of pixels in the jth suspected area; q j,a Represents the grayscale uniformity of the 8-neighborhood of the a-th pixel in the j-th suspected area; represents the mean value of the grayscale uniformity of the eight-neighborhood of all pixels in the grayscale image of the bottle bottom; l j Represents the maximum number of consecutive repeated chain codes in the edge chain code sequence of the jth suspected area; norm() is a linear normalization function.

[0021] Furthermore, the method of selecting a plurality of highlight points on all edge lines in each target area according to the grayscale values ​​of all pixels in each target area includes the following specific steps:

[0022] In the 8-neighborhood of the y-th edge pixel point on all edge lines of the x-th target area, when the grayscale value of the y-th edge pixel point is greater than the grayscale values ​​of all pixels in the 8-neighborhood of the y-th edge pixel point and the number of pixels in the 8-neighborhood of the y-th edge pixel point whose grayscale values ​​are greater than the average grayscale value is greater than or equal to a preset number of pixels, the y-th edge pixel point is recorded as a highlight point.

[0023] Furthermore, the method of screening out several defective areas in all target areas according to the grayscale uniformity and gradient of the eight-neighborhood of the highlight point and its surrounding pixels includes the following specific steps:

[0024] In the x-th target area, the normal of each highlight point on all edge lines is obtained. On the normal of each highlight point, the first b pixels adjacent to each highlight point on both sides are recorded as the pixels to be detected of the corresponding highlight point in the x-th target area, where b is the preset number of pixels;

[0025] According to the 8-neighborhood grayscale uniformity and gradient direction vector of all the pixels to be detected in each target area, the degree to which each pixel to be detected of each highlight point in each target area conforms to the pixel of the text area is obtained;

[0026] Among all the pixels to be detected in each target area, the pixels to be detected whose degree of conformity with the pixels in the text area is greater than a preset valid pixel threshold are recorded as valid pixels;

[0027] According to the degree to which all the pixels to be detected in each target area conform to the pixels in the text area and the number of valid pixels, the degree to which each target area conforms to the text area is obtained;

[0028] Among all target areas, a target area whose degree of conformity to the text area is less than a preset defect area threshold is recorded as a defect area.

[0029] Furthermore, the specific calculation formula for obtaining the degree to which each pixel to be detected of each highlight point in each target area conforms to the pixel of the text area according to the 8-neighborhood grayscale uniformity and gradient direction vector of all the pixels to be detected in each target area is:

[0030]

[0031] In the formula, Indicates the degree to which the mth pixel to be detected at the kth highlight point of the ath target area matches the pixel of the text area; Represents the grayscale uniformity of the 8-neighborhood of the m-th pixel to be detected at the k-th highlight point in the a-th target area; Represents the grayscale uniformity of the 8-neighborhood pixel to be detected symmetrically about the highlight point on the corresponding normal line of the m-th pixel to be detected at the k-th highlight point in the a-th target area; Represents the gradient of the mth pixel to be detected at the kth highlight point in the ath target area; Represents the gradient of the mth pixel to be detected at the k+1th highlight point in the ath target area; express and The degree of the angle; || is the absolute value function; norm() is the linear normalization function.

[0032] Furthermore, according to the degree to which all the pixels to be detected in each target area conform to the pixels in the text area and the number of valid pixels, the specific calculation formula for obtaining the degree to which each target area conforms to the text area is:

[0033]

[0034] In the formula, w n Indicates the degree to which the nth target area conforms to the text area; c n Indicates the number of all pixels to be detected in the nth target area; u n,d Indicates the degree to which the dth pixel to be detected in the nth target area matches the pixel in the text area; c ′ n Represents the number of all valid pixels in the nth target area; norm() is a linear normalization function.

[0035] Furthermore, the step of selecting a plurality of defective regions from a plurality of possible connected domains includes the following specific steps:

[0036] Perform circle fitting on the grayscale image of the bottle bottom, and obtain the circle with the largest radius in the fitting result, which is recorded as the outermost circle curve of the bottle bottom;

[0037] The pixel points in the intersection of all the 8-neighborhood pixel points of all the pixel points of the outermost circular curve of the bottle bottom and all the pixel points of each possible connected domain are recorded as the pixel points of each possible connected domain on the outermost circular curve of the bottle bottom;

[0038] The linear normalized value of the quotient of the number of pixels of each possible connected domain on the outermost circular curve of the bottle bottom and the average value of the shortest distance from all edge pixels in each possible connected domain to the outermost circular curve of the bottle bottom is recorded as the degree to which each possible connected domain conforms to the texture of the glass bottle itself;

[0039] Among all possible connected domains, the possible connected domains whose degree of conformity to the texture of the glass bottle itself is greater than a preset defect region threshold are recorded as defect regions.

[0040] Furthermore, judging whether the outer packaging of the bottle bottom is a qualified outer packaging according to the position distribution of all defective areas in the grayscale image of the bottle bottom includes the following specific steps:

[0041] In the grayscale image of the bottle bottom, the product of the shortest distance from the center of gravity of each defect area to the center of the outermost circle of the bottle bottom and the number of all pixels in the defect area is recorded as the severity of each defect area;

[0042] Performing linear normalization on the severity of each defect area to obtain the normalized severity of each defect area;

[0043] The average of the normalized severity of all defective areas is recorded as the defect degree of the tested bottle bottom;

[0044] The outer packaging bottle bottom with a defect degree less than the preset defect area threshold is recorded as a qualified outer packaging.

[0045] The beneficial effects of the technical solution of the present invention are:

[0046] In the embodiment of the present invention, a grayscale image of the bottle bottom is obtained; a threshold segmentation is performed on the grayscale image of the bottle bottom to obtain a suspected area; an edge chain code sequence of each suspected area is obtained to provide a data basis for subsequent analysis and processing; the 8-neighborhood grayscale uniformity of each pixel point in the grayscale image of the bottle bottom is obtained according to the gradient amplitude and grayscale value of all pixels in the grayscale image of the bottle bottom; according to the 8-neighborhood grayscale uniformity of all pixels in the grayscale image of the bottle bottom and the edge chain code sequence of each suspected area, a target area is screened out from all suspected areas of the grayscale image of the bottle bottom, and the area where defects may exist is accurately located by combining the 8-neighborhood grayscale uniformity and edge information, thereby further narrowing the scope that needs attention; according to each target area, the grayscale uniformity of each pixel point in the grayscale image of the bottle bottom is obtained; The grayscale values ​​of all pixels in the target area are used to screen out several highlight points on all edge lines in each target area; according to the grayscale uniformity and gradient of the 8-neighborhood of the highlight point and its surrounding pixels, several defect areas are screened out in all target areas, and the defect areas are further screened to ensure that the real defect areas are found; morphological operations are performed on all defect areas to obtain several possible connected domains; several defect areas are screened out from several possible connected domains, and the missed defect areas are found in combination with the characteristics of the defect areas; according to the position distribution of all defect areas in the grayscale image of the bottle bottom, it is judged whether the outer packaging of the bottle bottom is a qualified outer packaging, and the intelligent detection of defects in the outer packaging of milk is realized. So far, the present invention screens interference information according to the grayscale difference and edge characteristics between regions, and finally determines the defect area, which effectively improves the accuracy and efficiency of the prior art in identifying defects in the outer packaging of bottled milk, and reduces the loss of detailed information. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0048] Figure 1 A flowchart of the steps of an intelligent defect detection method for milk outer packaging of the present invention;

[0049] Figure 2 An example bottle bottom grayscale image provided by an embodiment of the present invention;

[0050] Figure 3 An example of a bottle bottom grayscale image segmentation result provided by an embodiment of the present invention;

[0051] Figure 4 A schematic diagram of bottle bottom text provided by an embodiment of the present invention;

[0052] Figure 5A schematic diagram of a defect area threshold segmentation result provided by an embodiment of the present invention;

[0053] Figure 6 A schematic diagram of defect area edge detection results provided by an embodiment of the present invention;

[0054] Figure 7 A schematic diagram of a normal area that shares a border with a defective area provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0055] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the specific implementation, structure, features and effects of an intelligent defect detection method for milk outer packaging proposed by the present invention 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.

[0056] 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 invention belongs.

[0057] The specific scheme of the intelligent defect detection method for milk outer packaging provided by the present invention is described in detail below with reference to the accompanying drawings.

[0058] See also Figure 1 , which shows a flowchart of a method for intelligently detecting defects in milk packaging provided by an embodiment of the present invention, the method comprising the following steps:

[0059] Step S001: obtaining a grayscale image of the bottle bottom; performing threshold segmentation on the grayscale image of the bottle bottom to obtain suspected regions; and obtaining an edge chain code sequence of each suspected region.

[0060] Use the camera pre-arranged on the production line to collect bottle bottom images;

[0061] The bottle bottom image is grayed to obtain a bottle bottom grayscale image.

[0062] It should be noted that the glass bottles to be inspected are transported by a conveyor belt, a light source and a camera are set at a fixed position, and the bottle bottom image is obtained and grayscaled. The grayscale image of the bottle bottom is shown as follows: Figure 2 shown.

[0063] The bottle bottom grayscale image is operated using the Otsu algorithm to obtain the optimal segmentation threshold and the bottle bottom grayscale image segmentation result. Figure 3 The figure shows the segmentation result of the grayscale image of the bottom of an example bottle, wherein the Otsu algorithm is a well-known technique;

[0064] Among all the pixels whose grayscale values ​​in the grayscale image of the bottle bottom are greater than the optimal segmentation threshold, the connected domain composed of consecutive adjacent pixels is recorded as a suspected region; thus, a number of suspected regions are obtained.

[0065] The Freeman chain code algorithm is used to obtain the edge chain code sequence of each suspected area, which is a well-known technology.

[0066] Step S002: according to the gradient amplitude and gray value of all pixels in the bottle bottom gray image, the 8-neighborhood gray uniformity of each pixel in the bottle bottom gray image is obtained; according to the 8-neighborhood gray uniformity of all pixels in the bottle bottom gray image and the edge chain code sequence of each suspected area, the target area is screened out from all suspected areas in the bottle bottom gray image.

[0067] Since the inside of the notch of the glass bottle is uneven, there are many tiny facets on the surface of the notch, which have a strong ability to reflect light. However, the distribution of the facets inside the notch is irregular, which makes the light refraction angle variable and irregular. Under the influence of light, the defective area is brighter and has more internal textures than the normal area. In addition, the surface of the notch made of glass is often uneven (the notch is often formed by external force destroying the bottle body. Due to the particularity of the glass material, many tiny cracks will be formed along the notch direction during the notch formation process, so the surface of the notch area is uneven), the edge is rough and the notch shape is irregular, while the normal area caused by light reflection often has smooth edges and regular shapes.

[0068] According to the gradient amplitude and gray value of all pixels in the bottle bottom gray image, the corresponding calculation formula for the 8-neighborhood gray uniformity of each pixel in the bottle bottom gray image is obtained as follows:

[0069]

[0070] In the formula, q i represents the grayscale uniformity of the 8-neighborhood of the i-th pixel of the bottle bottom grayscale image; t i represents the sum of the gradient amplitudes of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom; h i Represents the mean of the grayscale values ​​of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom; Represents the mean grayscale value of all pixels in the grayscale image of the bottle bottom; s i Represents the variance of the grayscale values ​​of all pixels in the 8-neighborhood of the i-th pixel in the grayscale image of the bottle bottom.

[0071] It should be noted that in this embodiment, the gradient amplitude of the pixel point is obtained using the Sobel operator, which is a well-known technique; the sum of the gradient amplitudes of all the pixel points in the 8-neighborhood of the i-th pixel point is t iThe larger it is, the more chaotic the texture distribution is; The larger the value, the larger the gray value of the 8-neighborhood of the i-th pixel is relative to the overall image, that is, the higher the brightness; the variance s of the gray values ​​of all pixels in the 8-neighborhood of the i-th pixel is i The larger the value is, the greater the grayscale change of all pixels in the 8-neighborhood of the i-th pixel.

[0072] According to the 8-neighborhood grayscale uniformity of all pixels in the grayscale image of the bottle bottom, the corresponding calculation formula for the degree to which each suspected area meets the defect characteristics is obtained:

[0073]

[0074] In the formula, p j Indicates the degree to which the jth suspected area meets the defect characteristics; v j represents the number of pixels in the jth suspected area; q j,a Represents the grayscale uniformity of the 8-neighborhood of the a-th pixel in the j-th suspected area; represents the mean value of the grayscale uniformity of the eight-neighborhood of all pixels in the grayscale image of the bottle bottom; l j Represents the maximum number of consecutive repeated chain codes in the edge chain code sequence of the jth suspected area; norm() is a linear normalization function that normalizes the data value to the [0,1] interval.

[0075] The threshold value of the degree of defect characteristics preset in this embodiment is 0.5, which is used as an example for description. In other implementations, it can be set to other values, which are not limited in this embodiment.

[0076] Among all the suspected regions of the grayscale image of the bottle bottom, the suspected region whose degree of conformity to the defect feature is greater than a preset degree threshold of the defect feature is recorded as the target region.

[0077] Step S003: According to the grayscale values ​​of all pixels in each target area, several highlight points are screened out on all edge lines in each target area; according to the grayscale uniformity and gradient of the 8-neighborhood of the highlight point and its surrounding pixels, several defect areas are screened out in all target areas.

[0078] The bottom of the glass bottle may contain trademarks, text, and other areas that belong to the bottle's own texture. Figure 4The figure shows a schematic diagram of the text on the bottom of the bottle. Due to the influence of the shooting angle and lighting, the shape of the text in the photo may interfere with the identification of the defective area. Therefore, the defective area is identified by the morphological characteristics of the two areas. Taking the raised text area of ​​the glass bottle as an example, since the text area is raised and has a regular shape, under the influence of lighting, the pixel point at the highest point of the raised part has the highest brightness relative to other pixels in the area. The highlight points are connected to form a highlight line. The grayscale values ​​of the pixels on both sides of the highlight line gradually decrease along the direction perpendicular to the highlight line starting from the highlight line. The more uneven the grayscale value distribution is, the greater the grayscale uniformity of the 8-neighborhood of the pixel point is. Since the shape of the raised text is relatively regular, the smaller the difference in distance between the pixels on both sides of the highlight line and the highlight line is, the smaller the difference in grayscale uniformity of the 8-neighborhood of the pixel point is. The angle between the gradient directions of the two adjacent pixels on the same side along the extension direction of the highlight line is smaller. The more pixels that meet the above rules in the area, the greater the possibility that the area belongs to the text area.

[0079] The number of pixels preset in this embodiment is b=5, which is used as an example for description. Other values ​​may be set in other implementations, which are not limited in this embodiment.

[0080] Use the Canny edge detection algorithm to perform edge detection on each target area to obtain several edge lines, where the Canny edge detection algorithm is a public technology;

[0081] In the 8-neighborhood of the y-th edge pixel on all edge lines of the x-th target area, when the grayscale value of the y-th edge pixel is greater than the grayscale values ​​of all pixels in the 8-neighborhood of the y-th edge pixel and the number of pixels in the 8-neighborhood of the y-th edge pixel whose grayscale value is greater than the average grayscale value is greater than or equal to the preset number of pixels, the y-th edge pixel is recorded as a highlight point;

[0082] It should be noted that the highlight line composed of highlight points may be a plurality of discontinuous curve segments. From the above analysis, it can be seen that, with the pixel point on the curve segment as the starting point, the grayscale change of the pixel point gradually decreases toward both sides along the direction perpendicular to the tangent of the point, and the closer the distance from the pixel points on both sides to the highlight line, the closer the grayscale uniformity of the 8-neighborhood of the pixel point.

[0083] In the x-th target area, the normal of each highlight point on all edge lines is obtained. On the normal of each highlight point, the first b pixels adjacent to each highlight point on both sides are recorded as the pixels to be detected of the corresponding highlight point in the x-th target area, where b is the preset number of pixels;

[0084] It should be noted that, on the normal line of any highlight point in the xth target area, when the number of pixels on either side of the highlight point is less than b, the smallest number of pixels on both sides is taken as b to obtain the pixel point to be detected.

[0085] According to the 8-neighborhood grayscale uniformity and gradient direction vector of all the pixels to be detected in each target area, the corresponding calculation formula for the degree to which each pixel to be detected of each highlight point in each target area conforms to the pixel of the text area is obtained:

[0086]

[0087] In the formula, Indicates the degree to which the mth pixel to be detected at the kth highlight point of the ath target area matches the pixel of the text area; Represents the grayscale uniformity of the 8-neighborhood of the m-th pixel to be detected at the k-th highlight point in the a-th target area; Represents the grayscale uniformity of the 8-neighborhood pixel to be detected symmetrically about the highlight point on the corresponding normal line of the m-th pixel to be detected at the k-th highlight point in the a-th target area; Represents the gradient of the mth pixel to be detected at the kth highlight point in the ath target area; Represents the gradient of the mth pixel to be detected at the k+1th highlight point in the ath target area; express and The degree of the angle; || is the absolute value function; norm() is the linear normalization function, which normalizes the data value to the [0,1] interval.

[0088] It should be noted that It indicates the grayscale similarity between the mth pixel to be detected at the kth highlight point in the ath target area and the pixel to be detected symmetrically about the highlight point on the corresponding normal line. The larger the value, the greater the similarity, and the more it conforms to the characteristics of the pixel in the text area. express and The degree of the angle. The smaller the angle, the more consistent the grayscale change is, and the more consistent it is with the distribution law of the pixels in the text area. When it does not exist, θ Set it to 1 to ensure that the formula holds.

[0089] The effective pixel threshold value preset in this embodiment is 0.7, which is used as an example for description. Other values ​​may be set in other implementations, and this embodiment does not limit this.

[0090] Among all the pixels to be detected in each target area, the pixels to be detected whose degree of conformity with the pixels in the text area is greater than a preset valid pixel threshold are recorded as valid pixels;

[0091] According to the degree to which all the pixels to be detected in each target area conform to the pixels in the text area and the number of valid pixels, the corresponding calculation formula for the degree to which each target area conforms to the text area is obtained:

[0092]

[0093] In the formula, w n Indicates the degree to which the nth target area conforms to the text area; c n Indicates the number of all pixels to be detected in the nth target area; u n,d Indicates the degree to which the dth pixel to be detected in the nth target area matches the pixel in the text area; c ′ n Represents the number of all valid pixels in the nth target area; norm() is a linear normalization function that normalizes the data value to the [0,1] interval.

[0094] It should be noted that Indicates the average value of the degree to which all the pixels to be detected in the nth target area conform to the pixels in the text area; It represents the ratio of all valid pixels in the nth target area to the number of pixels to be detected. The larger the ratio is, the more the nth target area conforms to the text area.

[0095] The defect area threshold value preset in this embodiment is 0.5, which is used as an example for description. Other values ​​may be set in other implementations, which are not limited in this embodiment.

[0096] Among all target areas, a target area whose degree of conformity to the text area is less than a preset defect area threshold is recorded as a defect area.

[0097] Step S004: performing morphological operations on all defective regions to obtain a number of possible connected domains; and screening out a number of defective regions from the possible connected domains.

[0098] In the process of collecting images, glass will refract under the light source, resulting in the area obtained by threshold segmentation in the current scene may miss the actual defect part; due to the influence of light, the glass gap may have high brightness at the edge and low brightness in the concave area of ​​the gap, resulting in incomplete suspected area obtained by threshold segmentation. Figure 5 shown.

[0099] Performing morphological dilation operation on all defect regions to obtain dilated regions, wherein the morphological dilation operation is a well-known technology;

[0100] It should be noted that the specific process of the morphological dilation operation is: in the grayscale image of the bottle bottom, the grayscale value of the pixels in the defect area is set to 1, and the grayscale value of the pixels in the non-defect area is set to 0 to obtain a binary image, and a morphological dilation operation is performed on the binary image to obtain an expanded binary image, and the area where the grayscale value of the pixels in the expanded binary image is 1 corresponds to the area in the grayscale image of the bottle bottom as the expansion area.

[0101] The area in the expansion region, except for all defective areas, is recorded as the possible area;

[0102] In the possible area, the connected domain formed by continuous adjacent pixels is recorded as a possible connected domain.

[0103] It should be noted that the possible connected domain obtained by the subtraction operation may be Figure 6 The defect area shown may also be Figure 7 The area shown shares a border with the defective area. In order to determine the defective area, the edge features of the possible connected domain are analyzed to determine the possibility that the possible connected domain belongs to the defective area.

[0104] Since the area that shares the boundary with the defective area is a normal area, there must be multiple pixel points on its edge that conform to the texture characteristics of the glass bottle itself. Curve fitting is used to determine the degree to which the edge of the possible connected domain conforms to the texture of the glass bottle itself.

[0105] Use the least squares method to perform circle fitting on the grayscale image of the bottle bottom, and obtain the circle with the largest radius in the fitting result, which is recorded as the outermost circle curve of the bottle bottom;

[0106] The pixel points in the intersection of all the 8-neighborhood pixel points of all the pixel points of the outermost circular curve of the bottle bottom and all the pixel points of each possible connected domain are recorded as the pixel points of each possible connected domain on the outermost circular curve of the bottle bottom;

[0107] According to the pixel points of each possible connected domain on the outermost circular curve of the bottle bottom and the distances from all edge pixels to the outermost circular curve of the bottle bottom, the corresponding calculation formula for the degree to which each possible connected domain conforms to the texture of the glass bottle itself is obtained:

[0108]

[0109] In the formula, r e Indicates the degree to which the e-th possible connected domain conforms to the texture of the glass bottle itself; represents the average value of the shortest distance from all edge pixels in the e-th possible connected domain to the outermost circular curve at the bottom of the bottle; f e Represents the number of pixels of the e-th possible connected domain on the outermost circular curve of the bottle bottom; norm() is a linear normalization function that normalizes the data value to the interval [0,1].

[0110] Among all possible connected domains, the possible connected domains whose degree of conformity to the texture of the glass bottle itself is greater than a preset defect region threshold are recorded as defect regions.

[0111] Step S005: judging whether the outer packaging of the bottle bottom is qualified according to the position distribution of all defective areas in the grayscale image of the bottle bottom.

[0112] In the grayscale image of the bottle bottom, the product of the shortest distance from the center of gravity of each defect area to the center of the outermost circle of the bottle bottom and the number of all pixels in the defect area is recorded as the severity of each defect area;

[0113] Use the norm() function to perform linear normalization on the severity of each defect area to obtain the normalized severity of each defect area, wherein norm() is a well-known technology that normalizes the data value to the interval [0,1];

[0114] The average of the normalized severity of all defective areas is recorded as the defect degree of the tested bottle bottom;

[0115] The outer packaging bottle bottom with a defect degree less than a preset defect area threshold is recorded as a qualified outer packaging, thereby completing the intelligent defect detection of the milk outer packaging.

[0116] So far, the present invention is completed.

[0117] In summary, in the embodiment of the present invention, the grayscale image of the bottle bottom is obtained and the suspected area is obtained, the 8-neighborhood grayscale uniformity of each pixel point of the grayscale image of the bottle bottom is calculated, and then the target area is screened out, and a number of highlight points are screened out in each target area. According to the 8-neighborhood grayscale uniformity and gradient of the highlight points and the surrounding pixels, a number of defective areas are screened out in all target areas, and the missed defective areas are found according to the characteristics of the defective areas. According to the position distribution of all defective areas in the grayscale image of the bottle bottom, it is judged whether the outer packaging of the bottle bottom is a qualified outer packaging. The present invention screens interference information according to the grayscale difference and edge characteristics between regions, and finally determines the defective area, which effectively improves the accuracy and efficiency of the prior art in identifying defects in the outer packaging of bottled milk, and reduces the loss of detailed information.

[0118] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present invention should be included in the protection scope of the present invention.

Claims

1. An intelligent defect detection method for milk packaging, characterized in that: The method comprises the following steps: Obtain a grayscale image of the bottle bottom; perform threshold segmentation on the grayscale image of the bottle bottom to obtain suspected areas; obtain an edge chain code sequence for each suspected area; According to the gradient amplitude and gray value of all pixels in the bottle bottom gray image, the 8-neighborhood gray uniformity of each pixel in the bottle bottom gray image is obtained; according to the 8-neighborhood gray uniformity of all pixels in the bottle bottom gray image and the edge chain code sequence of each suspected area, the target area is screened out from all suspected areas in the bottle bottom gray image; According to the grayscale values ​​of all pixels in each target area, several highlight points are screened out on all edge lines in each target area; according to the grayscale uniformity and gradient of the 8-neighborhood of the highlight point and its surrounding pixels, several defect areas are screened out in all target areas; Perform morphological operations on all defective areas to obtain several possible connected domains; select several defective areas from the several possible connected domains; According to the position distribution of all defective areas in the grayscale image of the bottle bottom, determine whether the outer packaging of the bottle bottom is qualified; The specific calculation formula for obtaining the 8-neighborhood grayscale uniformity of each pixel point in the bottle bottom grayscale image according to the gradient amplitude and grayscale value of all pixels in the bottle bottom grayscale image is: In the formula, The grayscale image of the bottle bottom Grayscale uniformity of the 8-neighborhood of each pixel; The grayscale image of the bottle bottom The sum of the gradient amplitudes of all pixels in the 8-neighborhood of a pixel; The grayscale image of the bottle bottom The mean gray value of all pixels in the 8-neighborhood of a pixel; Represents the mean grayscale value of all pixels in the grayscale image of the bottle bottom; The grayscale image of the bottle bottom The variance of the grayscale values ​​of all pixels in the 8-neighborhood of a pixel; The specific steps of screening out the target area from all the suspected areas in the bottle bottom grayscale image according to the 8-neighborhood grayscale uniformity of all pixels in the bottle bottom grayscale image and the edge chain code sequence of each suspected area are as follows: According to the 8-neighborhood grayscale uniformity of all pixels in the grayscale image of the bottle bottom, the degree to which each suspected area meets the defect characteristics is obtained; Among all the suspected areas of the grayscale image of the bottle bottom, the suspected area whose degree of conformity to the defect feature is greater than a preset degree threshold of the defect feature is recorded as the target area; The specific calculation formula for obtaining the degree to which each suspected area meets the defect characteristics based on the 8-neighborhood grayscale uniformity of all pixels in the bottle bottom grayscale image is: In the formula, Indicates The degree to which the suspected area meets the defect characteristics; Indicates The number of pixels in the suspected area; Indicates In the suspected area Grayscale uniformity of the 8-neighborhood of each pixel; Represents the mean value of the grayscale uniformity of the 8-neighborhood of all pixels in the grayscale image of the bottle bottom; Indicates The maximum number of consecutive repeated chain codes in the edge chain code sequence of the suspected region; is a linear normalization function; The specific steps of screening out several defective areas in all target areas according to the grayscale uniformity and gradient of the 8-neighborhood of the highlight point and its surrounding pixels are as follows: In the In the target area, obtain the normal of each highlight point on all edge lines, and on the normal of each highlight point, add the adjacent front edges of each highlight point to the normal of each highlight point. pixel point, denoted as The pixel points to be detected corresponding to the highlight points in the target area, where is the preset number of pixels; According to the 8-neighborhood grayscale uniformity and gradient direction vector of all the pixels to be detected in each target area, the degree to which each pixel to be detected of each highlight point in each target area conforms to the pixel of the text area is obtained; Among all the pixels to be detected in each target area, the pixels to be detected whose degree of conformity with the pixels in the text area is greater than a preset effective pixel threshold are recorded as effective pixels; According to the degree to which all the pixels to be detected in each target area conform to the pixels in the text area and the number of valid pixels, the degree to which each target area conforms to the text area is obtained; Among all target areas, a target area whose degree of conformity to the text area is less than a preset defect area threshold is recorded as a defect area; The specific calculation formula for obtaining the degree to which each pixel to be detected of each highlight point in each target area conforms to the pixel of the text area according to the grayscale uniformity and gradient direction vector of the 8-neighborhood of all the pixels to be detected in each target area is: In the formula, Indicates The target area Highlight No. The degree to which the pixels to be detected match the pixels in the text area; Indicates The target area Highlight No. Grayscale uniformity of the 8-neighborhood of the pixel to be detected; Indicates The target area Highlight No. Grayscale uniformity of the 8-neighborhood of the pixel to be detected that is symmetrical about the highlight point on the corresponding normal line; Indicates The target area Highlight No. The gradient of the pixel to be detected; Indicates The target area Highlight No. The gradient of the pixel to be detected; express and The degree of the angle; is the absolute value function; is a linear normalization function; The specific calculation formula for obtaining the degree to which each target area conforms to the text area according to the degree to which all the pixels to be detected in each target area conform to the pixels in the text area and the number of valid pixels is: In the formula, Indicates The degree to which the target area fits the text area; Indicates The number of all pixels to be detected in the target area; Indicates In the target area The degree to which the pixels to be detected match the pixels in the text area; Indicates The number of all valid pixels in the target area; is a linear normalization function.

2. The intelligent defect detection method for milk packaging according to claim 1 is characterized in that: The specific steps of selecting a plurality of highlight points on all edge lines in each target area according to the grayscale values ​​of all pixels in each target area are as follows: In the The first line on all edges of the target area In the 8-neighborhood of edge pixels, when the The gray value of the edge pixel is greater than The gray values ​​of all pixels in the 8-neighborhood of the edge pixel and the When the number of pixels with grayscale values ​​greater than the average grayscale value in the 8-neighborhood of the edge pixel is greater than or equal to the preset number of pixels, the first The edge pixels are recorded as highlight points.

3. The intelligent defect detection method for milk packaging according to claim 1 is characterized in that: The specific steps of selecting a plurality of defective regions from a plurality of possible connected domains are as follows: Perform circle fitting on the grayscale image of the bottle bottom, and obtain the circle with the largest radius in the fitting result, which is recorded as the outermost circle curve of the bottle bottom; The pixel points in the intersection of all the 8-neighborhood pixel points of all the pixel points of the outermost circular curve of the bottle bottom and all the pixel points of each possible connected domain are recorded as the pixel points of each possible connected domain on the outermost circular curve of the bottle bottom; The linear normalized value of the quotient of the number of pixels of each possible connected domain on the outermost circular curve of the bottle bottom and the average value of the shortest distance from all edge pixels in each possible connected domain to the outermost circular curve of the bottle bottom is recorded as the degree to which each possible connected domain conforms to the texture of the glass bottle itself; Among all possible connected domains, the possible connected domains whose degree of conformity to the texture of the glass bottle itself is greater than a preset defect region threshold are recorded as defect regions.

4. The intelligent defect detection method for milk packaging according to claim 1 is characterized in that: The specific steps of judging whether the outer packaging of the bottle bottom is qualified according to the position distribution of all defective areas in the grayscale image of the bottle bottom are as follows: In the grayscale image of the bottle bottom, the product of the shortest distance from the center of gravity of each defect area to the center of the outermost circle of the bottle bottom and the number of all pixels in the defect area is recorded as the severity of each defect area; Performing linear normalization on the severity of each defect area to obtain the normalized severity of each defect area; The average of the normalized severity of all defective areas is recorded as the defect degree of the tested bottle bottom; The outer packaging bottle bottom with a defect degree less than the preset defect area threshold is recorded as a qualified outer packaging.

Citation Information

Patent Citations

  • Paper product printing defect detection method

    CN117541588A

  • Large-aperture telescope lens defect detection method based on artificial intelligence

    CN117745715A