Efficient detection method of paper cup defects based on machine vision

Machine vision technology is used to perform grayscale processing and connected domain analysis on the bottom of the paper cup, which solves the inaccuracy problem of traditional detection methods, achieves higher accuracy in detecting damage to the bottom of the paper cup, and ensures the reliability of product quality.

CN118314136BActive Publication Date: 2024-09-03ZHEJIANG MINGXING PACKAGING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410733413.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-07
Publication Date
2024-09-03
Estimated Expiration
2044-06-07

Smart Images

  • Figure CN118314136B
    Figure CN118314136B
Patent Text Reader

Abstract

The present application relates to the field of image analysis, and specifically to an efficient method for detecting paper cup defects based on machine vision, including: confirming a connected domain according to the damage probability corresponding to each pixel in the initial grayscale image corresponding to the image of the bottom of the paper cup, and then calculating the damage probability of the initial connected domain corresponding to the target connected domain, and then calculating the final connected domain damage probability corresponding to the target connected domain through the number of approximate connected domains corresponding to the target connected domain, the damage probability of the initial connected domain, and the total number of connected domains corresponding to the initial grayscale image, and finally confirming whether the bottom of the paper cup is damaged based on the final connected domain damage probability corresponding to the target connected domain. The connected domain is confirmed by the grayscale value of the pixel points of the initial grayscale image corresponding to the image of the bottom of the paper cup, and further confirmed whether the paper cup is damaged according to the damage probability of the final connected domain corresponding to the connected domain. Compared with the traditional method for detecting the damage of the bottom of the paper cup, the accuracy of detecting the damage of the paper cup is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of image analysis, and in particular to an efficient method for detecting paper cup defects based on machine vision. Background Art

[0002] Disposable paper cups usually refer to paper drinking containers that are designed to be discarded after a single use. The characteristics of these paper cups are that they are usually light, inexpensive, and can be easily replaced after use. The types of paper cups can be classified according to their uses, such as cold drink cups, hot drink cups, and yogurt cups. Cold drink cups are suitable for cold drinks, while hot drink cups are suitable for hot drinks. The production process of disposable paper cups has undergone many changes. Initially, the production of paper cups mainly relied on manual or simple mechanical equipment. With the advancement of industrialization, the production of paper cups began to adopt automated production lines, which greatly improved production efficiency. Modern paper cup production lines can complete the entire process from base paper to finished products automatically.

[0003] In the traditional production process of paper cups, the assembly of the bottom of the paper cup usually causes the bottom of the paper cup to be subjected to greater friction. Excessive friction may cause minor damage to the bottom of the paper cup, which is difficult to detect manually in time. If drinks are put in, the drinks will spill, giving customers a bad experience and affecting the reputation of the product. The traditional detection of damage at the bottom of paper cups is done by traditional edge detection. However, the traditional edge detection method is prone to incomplete detection of damage at the bottom of paper cups, resulting in a high frequency of misjudgment and low detection accuracy. Summary of the invention

[0004] In view of the above, it is necessary to provide an efficient paper cup defect detection method based on machine vision, which improves the accuracy of paper cup defects compared with traditional paper cup defect detection methods.

[0005] In a first aspect, the present application provides an efficient paper cup defect detection method based on machine vision, which is applied to the field of paper cup defect detection. The method comprises: graying the image of the bottom of the paper cup to obtain an initial gray image corresponding to the image of the bottom of the paper cup; confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel; calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain; confirming the approximate connected domain corresponding to the target connected domain according to the initial connected domain damage probability corresponding to the target connected domain; calculating the final connected domain damage probability corresponding to the target connected domain by the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial gray image; confirming whether the bottom of the paper cup is damaged based on the final connected domain damage probability corresponding to the target connected domain.

[0006] In one of the embodiments, the method of confirming the pixel damage probability corresponding to each pixel according to the grayscale value corresponding to the pixel in the initial grayscale image, so as to confirm the connected domain corresponding to the initial grayscale image according to the damage probability corresponding to each pixel, specifically includes: calculating the grayscale value difference value and the second variance corresponding to the target pixel according to the grayscale value of the target pixel in the initial grayscale image, wherein the grayscale value difference value refers to the difference between the grayscale value average value of a preset sliding window centered on the target pixel and the grayscale value average value of the initial grayscale image, and the second variance refers to the variance of the grayscale value of the preset sliding window centered on the target pixel; inputting the grayscale value difference value and the second variance corresponding to the target pixel into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel; converting the initial grayscale image into a binary image according to the comparison result of the pixel damage probability corresponding to the target pixel and a preset first threshold value, so as to perform connected domain detection on the binary image and obtain the connected domain corresponding to the initial grayscale image.

[0007] In one embodiment, the grayscale value difference value corresponding to the target pixel and the second variance are input into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel, specifically including:

[0008]

[0009] in, The target pixel The corresponding pixel damage probability, is the average gray value of the initial gray image, The target pixel The average gray value of the preset sliding window centered at The target pixel The gray value of The target pixel The corresponding second variance, is the normalization function.

