Edible commodity packaging box damage abnormity detection method
By performing K-means clustering and connected domain feature analysis on the packaging box appearance images, the problem that traditional algorithms have difficulty in identifying damage under complex patterns is solved, and high-accuracy damage detection is achieved.
Patent Information
- Application Number
- CN202511157329.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-19
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2045-08-19
AI Technical Summary
Traditional image processing algorithms have difficulty accurately identifying damaged food packaging boxes, especially when the surface has rich colorful patterns and text.
By obtaining the appearance image of the packaging box, the K-means clustering algorithm is used to segment it into different point clusters, the color complexity and edge complexity of the connected domain are calculated, and the degree of damage abnormality is analyzed by combining color and edge features.
The accuracy of damage detection is improved, the interference of complex patterns on detection is reduced, and the damaged area can be accurately identified.
Smart Images

Figure CN120707564A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition technology, and in particular to a method for detecting abnormal damage to a food product packaging box. Background Art
[0002] Food packaging damage anomaly detection uses machine vision technology to automatically identify and determine whether a food packaging box has structural damage defects such as cracks and holes. Image processing algorithms such as edge detection or feature extraction are typically used to obtain a clear image of the damaged edges. However, the surface of food packaging often features a variety of colorful patterns, trademarks, and text, which can interfere with the recognition process of traditional image processing algorithms. This results in traditional image processing algorithms being unable to accurately determine whether a packaging box is damaged, impacting the accuracy of food packaging damage detection. Summary of the Invention
[0003] In order to solve the above technical problems, the purpose of the present invention is to provide a method for detecting abnormal damage of edible product packaging boxes. The technical solution adopted is as follows: Obtaining an appearance image of a food product packaging box; Clustering the pixels in the appearance image according to the color difference characteristics of the pixels to obtain different point clusters; obtaining different connected domains according to the distribution characteristics of the pixels in the point clusters; Color complexity is obtained based on the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics within the connected domain; edge complexity is obtained based on the angle change characteristics of adjacent edge pixels in the connected domain and the smoothness characteristics of the edge line; The abnormal damage degree of the connected domain is obtained according to the color complexity and the edge complexity; and the damage condition of the edible product packaging box is detected according to the abnormal damage degree.
[0004] Furthermore, the step of clustering the pixels according to the color difference characteristics of the pixels in the appearance image to obtain different point clusters includes: Clustering is performed based on the RGB three-channel values of the pixels in the appearance image using the K-means clustering algorithm to obtain different point clusters.
[0005] Furthermore, the step of obtaining different connected domains according to the distribution characteristics of the pixels in the point cluster includes: The area formed by the pixels in the same cluster and adjacent to each other is regarded as the same connected domain.
[0006] Furthermore, the step of obtaining color complexity according to the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics in the connected domain includes: In the connected domain, the sum of the maximum difference values in each RGB channel is calculated and normalized to obtain an overall color difference value; the sum of the absolute values of the difference between the RGB three channels of any pixel point in the connected domain and other pixel points in the same connected domain within the eight neighborhoods is calculated to obtain a first difference between the arbitrary pixel point and other pixel points; the average value of the first difference between the arbitrary pixel point and all other pixel points in the same connected domain within the eight neighborhoods is calculated to obtain a local color difference value of the arbitrary pixel point; the average value of the local color difference values of all pixels in the connected domain is calculated and normalized to obtain a local color average difference value; the sum of the overall color difference value and the local color average difference value is calculated to obtain the color complexity of the connected domain.
[0007] Furthermore, the step of obtaining edge complexity according to the angle variation characteristics of adjacent edge pixels of the connected domain and the smoothness characteristics of the edge line includes: According to the clockwise direction of the edge line of the connected domain, the angle formed by any edge pixel point and the horizontal axis at the adjacent previous edge pixel point is calculated to obtain the relative angle of the arbitrary edge pixel point; the absolute value of the difference between the relative angle and the previous relative angle is calculated and normalized to obtain the degree of change of the arbitrary edge pixel point; the proportion of the number of edge pixel points whose degree of change is not a constant 0 is counted to obtain the degree of change value of the connected domain; the edge pixel points whose degree of change is continuously not a constant 0 are connected to obtain a pixel point chain; the sum of the squares of the number of pixels in all pixel point chains on the edge line is calculated and normalized to obtain the contour mutation degree; the product of the average value of the degree of change of all edge pixel points, the degree of change value, and the contour mutation degree is calculated to obtain the edge complexity of the connected domain.
[0008] Furthermore, the step of obtaining the degree of damage abnormality of the connected domain according to the color complexity and the edge complexity includes: The color complexity is negatively correlated with the edge complexity and then calculated to obtain the degree of abnormal damage of the connected domain.
[0009] Furthermore, the step of detecting damage of the edible product packaging box according to the abnormal damage degree includes: When there is a connected domain where the abnormal degree of damage exceeds a preset abnormal threshold, the edible product packaging box is damaged.
[0010] The present invention has the following beneficial effects: In the present invention, since the color of the packaging box surface is relatively rich, obtaining different point clusters can divide the positions of different colors in the appearance image, thereby determining the area of the connected domain; since damage will appear as an area in the appearance image; obtaining different connected domains can determine areas with similar colors and adjacent positions, and then determine whether the connected domain is caused by packaging damage. Since the color distribution characteristics of the normal area and the damaged area on the packaging box surface are significantly different, obtaining color complexity can analyze whether the connected domain is a damaged area from the color characteristics. Since the burr characteristics of the damaged edge are relatively obvious, obtaining edge complexity can analyze whether the connected domain is a damaged area from the edge shape characteristics. The degree of damage abnormality of the connected domain is obtained based on the color complexity and edge complexity, which can accurately characterize the possibility that the connected domain is a damaged area; finally, the damage of the edible product packaging box is detected based on the degree of damage abnormality, which improves the accuracy of damage detection and reduces the interference of complex patterns on the surface of the edible product packaging box on damage detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. 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 any creative work.
[0012] Figure 1 This is a flow chart of a method for detecting abnormal damage to edible product packaging boxes provided by one embodiment of the present invention. DETAILED DESCRIPTION
[0013] To further illustrate the technical means and effectiveness of the present invention in achieving its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, describes in detail the specific implementation, structure, features, and effectiveness of a method for detecting abnormal damage to edible product packaging boxes proposed by the present invention. In the following description, different references to "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics of one or more embodiments may be combined in any suitable manner.
[0014] 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.
[0015] The following describes in detail a method for detecting abnormal damage to a food product packaging box provided by the present invention with reference to the accompanying drawings.
[0016] See also Figure 1, which shows a flow chart of a method for detecting abnormal damage to edible product packaging boxes according to an embodiment of the present invention. The method includes the following steps: Step S1: Acquire an appearance image of a food product packaging box.
[0017] In this embodiment of the present invention, the food packaging being inspected is a paper box-style package with a rich, complex, and varied appearance. First, an image of the food packaging is captured. An industrial camera is used to capture images of each surface of the packaging. The image capture environment maintains sufficient and uniform lighting. To prevent shadows and reflections, a high-brightness LED ring light source and a diffuser are used. After the capture is complete, different images of the packaging surface are obtained.
[0018] Step S2: clustering the pixels in the appearance image according to the color difference characteristics of the pixels to obtain different point clusters; and obtaining different connected domains according to the distribution characteristics of the pixels in the point clusters.
[0019] Gaps and cracks caused by damage have a certain area and will occupy a certain area of pixels in the image to form a connected domain. Therefore, it is necessary to first obtain all connected domains in the image and further analyze the areas where damage may exist based on the connected domains. Therefore, the pixels are clustered according to the color difference characteristics of the pixels in the appearance image to obtain different point clusters. In an embodiment of the present invention, the step of obtaining point clusters includes: clustering the pixels in the appearance image using the K-means clustering algorithm according to the RGB three-channel values of the pixels to obtain different point clusters. It should be noted that the K-means clustering algorithm belongs to the prior art and the specific steps will not be repeated. The pixels in each point cluster have similar colors, and the pixels in the same point cluster may not be distributed in the same area in the appearance image. Different connected domains are then obtained based on the distribution characteristics of the pixels in the point cluster. The area formed by the pixels in the same point cluster and adjacent to each other is regarded as the same connected domain. The appearance image is divided into different connected domains by traversal, and the pixels in each connected domain have similar colors.
[0020] Step S3, obtaining color complexity based on the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics within the connected domain; obtaining edge complexity based on the angle change characteristics of adjacent edge pixels in the connected domain and the smoothness characteristics of the edge line.
[0021] Since the color of some areas on the packaging surface may be similar to the color of the damaged area, it is difficult to accurately identify the damaged area by analyzing the color features alone. In order to meet the visual aesthetics of customers’ product selection, the packaging boxes detected by the embodiment of the present invention and common similar food packaging boxes will contain rich color changes such as gradient colors on the surface, and the color distribution regularity is poor. In the connected domain with similar color distribution, the color change of the normal surface area is more obvious. The damaged area of the package does not reflect light because the inside of the package is darker, so it appears as a relatively uniform color; or it appears as the color of the inside of the package. In order to ensure food safety, the inside of the package will not be printed and dyed, and the color is relatively uniform; therefore, the color of the connected domain corresponding to the damaged area is relatively uniform and the distribution regularity is relatively strong. Therefore, the color complexity is obtained based on the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics in the connected domain.
[0022] Preferably, in an embodiment of the present invention, the step of obtaining color complexity includes: calculating the sum of the maximum difference values in each RGB channel in the connected domain and normalizing it to obtain an overall color difference value; when the maximum difference value in each RGB channel is larger, the overall color difference value is larger, which means that the uniformity of the pixels in the connected domain is worse, the color change characteristics are more obvious, and the possibility that the connected domain is a damaged area is less; when the overall color difference value is smaller, it means that the color of the pixels in the connected domain is more uniform and the possibility that it is a damaged area is more likely. Calculating the sum of the absolute values of the differences between the RGB three channels of any pixel in the connected domain and other pixels in the same connected domain within the eight-neighborhood area to obtain a first difference between the arbitrary pixel and the other pixels; when the first difference value is larger, it means that the color difference between the arbitrary pixel and other pixels in the same connected domain within the eight-neighborhood area is more obvious. Calculating the average of the first differences between the arbitrary pixel and all other pixels in the same connected domain within the eight-neighborhood area to obtain a local color difference value for the arbitrary pixel; when the local color difference value of the arbitrary pixel is larger, it means that the color change characteristics of the local area are more obvious. Calculate the average local color difference value of all pixels in the connected domain and normalize it to obtain the local color average difference value. The larger the local color average difference value, the more obvious the color gradient characteristics of the connected domain are, and the more likely it is a normal area on the packaging surface. Calculate the sum of the overall color difference value and the local color average difference value to obtain the color complexity of the connected domain. The smaller the color complexity, the more uniform the color within the connected domain is, and the more likely it is a damaged area. The formula for obtaining color complexity includes:
[0023] Where W represents the color complexity of the connected domain, Indicates the maximum difference of the R channel in the connected domain, Indicates the maximum difference of the G channel in the connected domain, Indicates the maximum difference of the B channel in the connected domain, Represents the sum of the ranges of all RGB channels, used for normalization. Represents the overall color difference value; N represents the number of pixels in the connected domain, Represents the local color difference value of the nth pixel, Indicates the local color average difference value.
[0024] Furthermore, since there are many printed fonts on the surface of edible product packaging boxes to introduce product information, and the printed fonts are of the same color, it is difficult to distinguish the font area from the damaged area by the color complexity feature alone. It is necessary to distinguish them by the edge features of the connected domain. The pattern contours or font edges on the packaging surface are relatively smooth overall, while the damaged areas are caused by external forces, resulting in gaps or cracks in the packaging. When the paper material of the packaging is torn and cracked, there will be many burrs on its edges. The smoothness features of the edge contours of the connected domain corresponding to the damaged area are weak, and the edge shape changes irregularly and is highly random. The font edge only changes in shape at certain locations, and the edges at unchanged locations are relatively smooth. Therefore, the edge complexity is obtained based on the angle change features of the adjacent edge pixels of the connected domain and the smoothness features of the edge line.
[0025] Preferably, in an embodiment of the present invention, the step of obtaining edge complexity includes: calculating the angle formed by any edge pixel and the horizontal axis at the adjacent previous edge pixel in the clockwise direction of the edge line of the connected domain, thereby obtaining the relative angle of the arbitrary edge pixel; it should be noted that the angle is the angle traversed by the horizontal axis of the positive direction of the adjacent previous edge pixel when rotating counterclockwise around the pixel to the arbitrary edge pixel, and the relative angle reflects the orientation of the arbitrary edge pixel relative to the adjacent previous edge pixel. Calculating the absolute value of the difference between the relative angle and the previous relative angle and normalizing it to obtain the degree of change of the arbitrary edge pixel; when the degree of change is 0, it means that the relative angles of the adjacent edge pixels are the same, the three adjacent edge pixels are on the same line, and the direction of the edge line has not changed; conversely, when the degree of change is not 0, it means that the relative angle has changed and the direction of the edge line has changed. The percentage of edge pixels with a degree of change that is not a constant 0 is counted to obtain the degree of change value of the connected domain; the larger the degree of change value, the more edge pixels have angle changes, the more frequent the changes in edge line direction, and the more consistent with the burr characteristics of the damaged edge of the package. Connect the edge pixels whose degree of change is not a constant 0 to obtain a pixel chain; the longer the pixel chain, the longer the part of the edge line where the direction changes continuously, and the more consistent it is with the burr characteristics of a damaged edge. Calculate the sum of the squares of the number of pixels in all pixel chains on the edge line and normalize them to obtain the contour mutation degree; the greater the contour mutation degree, the more complex the edge contour shape, the weaker the smoothness feature, and the more consistent it is with the burr characteristics of a damaged edge. Calculate the product of the average value of the degree of change of all edge pixels, the degree of change value, and the contour mutation degree to obtain the edge complexity of the connected domain; the greater the edge complexity, the more complex the edge shape of the connected domain, the weaker the smoothness feature, and the more consistent it is with the burr characteristics of a damaged edge, and the more likely the connected domain is to be a damaged area. The formulas for obtaining edge complexity include:
[0026] Where D represents the edge complexity of the connected domain, M represents the number of edge pixels whose change degree is not 0, and H represents the number of edge pixels. Indicates the degree of change, Q indicates the number of pixel chains, Represents the square of the number of edge pixels in the qth pixel chain, The purpose is to normalize the molecule. Indicates the degree of contour mutation; Indicates the hth and The absolute value of the difference in relative angles of edge pixels, Indicates the maximum value of the angle difference, used for normalization, Indicates the degree of change of the h-th edge pixel, Indicates the average value of the degree of change of all edge pixels.
[0027] Step S4: obtaining the abnormal damage degree of the connected domain according to the color complexity and the edge complexity; and detecting the damage condition of the edible product packaging box according to the abnormal damage degree.
[0028] After obtaining the color complexity and edge complexity of the connected domain, the degree of damage anomaly of the connected domain can be obtained according to the color complexity and edge complexity; preferably, in the embodiment of the present invention, the step of obtaining the degree of damage anomaly includes: after negative correlation mapping of the color complexity and calculating the average value of the edge complexity, obtaining the degree of damage anomaly of the connected domain. The embodiment of the present invention uses the formula A negative correlation mapping is performed on the color complexity, where W represents the color complexity; when the color complexity is smaller, it means that the color in the connected domain is more uniform, and the more likely it is a damaged area; when the edge complexity is greater, the more likely it is a damaged area; therefore, when the degree of damage anomaly is greater, it means that the connected domain is more likely to be caused by a damaged area. Furthermore, the damage of the edible product packaging box can be detected based on the degree of damage anomaly, specifically including: when there is a connected domain whose degree of damage anomaly exceeds a preset anomaly threshold, the edible product packaging box is damaged; in the embodiment of the present invention, the preset anomaly threshold is 0.8, and the implementer can determine it by himself according to the implementation scenario. When a connected domain exceeds the preset anomaly threshold, it means that there is a damaged area in the packaging box. At this point, the degree of damage anomaly is obtained by analyzing the color change characteristics and edge shape characteristics of the connected domain. The degree of damage anomaly can accurately characterize whether the connected domain is caused by damage, thereby improving the accuracy of surface damage detection of edible product packaging boxes.
[0029] In summary, an embodiment of the present invention provides a method for detecting abnormal damage to edible product packaging boxes; clustering pixels based on the color difference characteristics of the pixels in the appearance image to obtain different point clusters; obtaining different connected domains based on the distribution characteristics of the pixels in the point clusters; obtaining color complexity based on the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics within the connected domain; and obtaining edge complexity based on the angular change characteristics of adjacent edge pixels in the connected domain and the smoothness characteristics of the edge lines. The present invention obtains the degree of abnormal damage in the connected domain based on the color complexity and edge complexity; detects the damage of the edible product packaging box based on the degree of abnormal damage, thereby improving the accuracy of damage detection.
[0030] It should be noted that the order in which the embodiments of the present invention are described above is for illustrative purposes only and does not necessarily represent the superiority or inferiority of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or sequential order shown to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0031] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
Claims
1. A method for detecting abnormal damage of food product packaging boxes, characterized in that: The method comprises the following steps: Obtaining an appearance image of a food product packaging box; Clustering the pixels in the appearance image according to the color difference characteristics of the pixels to obtain different point clusters; obtaining different connected domains according to the distribution characteristics of the pixels in the point clusters; Color complexity is obtained based on the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics within the connected domain; edge complexity is obtained based on the angle change characteristics of adjacent edge pixels in the connected domain and the smoothness characteristics of the edge line; The abnormal damage degree of the connected domain is obtained according to the color complexity and the edge complexity; and the damage condition of the edible product packaging box is detected according to the abnormal damage degree.
2. A method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of clustering the pixels according to the color difference characteristics of the pixels in the appearance image to obtain different point clusters includes: Clustering is performed based on the RGB three-channel values of the pixels in the appearance image using the K-means clustering algorithm to obtain different point clusters.
3. The method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of obtaining different connected domains according to the distribution characteristics of the pixels in the point cluster comprises: The area formed by the pixels in the same cluster and adjacent to each other is regarded as the same connected domain.
4. The method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of obtaining color complexity according to the color difference characteristics between adjacent pixels in the connected domain and the overall color difference characteristics in the connected domain comprises: In the connected domain, the sum of the maximum difference values in each RGB channel is calculated and normalized to obtain an overall color difference value; the sum of the absolute values of the difference between the RGB three channels of any pixel point in the connected domain and other pixel points in the same connected domain within the eight neighborhoods is calculated to obtain a first difference between the arbitrary pixel point and other pixel points; the average value of the first difference between the arbitrary pixel point and all other pixel points in the same connected domain within the eight neighborhoods is calculated to obtain a local color difference value of the arbitrary pixel point; the average value of the local color difference values of all pixels in the connected domain is calculated and normalized to obtain a local color average difference value; the sum of the overall color difference value and the local color average difference value is calculated to obtain the color complexity of the connected domain.
5. The method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of obtaining edge complexity according to the angle variation characteristics of adjacent edge pixels of the connected domain and the smoothness characteristics of the edge line comprises: According to the clockwise direction of the edge line of the connected domain, the angle formed by any edge pixel point and the horizontal axis at the adjacent previous edge pixel point is calculated to obtain the relative angle of the arbitrary edge pixel point; the absolute value of the difference between the relative angle and the previous relative angle is calculated and normalized to obtain the degree of change of the arbitrary edge pixel point; the proportion of the number of edge pixel points whose degree of change is not a constant 0 is counted to obtain the degree of change value of the connected domain; the edge pixel points whose degree of change is continuously not a constant 0 are connected to obtain a pixel point chain; the sum of the squares of the number of pixels in all pixel point chains on the edge line is calculated and normalized to obtain the contour mutation degree; the product of the average value of the degree of change of all edge pixel points, the degree of change value, and the contour mutation degree is calculated to obtain the edge complexity of the connected domain.
6. The method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of obtaining the degree of damage abnormality of the connected domain according to the color complexity and the edge complexity comprises: The color complexity is negatively correlated with the edge complexity and then calculated to obtain the degree of abnormal damage of the connected domain.
7. The method for detecting damage anomalies in food product packaging boxes according to claim 1, characterized in that: The step of detecting the damage of the edible product packaging box according to the abnormal damage degree includes: When there is a connected domain where the abnormal degree of damage exceeds a preset abnormal threshold, the edible product packaging box is damaged.
Citation Information
Patent Citations
Polyurethane floor mat forming detection method and system
CN118334030A
Printing pattern defect detection method and system for plastic package
CN118411367A
Metal composite material quality detection method based on image processing
CN118781112A
Corrugated carton damage detection method based on machine vision
CN120142298A
Lens surface defect detection method and apparatus, and device and readable storage medium
WO2025054982A1