[0010] In one of the embodiments, the initial grayscale image is converted into a binary image based on a comparison result of a pixel damage probability corresponding to the target pixel with a preset first threshold value, so as to perform a connected domain detection on the binary image and obtain a connected domain corresponding to the initial grayscale image, specifically comprising: assigning the grayscale value of the target pixel whose pixel damage probability is greater than the preset first threshold value to the highest grayscale value, and assigning the grayscale value of the target pixel whose pixel damage probability is less than or equal to the preset first threshold value to the lowest grayscale value, to obtain a binary image corresponding to the initial grayscale image; and performing a connected domain detection on the binary image corresponding to the initial grayscale image by using a preset connected domain detection algorithm to obtain a connected domain corresponding to the initial grayscale image.

[0011] In one of the embodiments, the calculation of the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the mean of the first-order difference code corresponding to the target connected domain specifically includes: calculating the average pixel damage probability corresponding to the target connected domain with the first variance according to the grayscale values ​​of all pixels in the target connected domain; confirming the chain code values ​​of a number of chain codes of the target connected domain based on the shape of the target connected domain corresponding to the approximate polygon, so as to confirm the mean of the first-order difference code corresponding to the target connected domain; inputting the average pixel damage probability, the first variance and the mean of the first-order difference code corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain.

[0012] In one embodiment, the step of inputting the average pixel damage probability, the first variance, and the first-order differential code mean corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain specifically includes:

[0013]

[0014] in, The target connected domain The corresponding initial connected domain damage probability, The target connected domain Target pixel The corresponding pixel damage probability, The target connected domain The number of pixels in The target connected domain The corresponding first variance is, The target connected domain The corresponding The chain code value of the first-order difference code, The target connected domain The number of all first-order difference codes in .

[0015] In one of the embodiments, the method of confirming the approximate connected domain corresponding to the target connected domain based on the damage probability of the initial connected domain corresponding to the target connected domain specifically includes: calculating a number of similarity probability values ​​corresponding to the target connected domain based on the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distance between the nearest pixel point; and confirming other connected domains with similarity probability values ​​greater than a second threshold as the approximate connected domain corresponding to the target connected domain.

[0016] In one embodiment, the calculating of a number of similarity probability values ​​corresponding to the target connected domain according to the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distance to the nearest pixel point specifically includes:

[0017]

[0018] in, The target connected domain With other connected domains The corresponding similarity probability value is, The target connected domain The corresponding initial connected domain damage probability, For other connected domains The corresponding initial connected domain damage probability, The target connected domain With other connected domains The nearest pixel distance, is the normalization function.

[0019] In one embodiment, calculating the final connected domain damage probability corresponding to the target connected domain by using the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability, and the total number of connected domains corresponding to the initial grayscale image specifically includes:

[0020]

[0021] in, The target connected domain The corresponding final connected domain damage probability, The target connected domain The corresponding initial connected domain damage probability, The target connected domain The number of corresponding approximately connected domains, The target connected domain The angle between any two other approximately connected domains, is the total number of connected domains corresponding to the initial grayscale image, is the normalization function.

[0022] In one of the embodiments, the confirming whether the bottom of the paper cup is damaged based on the damage probability of the final connected domain corresponding to the target connected domain specifically includes: when the damage probability of the final connected domain corresponding to the target connected domain is greater than the first damage threshold, confirming that the paper cup corresponding to the target connected domain is in a damaged state; when the damage probability of the final connected domain corresponding to the target connected domain is less than or equal to the first damage threshold, confirming that the paper cup corresponding to the target connected domain is in a normal state.

[0023] The embodiment of the present application provides an efficient method for detecting paper cup defects based on machine vision, the method comprising: first graying the bottom image of the paper cup to obtain an initial gray image corresponding to the bottom image of the paper cup, then confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel, then calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain, and confirming the approximate connected domain corresponding to the target connected domain according to the initial connected domain damage probability corresponding to the target connected domain, and then calculating the final connected domain damage probability corresponding to the target connected domain according to the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial gray image, and finally confirming whether the bottom of the paper cup is damaged based on the final connected domain damage probability corresponding to the target connected domain. The connected domain is confirmed by the pixel gray value of the initial gray image corresponding to the bottom image of the paper cup, and further confirmed whether the paper cup is damaged according to the final connected domain damage probability corresponding to the connected domain. Compared with the traditional detection of damaged bottom of paper cups, the detection accuracy of damaged area at the bottom of paper cups is improved, and the accuracy of damaged detection of paper cups is further improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a flow chart of an efficient method for detecting paper cup defects based on machine vision according to an embodiment of the present application.

[0025] Figure 2 This is a schematic diagram of the first sub-process of an efficient method for detecting paper cup defects based on machine vision in an embodiment of the present application.

[0026] Figure 3 This is a schematic diagram of the second sub-process of an efficient method for detecting paper cup defects based on machine vision in an embodiment of the present application.

[0027] Figure 4 This is a schematic diagram of the third sub-process of an efficient method for detecting paper cup defects based on machine vision in an embodiment of the present application.

[0028] Figure 5 This is a schematic diagram of the fourth sub-process of an efficient method for detecting paper cup defects based on machine vision in an embodiment of the present application.

[0029] Figure 6 This is a fifth sub-process diagram of an efficient paper cup defect detection method based on machine vision in an embodiment of the present application. DETAILED DESCRIPTION

[0030] In the description of the embodiments of the present application, words such as "exemplary", "or", "for example" and the like are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary", "or", "for example" and the like is intended to present related concepts in a concrete manner.

[0031] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those generally understood by technicians in the technical field in this application. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. It should be understood that, unless otherwise specified in this application, " / " means or. For example, A / B can represent A or B. "And / or" in this application is only a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. "At least one" means one or more. "Multiple" means two or more than two. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, a, b and c seven situations.

[0032] It should also be noted that the terms "first" and "second" in the specification, claims and drawings of this application are used to distinguish similar objects, rather than to describe a specific order or sequence. The method disclosed in the embodiments of this application or the method shown in the flowchart includes one or more steps for implementing the method. Without departing from the scope of the claims, the execution order of multiple steps can be interchanged with each other, and some steps can also be deleted.

[0033] The present application embodiment first proposes an efficient paper cup defect detection method based on machine vision, which is applied to the field of paper cup defect detection. Figure 1 , the method comprises the following steps:

[0034] S101, graying the image of the bottom of the paper cup to obtain an initial gray image corresponding to the image of the bottom of the paper cup.

[0035] The paper cup bottom image is an image obtained by pre-setting a shooting device to shoot the bottom of the paper cup during the production process of the paper cup. After the paper cup bottom image is obtained, the paper cup bottom image is pre-processed to obtain an initial grayscale image corresponding to the paper cup bottom image. The pre-processing includes roughly extracting the suspected damaged area in the collected paper cup bottom image, graying it, smoothing the image and enhancing the image to enhance the subsequent extraction of the damaged area.

[0036] It should be noted that the production process of paper cups is usually as follows: first, the PE coated paper is cut, printed, and die-cut to obtain the fan-shaped paper sheets required for the side walls of the paper cups and the roll paper required for the bottom, and then sent to the paper cup machine for assembly. In the process of punching the bottom of the cup, in order to form a flat and neat bottom of the paper cup, pressure is usually applied to the bottom of the paper cup, which is likely to cause scratches on the bottom of the paper cup and cause damage. Therefore, in the production process of paper cups, the bottom of the paper cup is easily damaged and broken due to pressure or scratches in the production process, so it is extremely important to detect the damage of the bottom of the paper cup.

[0037] Furthermore, the slightly damaged area on the bottom of the paper cup caused by abrasions includes the following features: 1) For severely abraded areas, the bottom of the paper cup may be damaged, where the damaged areas appear as black spots one by one, with a low grayscale value, and each damaged area is on the same straight line; 2) For areas with less abrasions, no damage is caused, only the rough edges of the bottom of the paper cup are caused, and the overall grayscale value is slightly lower than that of the intact paper area; 3) The abraded damaged area is irregular as a whole. When the bottom of the paper cup is subsequently tested for damage, the above three features are combined for comprehensive evaluation to increase the accuracy of the detection.

[0038] S102, confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel.

[0039] Among them, the pixel damage probability refers to the probability that the pixel is a damaged area in the image of the bottom of the paper cup. Furthermore, the pixel damage probability corresponding to the pixel is the probability of whether it is a damaged area in the image of the bottom of the paper cup derived from the difference in grayscale values ​​between the target pixel and the surrounding or the entire initial grayscale image. The connected domain corresponding to the initial grayscale image refers to a connected domain formed by binarizing the pixel damage probability corresponding to the pixel in the initial grayscale image and then performing continuous expansion and corrosion operations. For example, the pixel points with a pixel damage probability greater than 0.8 in the initial grayscale image are regarded as pixels in the scratched and damaged area, and the grayscale values ​​of the pixels in the scratched and damaged area are assigned to the highest grayscale value (255), and the grayscale values ​​of other pixels are assigned to the lowest grayscale value (0), then a binary image is obtained, and the connected domain corresponding to the initial grayscale image is obtained by detecting the connected domain of the binary image.

[0040] S103: Calculate the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance, and the first-order difference code mean corresponding to the target connected domain.

[0041] Among them, the average pixel damage probability corresponding to the target connected domain refers to the average value of the pixel damage probability of all pixels in the target connected domain, the first variance corresponding to the target connected domain refers to the variance calculated based on the pixel damage probability of all pixels in the target connected domain, and the first-order differential code mean corresponding to the target connected domain refers to the average value of the chain code of the polygon obtained based on the approximate polygon of the boundary of the target connected domain. The initial connected domain damage probability corresponding to the target connected domain refers to the possibility that the target connected domain is a damaged area. The target connected domain refers to any connected domain of the above connected domains.

[0042] S104: According to the damage probability of the initial connected domain corresponding to the target connected domain, an approximate connected domain corresponding to the target connected domain is confirmed.

[0043] Among them, the approximate connected domain corresponding to the target connected domain refers to other connected domains that belong to the same damaged area as the target connected domain. It should be understood that due to different factors causing scratches or damage to the bottom of the paper cup, there may be multiple connected domains belonging to the same damaged area. For example, the external force during scratching is uneven, resulting in multiple connected domains for the same damage factor. Furthermore, the subsequent damage judgment of the bottom of the paper cup can be made in combination with the approximate connected domain corresponding to the target connected domain, which can more comprehensively and accurately confirm whether it is damaged from multiple aspects.

[0044] S105 , calculating a final connected domain damage probability corresponding to the target connected domain by using the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability, and the total number of connected domains corresponding to the initial grayscale image.

[0045] Among them, after obtaining the approximate number of connected domains corresponding to the target connected domain, the damage probability of the initial connected domain, and the total number of connected domains corresponding to the initial grayscale image, the three are used as calculation parameters, and the final connected domain damage probability corresponding to the target connected domain is further calculated through the preset calculation rules. The final connected domain damage probability corresponding to the target connected domain refers to the possibility of whether the target connected domain is a damaged area, which is obtained by combining factors such as the gray value difference between the damaged area and the normal area and the overall irregular state of the scratched and damaged area. After obtaining the final connected domain damage probability corresponding to the target connected domain, it is confirmed whether the bottom of the paper cup is damaged according to the final connected domain damage probability corresponding to the target connected domain, and further confirmed whether the quality of the paper cup meets the requirements.

[0046] S106: Determine whether the paper cup is damaged based on the damage probability of the final connected domain corresponding to the target connected domain.

[0047] After the damage probability of the final connected domain corresponding to the target connected domain is obtained, whether the paper cup is damaged is confirmed according to the comparison result of the damage probability of the final connected domain corresponding to the target connected domain and a preset first damage threshold.

[0048] For details, please refer to the attached Figure 2 , the determining whether the bottom of the paper cup is damaged based on the damage probability of the final connected domain corresponding to the target connected domain specifically includes:

[0049] S201, when the damage probability of the final connected domain corresponding to the target connected domain is greater than a first damage threshold, confirming that the paper cup corresponding to the target connected domain is in a damaged state;

[0050] S202: When the damage probability of the final connected domain corresponding to the target connected domain is less than or equal to a first damage threshold, confirm that the paper cup corresponding to the target connected domain is in a normal state.

[0051] After the damage probability of the final connected domain corresponding to the target connected domain is obtained, it is compared with the preset first damage threshold, and when a target connected domain corresponding to the damage probability of the final connected domain greater than the first damage threshold appears, it is confirmed that the paper cup corresponding to the target connected domain is in a damaged state. When there is no target connected domain corresponding to the damage probability of the final connected domain greater than the first damage threshold, it is confirmed that the paper cup corresponding to the target connected domain is in a normal state.

[0052] In some other possible embodiments, the damage state is further divided into two types: a severe scratch state and a slight scratch state. Specifically, when the target connected domain is greater than a first damage threshold and less than a second damage threshold, the paper cup corresponding to the target connected domain is confirmed to be slightly scratched; when the target connected domain is greater than the second damage threshold, the paper cup corresponding to the target connected domain is confirmed to be severely scratched. The second damage threshold is greater than the first damage threshold.

[0053] The embodiment of the present application provides an efficient method for detecting paper cup defects based on machine vision, the method comprising: first graying the bottom image of the paper cup to obtain an initial gray image corresponding to the bottom image of the paper cup, then confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel, then calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain, and confirming the approximate connected domain corresponding to the target connected domain according to the initial connected domain damage probability corresponding to the target connected domain, and then calculating the final connected domain damage probability corresponding to the target connected domain according to the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial gray image, and finally confirming whether the bottom of the paper cup is damaged based on the final connected domain damage probability corresponding to the target connected domain. The connected domain is confirmed by the pixel gray value of the initial gray image corresponding to the bottom image of the paper cup, and further confirmed whether the paper cup is damaged according to the final connected domain damage probability corresponding to the connected domain. Compared with the traditional detection of damaged bottom of paper cups, the detection accuracy of damaged area at the bottom of paper cups is improved, and the accuracy of damaged detection of paper cups is further improved.

[0054] In one embodiment of the present application, see Figure 3 The step S102: confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel, specifically includes:

[0055] S301. Calculate a grayscale value difference value and a second variance corresponding to the target pixel point according to the grayscale value of the target pixel point in the initial grayscale image, wherein the grayscale value difference value refers to the difference between the grayscale value average value of a preset sliding window centered on the target pixel point and the grayscale value average value of the initial grayscale image, and the second variance refers to the variance of the grayscale value of the preset sliding window centered on the target pixel point.

[0056] Among them, after obtaining the grayscale value of the target pixel in the initial grayscale image, the target pixel refers to any pixel in the initial grayscale image, and the grayscale value average of the preset sliding window centered on the target pixel and the grayscale value average of the initial grayscale image are counted. The size of the preset sliding window can be defined according to the actual application scenario. For example, the size of the preset sliding window can be 5×5 pixels. Then, the grayscale value average of the preset sliding window centered on the target pixel and the grayscale value average of the initial grayscale image are further calculated to obtain the grayscale value difference value corresponding to the target pixel. The grayscale value difference value corresponding to the target pixel is used to characterize the difference in grayscale value between the preset sliding window centered on the target pixel and the initial grayscale image. Because the grayscale value of the damaged area is greatly different from the grayscale value of the normal area, the larger the grayscale value difference value corresponding to the target pixel is, the more it can prove that the current target pixel is more likely to be a pixel in the damaged area. The second variance refers to the variance of the grayscale value of a preset sliding window centered on the target pixel point. When the variance of the grayscale value within the preset sliding window centered on the target pixel point is larger, it proves that the degree of discreteness of the area where the target pixel point is located is larger, indicating that the grayscale value near the target pixel point varies greatly, which is consistent with the characteristics of the damaged area, that is, the target pixel point is more likely to be a pixel point in the damaged area.

[0057] S302: Input the grayscale value difference value corresponding to the target pixel and the second variance into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel.

[0058] After obtaining the grayscale value difference value and the second variance corresponding to the target pixel point, the grayscale value difference value and the second variance corresponding to the target pixel point are used as calculation parameters and input into a preset pixel damage probability calculation formula to further calculate the pixel damage probability corresponding to the target pixel point. The pixel damage probability corresponding to the target pixel point refers to the possibility that the target pixel point is a pixel point in the damaged area.

[0059] Specifically, the gray value difference value corresponding to the target pixel and the second variance are input into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel, specifically including:

[0060]

[0061] in, The target pixel The corresponding pixel damage probability, is the average gray value of the initial gray image, The target pixel The average gray value of the preset sliding window centered at The target pixel The gray value of The target pixel The corresponding second variance, is a logarithmic function with a constant base of 2, is the normalization function.

[0062] Furthermore, is the grayscale value difference value corresponding to the target pixel, that is, the difference between the grayscale value average value of the preset sliding window centered on the target pixel and the grayscale value average value of the initial grayscale image. When the grayscale value difference value corresponding to the target pixel is larger, it proves that the grayscale value around the target pixel and the grayscale value of the overall initial grayscale image have a large change, which meets the grayscale value distribution characteristics of the damaged area. At the same time, the second variance corresponding to the target pixel The larger the value is, the greater the grayscale value discreteness of the preset sliding window where the target pixel is located, and it also meets the grayscale value distribution characteristics of the damaged area. is a logarithmic function with a constant of 2 as the base. The grayscale value difference corresponding to the target pixel is proportional to the dependent variable pixel damage probability. At the same time, the grayscale value difference corresponding to the target pixel is proportional to the dependent variable pixel damage probability. The second variance corresponding to the target pixel is proportional to the damage probability. Therefore, when the gray value difference value corresponding to the target pixel point is The second variance corresponding to the target pixel When the value is larger, the damage probability corresponding to the target pixel is greater, and the target pixel is more likely to be a pixel in the damaged area.

[0063] S303. According to the comparison result of the pixel damage probability corresponding to the target pixel and the preset first threshold, the initial grayscale image is converted into a binary image to perform connected domain detection on the binary image to obtain the connected domain corresponding to the initial grayscale image.

[0064] After obtaining the pixel damage probability corresponding to the target pixel, the pixel damage probability corresponding to the target pixel is compared with a preset first threshold to confirm the comparison result. Then, based on the comparison result, the target pixel in the initial grayscale image is assigned a grayscale value to convert the initial grayscale image into a binary image. The binary image refers to an image with only a maximum grayscale value of 255 and a minimum grayscale value of 0. After obtaining the initial grayscale image converted into a binary image, a connected domain detection is performed on it through a preset detection algorithm to obtain a connected domain corresponding to the initial grayscale image.

[0065] For details, please refer to the attached Figure 4, the initial grayscale image is converted into a binary image according to the comparison result of the pixel damage probability corresponding to the target pixel and the preset first threshold, so as to perform connected domain detection on the binary image and obtain the connected domain corresponding to the initial grayscale image, specifically including:

[0066] S401, assigning the grayscale value of the target pixel point whose pixel damage probability is greater than the preset first threshold to the highest grayscale value, assigning the grayscale value of the target pixel point whose pixel damage probability is less than or equal to the preset first threshold to the lowest grayscale value, and obtaining a binary image corresponding to the initial grayscale image.

[0067] Among them, because the probability of pixel damage is a normalized value, the value range of the preset first threshold is [0,1]. Preferably, the preset first threshold is 0.8. The value of the maximum grayscale value can be 255, and the value of the minimum grayscale value can be 0. When the target pixel point whose probability of pixel damage is greater than the preset first threshold is regarded as a pixel point with a greater possibility of being a damaged area, its grayscale value is assigned the highest grayscale value to highlight it. When the target pixel point whose probability of pixel damage is less than or equal to the preset first threshold is regarded as a pixel point with a greater possibility of being a normal area, its grayscale value is assigned the lowest grayscale value to fade it, and at the same time, the pixel point with a greater possibility of being a damaged area is highlighted.

[0068] S402 , performing connected domain detection on the binary image corresponding to the initial grayscale image using a preset connected domain detection algorithm to obtain a connected domain corresponding to the initial grayscale image.

[0069] Among them, after obtaining the binary image corresponding to the initial grayscale image, since there are only two kinds of pixel points with grayscale values, namely, the maximum grayscale value and the minimum grayscale value, in the binary image (the maximum grayscale value means that the pixel point is more likely to be a pixel point in the damaged area, and the minimum grayscale value means that the pixel point is more likely to be a pixel point in the normal area), the pixel points corresponding to the maximum grayscale value will form a connected domain if they are close to each other. The connected domain detection is performed on the binary image corresponding to the initial grayscale image by a preset connected domain detection algorithm to obtain the connected domain corresponding to the initial grayscale image. That is, the connected domain corresponding to the initial grayscale image is a connected domain composed of pixel points that are more likely to be in the damaged area. For example, the grayscale value of the pixel points with a probability of pixel damage greater than 0.8 is set to 255, and the grayscale values ​​of other pixel points are set to 0. At this time, the initial grayscale image is converted into a binary image, and then the binary image is continuously expanded and eroded until a connected domain is formed, and the connected domain is extracted by a preset connected domain detection algorithm to obtain the connected domain corresponding to the initial grayscale image.

[0070] In one embodiment of the present application, refer to the attached Figure 5Step S103, calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain, specifically includes:

[0071] S501. Calculate an average pixel damage probability and a first variance corresponding to the target connected domain according to pixel damage probabilities of all pixels in the target connected domain.

[0072] Among them, after obtaining the pixel damage probability of all pixels in the target connected domain, the average pixel damage probability corresponding to the target connected domain is calculated according to the pixel damage probability of all pixels in the target connected domain. At the same time, the first variance calculation corresponding to the target connected domain is performed according to the preset variance calculation formula and the pixel damage probability of all pixels in the target connected domain. When the average pixel damage probability corresponding to the target connected domain is larger, it proves that the target connected domain is more likely to be the local area corresponding to the damaged area. When the first variance corresponding to the pixel damage probability of all pixels in the target connected domain is larger, it proves that the pixel damage probability of all pixels in the target connected domain is more discrete, and the target connected domain is less likely to be the local area corresponding to the damaged area.

[0073] S502: based on the approximate polygon corresponding to the shape of the target connected domain, determine the chain code corresponding to the target connected domain to determine the mean value of the first-order differential code corresponding to the target connected domain.

[0074] Among them, the approximate polygon of the target connected domain is first solved based on the shape of the target connected domain. After the approximate polygon of the target connected domain is obtained, the chain code of the polygon is further calculated, preferably using 8 chain codes, and finally a number of first-order differential codes are calculated according to the chain code of the polygon, and one first-order differential code corresponds to one chain code value to confirm the mean of the first-order differential codes corresponding to the target connected domain.

[0075] S503: Input the average pixel damage probability, the first variance, and the first-order differential code mean corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain.

[0076] Among them, after obtaining the average pixel damage probability, the first variance and the first-order differential code mean corresponding to the target connected domain, the three are used as calculation parameters, and the preset initial connected domain damage probability calculation formula is input to calculate the initial connected domain damage probability corresponding to the target connected domain.

[0077] Specifically, the inputting the average pixel damage probability, the first variance, and the first-order difference code mean corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain specifically includes:

[0078]

[0079] in, The target connected domain The corresponding initial connected domain damage probability, The target connected domain Target pixel The corresponding pixel damage probability, The target connected domain The number of pixels in The target connected domain The corresponding first variance is, The target connected domain The corresponding The chain code value of the first-order difference code, The target connected domain The number of all first-order difference codes in .

[0080] Furthermore, The target connected domain The average pixel damage probability corresponding to the pixel damage probability of all pixels in the target connected domain is the average pixel damage probability corresponding to the pixel damage probability of all pixels in the target connected domain. The larger the pixel damage probability is, the more likely the corresponding pixel is to be a damaged area. Therefore, when the average pixel damage probability corresponding to the target connected domain is When the value is larger, the target connected domain is more likely to be a local area of ​​the damaged area. is the inverse of the first variance corresponding to the target connected domain. Since the first variance is inversely proportional to whether it is a damaged area, the larger the inverse of the first variance corresponding to the target connected domain is, the more likely the target connected domain is to be a local area of ​​the damaged area. is the mean of the first-order differential code corresponding to the target connected domain. The larger the mean of the first-order differential code corresponding to the target connected domain, the more irregular the boundary of the target connected domain is, the more it conforms to the characteristics of the damaged area, and the more likely the target connected domain is a local area of ​​the damaged area. Therefore, in summary, the initial connected domain corresponding to the target connected domain is damaged. When the value is larger, the target connected domain is more likely to be a local area of ​​the damaged area.

[0081] In one embodiment of the present application, refer to the attached Figure 6 Step S104, confirming the approximate connected domain corresponding to the target connected domain according to the damage probability of the initial connected domain corresponding to the target connected domain, specifically includes:

[0082] S601, calculating a number of similarity probability values ​​corresponding to the target connected domain according to the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distances to the nearest pixel points.

[0083] Among them, after obtaining the initial connected domain damage probabilities corresponding to the target connected domain and other connected domains, the initial connected domain damage probabilities corresponding to the target connected domain and other connected domains are respectively calculated by pairwise difference to obtain the initial connected domain damage probability difference value corresponding to the target connected domain. The nearest pixel point distance refers to the distance between the two nearest pixels in the target connected domain and other connected domains. The similarity probability value corresponding to the target connected domain refers to the probability that the target connected domain and other connected domains are caused by the same damage action.

[0084] Specifically, the calculation of a number of similarity probability values ​​corresponding to the target connected domain according to the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distance to the nearest pixel point specifically includes:

[0085]

[0086] in, The target connected domain With other connected domains The corresponding similarity probability value is, The target connected domain The corresponding initial connected domain damage probability, For other connected domains The corresponding initial connected domain damage probability, The target connected domain With other connected domains The nearest pixel distance, is the normalization function.

[0087] Furthermore, is the difference in the damage probability between the target connected domain and the initial connected domain of other connected domains, is the distance between the nearest pixel point of the target connected domain and other connected domains. When the difference value of the initial connected domain damage probability between the target connected domain and other connected domains is The smaller the damage probability is, the closer the initial connected domain damage probability of the target connected domain is to that of the other connected domains, and the more likely the target connected domain and the other connected domains are caused by the same damage action. The smaller it is, the closer the target connected domain is to other connected domains, and the more likely it is that the target connected domain and other connected domains are caused by the same damage action.

[0088] S602: Identify other connected domains whose similarity probability values ​​are greater than a second threshold as approximate connected domains corresponding to the target connected domain.

[0089] When obtaining similarity probability values ​​corresponding to the target connected domain and other connected domains, the similarity probability values ​​are compared with a second threshold, and other connected domains with similarity probability values ​​greater than the second threshold are identified as approximate connected domains corresponding to the target connected domain. The second threshold is preferably 0.9.

[0090] In one embodiment of the present application, step S105, calculating the final connected domain damage probability corresponding to the target connected domain by using the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability, and the total number of connected domains corresponding to the initial grayscale image, specifically includes:

[0091]

[0092] in, The target connected domain The corresponding final connected domain damage probability, The target connected domain The corresponding initial connected domain damage probability, The target connected domain The number of corresponding approximately connected domains, The target connected domain The angle between any two other approximately connected domains, is the total number of connected domains corresponding to the initial grayscale image, is the normalization function.

[0093] further, is the angle between the target connected domain and any two other approximate connected domains, that is, the angle formed by connecting the approximate center points of the target connected domain and its corresponding two approximate connected domains. For example, the target connected domain With the first other approximately connected domain Connect the approximate center points of , at the same time, the target connected domain With the first other approximately connected domain Connect the approximate center points of , The angle ∠ When the angle between the target connected domain and any two other approximate connected domains is The smaller it is, the greater the probability that the target connected domain and its corresponding approximate connected domain are on the same straight line, and the more likely the target connected domain is to be a local area of ​​the damaged area. At the same time, when the number of approximate connected domains corresponding to the target connected domain is larger, the more likely the target connected domain is to be a local area of ​​the damaged area. Therefore, the number of approximate connected domains corresponding to the target connected domain is proportional to the angle between the target connected domain and any two other approximate connected domains. sum The larger the value, the more likely the target connected domain is a local area of ​​the damaged area. In summary, the damage probability of the initial connected domain corresponding to the target connected domain is And when the ratio of the number of approximate connected domains corresponding to the target connected domain to the total number of connected domains corresponding to the initial grayscale image is larger, the target connected domain is more likely to be a local area of ​​the damaged area. Therefore, when the damage probability of the final connected domain corresponding to the target connected domain is larger, the target connected domain is more likely to be a local area of ​​the damaged area.

[0094] The embodiment of the present application provides an efficient method for detecting paper cup defects based on machine vision, the method comprising: first graying the bottom image of the paper cup to obtain an initial gray image corresponding to the bottom image of the paper cup, then confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel, then calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain, and confirming the approximate connected domain corresponding to the target connected domain according to the initial connected domain damage probability corresponding to the target connected domain, and then calculating the final connected domain damage probability corresponding to the target connected domain according to the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial gray image, and finally confirming whether the bottom of the paper cup is damaged based on the final connected domain damage probability corresponding to the target connected domain. The connected domain is confirmed by the pixel gray value of the initial gray image corresponding to the bottom image of the paper cup, and further confirmed whether the paper cup is damaged according to the final connected domain damage probability corresponding to the connected domain. Compared with the traditional detection of damaged bottom of paper cups, the detection accuracy of damaged area at the bottom of paper cups is improved, and the accuracy of damaged detection of paper cups is further improved.

[0095] The flowchart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and the block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.

[0096] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, no matter from which point of view, the above embodiments of the present application should be regarded as exemplary and non-restrictive, and the scope of the present application is defined by the attached claims rather than the above description, and therefore it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present application.

Claims

1. An efficient paper cup defect detection method based on machine vision, applied to the field of paper cup defect detection, characterized in that: The method comprises: Grayscale the image of the bottom of the paper cup to obtain an initial grayscale image corresponding to the image of the bottom of the paper cup; Confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel; Based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain, the initial connected domain damage probability corresponding to the target connected domain is calculated; According to the damage probability of the initial connected domain corresponding to the target connected domain, an approximate connected domain corresponding to the target connected domain is determined; Calculate the final connected domain damage probability corresponding to the target connected domain by the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial grayscale image; Determining whether the paper cup is damaged based on the damage probability of the final connected domain corresponding to the target connected domain; The calculating the initial connected domain damage probability corresponding to the target connected domain based on the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain specifically includes: According to the gray values ​​of all pixels in the target connected domain, the average pixel damage probability and the first variance corresponding to the target connected domain are calculated, where the first variance refers to the first variance corresponding to the pixel damage probability of all pixels in the target connected domain; Based on the shape of the target connected domain corresponding to the approximate polygon, the chain code values ​​of a number of chain codes of the target connected domain are determined to determine the mean value of the first-order differential code corresponding to the target connected domain; Inputting the average pixel damage probability, the first variance and the first-order difference code mean corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain; The step of inputting the average pixel damage probability, the first variance, and the first-order differential code mean corresponding to the target connected domain into a preset initial connected domain damage probability calculation formula to calculate the initial connected domain damage probability corresponding to the target connected domain specifically includes: in, The target connected domain The corresponding initial connected domain damage probability, The target connected domain Target pixel The corresponding pixel damage probability, The target connected domain The number of pixels in The target connected domain The corresponding first variance is, The target connected domain The corresponding The chain code value of the first-order difference code, The target connected domain The number of all first-order difference codes in ; The calculating the final connected domain damage probability corresponding to the target connected domain by using the number of approximate connected domains corresponding to the target connected domain, the initial connected domain damage probability and the total number of connected domains corresponding to the initial grayscale image specifically includes: in, The target connected domain The corresponding final connected domain damage probability, The target connected domain The number of corresponding approximately connected domains, The target connected domain The angle between any two other approximately connected domains, is the total number of connected domains corresponding to the initial grayscale image, is the normalization function.

2. The method for efficiently detecting paper cup defects based on machine vision according to claim 1 is characterized in that: The step of confirming the pixel damage probability corresponding to each pixel according to the gray value corresponding to the pixel in the initial gray image, so as to confirm the connected domain corresponding to the initial gray image according to the damage probability corresponding to each pixel, specifically includes: According to the grayscale value of the target pixel in the initial grayscale image, a grayscale value difference value and a second variance corresponding to the target pixel are calculated, wherein the grayscale value difference value refers to the difference between the grayscale value average value of a preset sliding window centered on the target pixel and the grayscale value average value of the initial grayscale image, and the second variance refers to the variance of the grayscale value of the preset sliding window centered on the target pixel; Inputting the gray value difference value corresponding to the target pixel and the second variance into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel; According to the comparison result of the pixel damage probability corresponding to the target pixel and the preset first threshold, the initial grayscale image is converted into a binary image to perform connected domain detection on the binary image to obtain the connected domain corresponding to the initial grayscale image.

3. The method for efficiently detecting paper cup defects based on machine vision according to claim 2 is characterized in that: The step of inputting the grayscale value difference value corresponding to the target pixel and the second variance into a preset pixel damage probability calculation formula to calculate the pixel damage probability corresponding to the target pixel specifically includes: in, The target pixel The corresponding pixel damage probability, is the average gray value of the initial gray image, The target pixel The average gray value of the preset sliding window centered at The target pixel The gray value of The target pixel The corresponding second variance, is a logarithmic function with a constant base of 2, is the normalization function.

4. The method for efficiently detecting paper cup defects based on machine vision according to claim 2 is characterized in that: The step of converting the initial grayscale image into a binary image according to a comparison result of the pixel damage probability corresponding to the target pixel with a preset first threshold, performing connected domain detection on the binary image, and obtaining a connected domain corresponding to the initial grayscale image specifically includes: Assigning the grayscale value of the target pixel point whose pixel damage probability is greater than the preset first threshold as the highest grayscale value, and assigning the grayscale value of the target pixel point whose pixel damage probability is less than or equal to the preset first threshold as the lowest grayscale value, to obtain a binary image corresponding to the initial grayscale image; A connected domain detection is performed on the binary image corresponding to the initial grayscale image using a preset connected domain detection algorithm to obtain a connected domain corresponding to the initial grayscale image.

5. The method for efficiently detecting paper cup defects based on machine vision according to claim 1, characterized in that: The determining, according to the damage probability of the initial connected domain corresponding to the target connected domain, the approximate connected domain corresponding to the target connected domain specifically includes: According to the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distance between the nearest pixel point, a number of similarity probability values ​​corresponding to the target connected domain are calculated; Other connected domains whose similarity probability values ​​are greater than the second threshold are confirmed as approximate connected domains corresponding to the target connected domain.

6. The method for efficiently detecting paper cup defects based on machine vision according to claim 5 is characterized in that: The method of calculating a number of similarity probability values ​​corresponding to the target connected domain according to the difference value of the initial connected domain damage probability between the target connected domain and other connected domains and the distance to the nearest pixel point specifically includes: in, The target connected domain With other connected domains The corresponding similarity probability value is, The target connected domain The corresponding initial connected domain damage probability, For other connected domains The corresponding initial connected domain damage probability, The target connected domain With other connected domains The nearest pixel distance, is the normalization function.

7. The method for efficiently detecting paper cup defects based on machine vision according to any one of claims 1 to 6, characterized in that: The determining whether the bottom of the paper cup is damaged based on the damage probability of the final connected domain corresponding to the target connected domain specifically includes: When the damage probability of the final connected domain corresponding to the target connected domain is greater than the first damage threshold, confirming that the paper cup corresponding to the target connected domain is in a damaged state; When the damage probability of the final connected domain corresponding to the target connected domain is less than or equal to the first damage threshold, it is confirmed that the paper cup corresponding to the target connected domain is in a normal state.