A Computer-Aided Defect Detection Method for Food Packaging Bags
By acquiring grayscale and HSV images of the surface of food packaging bags, calculating hue factors and gradient values, and combining them with neural networks for defect detection, the problem of low detection accuracy in traditional methods is solved, achieving efficient and accurate defect detection.
Patent Information
- Application Number
- CN202510959140.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-11
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2045-07-11
AI Technical Summary
Existing machine vision technology for detecting defects in food packaging bags suffers from unclear defect features and low detection accuracy due to variations in color distribution, thus impacting production efficiency.
A computer-aided method is used to acquire grayscale and HSV images of the surface of food packaging bags. By calculating the hue factor and gradient value of each pixel, and combining it with a neural network, defect detection is performed. Multiple updates of the grayscale image and filtering processes are used to improve the detection accuracy.
It improves the accuracy and efficiency of defect detection in food packaging bags, clearly distinguishes between defective and normal areas, and enhances the real-time performance and accuracy of the detection system.
Smart Images

Figure CN120876950B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and specifically to a computer-aided method for detecting defects in food packaging bags. Background Technology
[0002] Food packaging bags effectively protect food from contamination, thus extending its shelf life, and are therefore widely used in daily life. However, in actual industrial production, the production speed of packaging bags is relatively fast, and traditional manual visual inspection cannot accurately and effectively detect the quality of packaging bags quickly. Therefore, machine vision technology is often used to quickly and effectively detect defects in packaging bags. However, in existing packaging bag defect detection technologies, the different color distribution characteristics of different pixels in the packaging bag image lead to unclear defect features when traditional machine vision technology detects packaging bag defects, resulting in low accuracy in food packaging bag defect detection and causing significant interference to production efficiency. Summary of the Invention
[0003] To address the aforementioned technical problems, the present invention aims to provide a computer-aided method for detecting defects in food packaging bags, the specific technical solution of which is as follows:
[0004] One embodiment of the present invention provides a computer-aided method for detecting defects in food packaging bags: acquiring a grayscale image of the food packaging bag surface, obtaining an HSV image based on the grayscale image of the food packaging bag surface; obtaining the hue factor of each pixel based on the H channel value, S channel value and standard deviation of the H channel value of all pixels in the HSV image;
[0005] In the grayscale image of the food packaging bag surface, the product of the hue factor of each pixel and the gradient value of each pixel in different directions in its neighborhood is the hue gradient value of each pixel in different directions; the adjustment factor of each pixel in each direction is obtained based on the hue gradient value of each pixel in each direction.
[0006] The grayscale value of each pixel is updated based on its grayscale value, hue gradient values in different directions, and adjustment factors to obtain a first-updated grayscale image. Based on the first-updated grayscale image, the hue gradient values in different directions and adjustment factors of each pixel are obtained. Based on the grayscale value of each pixel in the first-updated grayscale image, the hue gradient values in different directions and adjustment factors are updated to obtain a second-updated grayscale image. This process is repeated until the number of updates reaches a preset number, at which point the final grayscale image is obtained.
[0007] The final grayscale image is input into the food packaging bag detection neural network, which outputs the probability of the food packaging bag being defective; the probability of the food packaging bag being defective is used to determine whether the food packaging bag is defective.
[0008] Preferably, obtaining a grayscale image of the food packaging bag surface and obtaining an HSV image based on the grayscale image includes: obtaining an image of the food packaging bag surface; converting the image of the food packaging bag surface into a grayscale image of the food packaging bag surface; performing bilateral filtering on the grayscale image of the food packaging bag surface to obtain a filtered grayscale image of the food packaging bag surface; and converting the filtered grayscale image of the food packaging bag surface into an HSV image.
[0009] Preferably, the hue factor of each pixel is obtained based on the H-channel value, S-channel value, and standard deviation of the H-channel values of all pixels in the HSV image, including: multiplying the H-channel value and S-channel value of the pixel to obtain a product; summing a constant coefficient and the standard deviation of the H-channel values of all pixels in the HSV image to obtain a summation result; the ratio of the product result to the summation result is the hue factor of the pixel; wherein the constant coefficient is a non-zero positive number.
[0010] Preferably, the adjustment factor for each direction of the pixel is obtained based on the hue gradient value in each direction of the pixel, including: setting a first constant coefficient, adding the square of the first constant coefficient to the square of the hue gradient value in each direction of the pixel to obtain the summation result; the ratio of the square of the first constant coefficient to the summation result is the adjustment factor for each direction of the pixel.
[0011] Preferably, updating the grayscale value of each pixel based on the grayscale value of each pixel, the hue gradient values in different directions, and the adjustment factor includes: obtaining the average value of the product of the hue gradient values in each direction and the adjustment factor of the pixel; the sum of the average value and the grayscale value of the pixel is the updated grayscale value of the pixel.
[0012] Preferably, the final grayscale image is input into the food packaging bag detection neural network to output the probability of a defect in the food packaging bag. This includes: the food packaging bag detection neural network is a fully connected neural network with a cross-entropy loss function; at least two final grayscale images are obtained to form a final grayscale image dataset; the final grayscale image dataset is labeled manually to form a training set, wherein the manual labeling involves labeling the final grayscale images in the final grayscale image data as either defective or non-defective, with defective images labeled as 1 and non-defective images labeled as 0; the food packaging bag detection neural network is trained using the training set to obtain a trained food packaging bag detection neural network; the final grayscale image is input into the trained food packaging bag detection neural network to output the probability of a defect in the food packaging bag.
[0013] Preferably, determining whether a food packaging bag is defective based on the probability of the food packaging bag being defective includes: setting a judgment threshold; if the probability of the food packaging bag being defective is greater than the judgment threshold, then the food packaging bag is defective.
[0014] The embodiments of the present invention have at least the following beneficial effects: After obtaining the grayscale image of the food packaging bag surface and the corresponding HSV image, the present invention performs defect analysis on the surface of the food packaging bag based on the grayscale and color value data in the image data, and the combination of color information makes subsequent detection more accurate; furthermore, when processing the gradient values of the pixels in the grayscale image of the food packaging bag surface, the hue factor is combined to obtain the hue gradient values of each pixel in different directions, so that the gradient values of the pixels in each direction contain the color information in the image, avoiding the problem that the traditional method of calculating gradient values does not combine the color information of the food packaging bag itself; at the same time, based on the grayscale image of the food packaging bag surface... The grayscale image updates the grayscale value of each pixel by taking its original grayscale value, the hue gradient values in different directions, and the adjustment factor. This process is repeated multiple times to update the pixels in the grayscale image of the food packaging bag surface. Each update combines the gradient and color information of neighboring pixels. The adjustment factor controls the magnitude of the grayscale value change of different pixels, making the final grayscale image clearer and more distinctive. At the same time, the distinction between defective and normal areas is also more obvious. The food packaging bag sheet detection neural network can then more accurately extract information from the surface of the food packaging bag sheet, making the final detection of food packaging bag defects more accurate. Attached Figure Description
[0015] To more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 A flowchart illustrating a computer-aided method for detecting defects in food packaging bags, provided as an embodiment of the present invention.
[0017] Figure 2 This is a schematic diagram of the multi-directional hue gradient values of a pixel. Detailed Implementation
[0018] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of a computer-aided food packaging bag defect detection method proposed according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0019] Unless otherwise defined, 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 pertains.
[0020] The following description, in conjunction with the accompanying drawings, details a specific scheme for a computer-aided defect detection method for food packaging bags provided by the present invention.
[0021] Example:
[0022] The main application scenario of this invention is as follows: During the use of food packaging bags, defects such as fading and cracks may occur due to time and environmental reasons. These defects have a great impact on the appearance and use of food packaging bags. Cracks may also cause safety problems. However, since food packaging bags are located at high places, it is very inconvenient to observe them manually. Therefore, by acquiring data of the surface image of food packaging bags and analyzing the acquired data, the purpose of detecting defects in food packaging bags can be achieved.
[0023] Please see Figure 1 The diagram illustrates a flowchart of a computer-aided method for detecting defects in food packaging bags, as provided in an embodiment of the present invention. The method includes the following steps:
[0024] Step S1: Acquire an image of the surface of the food packaging bag and convert it into a grayscale image of the food packaging bag surface. Convert the grayscale image of the food packaging bag surface into an HSV image. Obtain the hue factor of each pixel based on the H channel value, S channel value, and standard deviation of the H channel value of all pixels in the HSV image.
[0025] Firstly, considering the need for accurate and reliable analysis and detection of surface defects in food packaging bags, it is necessary to acquire high-resolution images of the food packaging bag surface that clearly show the characteristics of these defects. Commonly used imaging tools include CCD cameras and CMOS sensor cameras. Compared to CMOS sensor cameras, CCD cameras have the advantages of sensitive light-sensing components, image quality without ghosting, and higher image quality. Furthermore, considering that the transition textures caused by the ridge features and cracks resulting from aging at different locations on the food packaging bag surface may not be clearly represented in low-quality images, using a CCD camera to capture images of the food packaging bag surface can improve the imaging results. Additionally, to clearly capture the characteristic information of cracks and defects on the food packaging bag surface, a strip LED structured light source is used to supplement the lighting in areas with poor lighting. Based on this, the CCD camera's photosensitive components can acquire high-quality images of the food packaging bag surface in RGB color space, clearly showing the characteristics of various parts of the surface.
[0026] Further observation and analysis of the food packaging bag surface reveals that, due to its large overall area, food packaging bags, acting as structural elements on building surfaces, are prone to overlooking the overall spatial structure information when using CCD cameras to acquire close-up, near-focus images of the bag surface. This can easily lead to misjudgments during surface defect detection. To obtain the overall spatial information of the food packaging bag surface, it is necessary to capture images from multiple angles using different cameras. However, this approach not only increases the overhead costs of the food packaging bag image acquisition workflow but also... The real-time detection performance of subsequent food packaging bag surface defect detection algorithms has been significantly improved, which may cause a large lag in the entire food packaging bag surface detection system. Therefore, using a CCD camera to capture telephoto images of the food packaging bag surface at a distance can better preserve the overall spatial structure information of the food packaging bag surface. However, due to the wide field of view and long angle of view, the acquired telephoto images of the food packaging bag surface will inevitably show blurred and unclear local details in the final imaging result. Therefore, further processing is required for the telephoto images of the food packaging bag surface acquired by the CCD camera at a distance.
[0027] Bilateral filtering is used to process images of surface defects on food packaging bags, minimizing or even eliminating the impact of natural random noise in the shooting environment on the detection of surface defects. Simultaneously, weighting coefficients are set according to the human eye's perception of red, green, and blue colors in natural scenes to convert the filtered image into a grayscale image of the food packaging bag surface. Generally, empirical values of 0.299, 0.587, and 0.114 are used to complete the conversion between the image of the distant food packaging bag surface and the grayscale image in the RGB color space.
[0028] Furthermore, to facilitate the analysis of color components in the image of the food packaging bag surface, the image in the RGB color space is converted to the HSV color space to obtain an HSV image. This embodiment uses the cvtColor function provided by OpenCV to convert the RGB image to an HSV image.
[0029] Furthermore, the defects on the surface of food packaging bags mainly manifest as faded patches and crack shapes. However, traditional pixel gradient calculation methods do not consider the complex color information on the surface of food packaging bags. Additionally, because these are telephoto images of food packaging bags taken from a distance, local details may appear blurred. Therefore, it is necessary to reconstruct the entire image based on the gradient information of the pixels surrounding each pixel to ensure clear details and a clear contrast between normal and defective areas. Existing algorithms use Gaussian smoothing filters to improve image quality and remove noise, which can remove Gaussian white noise and salt-and-pepper noise. However, this also blurs the image of the food packaging bag surface, further obscuring the already low-resolution, telephoto-quality edge details.
[0030] Therefore, the hue factor of each pixel is calculated based on the HSV image, expressed by the formula:
[0031]
[0032] Where, ρ cor (x,y) represents the hue factor of the pixel at coordinates (x,y) in the HSV image; H(x,y) and S(x,y) represent the H-channel and S-channel values of the pixel at coordinates (x,y) in the HSV image, respectively; C represents a constant coefficient, with an empirical value of C = 0.1, which can be adjusted by the implementer according to specific circumstances. The constant coefficient is used to ensure that the denominator is not zero, and the value of the constant coefficient is a positive number that is not zero; StdH represents the standard deviation of the H-channel values of all pixels in the HSV image, which is used as the denominator as a benchmark.
[0033] When an aging defect occurs in a certain area, the hue factor ρ of that part of the pixels is calculated. cor The values of (x, y) will differ significantly from those of a normal, defect-free food packaging bag surface. When an aging defect occurs in a certain area of the food packaging bag surface, its color will differ from that of a defect-free food packaging bag surface. Defect-free food packaging bags have vibrant colors, and the calculated hue factor ρ of the food packaging bag... cor The hue factor ρ on the surface of food packaging bags with larger (x,y) values indicates aging defects. cor The (x,y) values are relatively small. Therefore, when calculating the gradient value of a pixel, combining the hue factor of the pixel can better reflect the characteristics of the defective and non-defective regions.
[0034] Step S2: In the grayscale image of the food packaging bag surface, the product of the hue factor of each pixel and the gradient value of each pixel in different directions in its neighborhood is the hue gradient value of each pixel in different directions; the adjustment factor of each pixel in each direction is obtained based on the hue gradient value of each pixel in each direction.
[0035] First, in order to update the grayscale value of a pixel by combining the information of each pixel in its neighborhood, it is necessary to calculate the hue gradient values in each direction within the neighborhood of the pixel by combining the hue factor of the pixel. Preferably, in this embodiment of the invention, the neighborhood is an 8-neighborhood, so the hue gradient values in 8 directions of a pixel can be calculated, specifically as follows:
[0036]
[0037] Where, ρ cor (x,y) represents the hue factor of the pixel with coordinates (x,y) in the grayscale image of the food packaging bag surface. f(x,y-1)-f(x,y) represents the hue gradient value of the pixel at position coordinates (x,y) in the vertical downward direction. f(x,y+1)-f(x,y) represents the hue gradient value of the pixel with position coordinates (x,y) in the vertical upward direction. f(x-1,y)-f(x,y) represents the hue gradient value of the pixel with position coordinates (x,y) in the horizontal left direction. f(x+1,y)-f(x,y) represents the hue gradient value of the pixel with position coordinates (x,y) in the horizontal direction to the right. f(x-1,y-1)-f(x,y), f(x+1,y+1)-f(x,y), f(x-1,y+1)-f(x,y), f(x-1,y+1)-f(x,y) and f(x+1,y-1)-f(x,y) represent the hue gradient values of the pixel at position coordinates (x,y) in the directions of upper left, upper right, lower left, and lower right, respectively.
[0038] When calculating the hue gradient value, the hue gradient value of each pixel in eight directions within its eight-neighborhood is obtained, and the directions are as follows: Figure 2 The above, Figure 2 This is a diagram illustrating the multi-directional hue gradient values of a pixel. Figure 2 In and These represent the hue gradient values of each pixel in each direction within its 8-neighborhood.
[0039] Where f() represents the grayscale value of a pixel at a certain position coordinate, such as f(x,y) representing the grayscale value of the pixel at position coordinate (x,y) in the grayscale image of the surface of the food packaging bag.
[0040] Traditional gradient calculations directly extract relevant information by calculating gradients based on differences in grayscale values. However, due to the complexity of defects such as cracks and color fading that occur on the surface of food packaging bags after aging, traditional gradient calculation methods may result in significant errors. Therefore, this paper proposes a method to calculate the hue gradient values of pixels in different directions by combining the hue factors of different pixels. Based on the hue gradient values of each pixel in different directions in the grayscale image of the food packaging bag surface, the grayscale values of pixels can be updated more effectively. The image obtained after the grayscale value update can better highlight the edge features of cracks and aging / fading defects on the surface of the food packaging bag, further improving the effectiveness of surface defect detection.
[0041] Finally, it is necessary to obtain the adjustment factor of the pixel in each direction within its 8-neighborhood. A first constant coefficient K is set, and the square of the first constant coefficient is added to the square of the hue gradient value of the pixel in each direction to obtain the sum. The ratio of the square of the first constant coefficient to the sum is the adjustment factor of the pixel in each direction; expressed by the formula:
[0042]
[0043] Among them, C NThis represents the adjustment factor in the vertical upward direction of the pixel with position coordinates (x, y); K represents the first constant coefficient, which is preferably 3.2 in this embodiment, but the implementer can adjust its value according to the specific situation; This represents the hue gradient value of the pixel at position coordinates (x, y) in the vertical upward direction.
[0044] When a pixel involved in the calculation is located on the edge of the far-focus image of the food packaging bag, the calculated hue gradient value is larger, resulting in smaller adjustment factors in each direction of the pixel. This makes the gray value of the pixel at the edge change slowly, allowing the defect feature information to be better preserved during the continuous updating of the pixel's gray value.
[0045] Conversely, when a pixel is not on an edge, the larger the adjustment factor value and the closer it is to 1, the more drastic the change in the pixel's grayscale value. This can smooth out these pixels and make defective areas in the image more prominent.
[0046] Step S3: Update the grayscale value of each pixel according to the grayscale value of each pixel, the hue gradient value in different directions, and the adjustment factor to obtain a first-updated grayscale image; obtain the hue gradient value and adjustment factor of each pixel in different directions based on the first-updated grayscale image; update the grayscale value of each pixel in the first-updated grayscale image according to the grayscale value of each pixel in the first-updated grayscale image, the hue gradient value in different directions, and the adjustment factor to obtain a second-updated grayscale image, and so on, until the number of updates reaches the preset number, to obtain the final grayscale image.
[0047] To make the details in the grayscale surface image more prominent, it is necessary to update the grayscale value of each pixel in the grayscale image of the food packaging bag surface. The grayscale value of each pixel is updated based on its grayscale value, hue gradient values in different directions, and adjustment factors, obtaining the average value of the product of the hue gradient values and adjustment factors in each direction. The sum of this average value and the pixel's grayscale value is the updated grayscale value of the pixel, expressed by the formula:
[0048]
[0049] Where f1(x,y) represents the grayscale value of the pixel at position coordinates (x,y) after the first update, C S C N C W C E C NW C NE C SW and C SEThese represent the adjustment factors for the pixel at position coordinates (x, y) in its 8-neighborhood along the vertically downward, vertically upward, horizontally leftward, horizontally rightward, upper leftward, upper rightward, lower leftward, and lower rightward directions, respectively. This allows us to obtain the first updated grayscale value of each pixel in the grayscale image of the food packaging bag surface, thus completing the first update of the grayscale value of each pixel in the grayscale image of the food packaging bag surface, resulting in an updated grayscale image. Here, when updating the grayscale value of a pixel, information from the pixels in its 8-neighborhood and the pixel's own color information are combined, effectively preserving the information of the food packaging bag surface.
[0050] Furthermore, the grayscale image of the food packaging bag surface needs to be updated multiple times. Each update is based on the previous update. For example, after the first update, an updated grayscale image is obtained. This updated grayscale image is converted into an HSV image, and the hue factor of each pixel in the updated grayscale image is calculated in eight directions within its eight-neighborhood. The hue gradient value and corresponding adjustment factor of each pixel in the updated grayscale image in eight directions within its eight-neighborhood are then calculated, and the grayscale value of each pixel in the updated grayscale image is updated. This update is the second update, resulting in a second updated grayscale image. This process continues until a preset number of updates is reached, at which point the update stops, and the final grayscale image is obtained. Preferably, in this embodiment, the preset number of updates is 15. It should be noted that the implementer can adjust the preset number of updates according to the actual situation to obtain a grayscale image with relatively clear details and easy distinction between defective and normal areas. During each update process, because the information and color information of the pixels in the neighborhood of each pixel are combined, the surface information of the food packaging bag can be well preserved, while also making the image details clearer.
[0051] Step S4: Input the final grayscale image into the food packaging bag detection neural network, and output the probability of the food packaging bag being defective; determine whether the food packaging bag is defective based on the probability of the food packaging bag being defective.
[0052] Based on step S3, a large number of final grayscale images can be obtained, forming a final grayscale image dataset. The dataset is then manually labeled to obtain a training set. The labeling method involves classifying the final grayscale images as either defective or defect-free, with a 1 for defective images and a 0 for defect-free images. For example, during manual labeling, if a final grayscale image shows a defect on the surface of a food packaging bag, the grayscale image of that food packaging bag surface would be labeled as 1. Further, a food packaging bag fragment detection neural network is constructed. This neural network is a fully connected neural network with three layers. Since this problem falls under the category of classification and recognition, the loss function of the food packaging bag detection neural network is the cross-entropy loss function. The SGD stochastic gradient descent method is used to optimize the food packaging bag detection neural network, ultimately obtaining a food packaging bag detection neural network with better detection performance, which is the trained food packaging bag detection neural network. The final grayscale image is input into the trained food packaging bag detection neural network, and the output is the probability of the food packaging bag being defective. The higher the probability, the greater the probability of the defect. Finally, the probability of the food packaging bag being defective can be used to determine whether the food packaging bag is defective.
[0053] A judgment threshold is set. Preferably, in this embodiment, the judgment threshold is set to 0.73. It should be noted that the judgment threshold can be adjusted by the implementer according to the specific situation. When the probability of a food packaging bag being defective is greater than 0.73, it indicates that the food packaging bag is defective, and at this time, the staff needs to carry out further processing.
[0054] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, the above description focuses on specific embodiments of this specification. Additionally, the processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0055] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
[0056] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the scope of the present invention should be included within the protection scope of the present invention.
Claims
1. A computer-aided based food packaging bag defect detection method, characterized by, The method comprises: acquiring a surface image of a food packaging bag and performing noise reduction processing; converting the image after noise reduction processing to obtain a surface gray scale image and an HSV image of the food packaging bag; obtaining a hue factor of each pixel point according to an H channel value and an S channel value of each pixel point in the HSV image and a standard deviation of H channel values of all pixel points in the HSV image; in the surface gray scale image of the food packaging bag, the product of the hue factor of each pixel point and the gradient value of each pixel point in different directions in its neighborhood is the hue gradient value of each pixel point in different directions; obtaining an adjustment factor of each pixel point in each direction based on the hue gradient value of each pixel point in each direction; acquiring neighborhood pixel points of each pixel point; updating the gray scale value of each pixel point according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a first updated gray scale image; obtaining the hue gradient value and the adjustment factor of each pixel point in different directions based on the first updated gray scale image; updating the gray scale value of each pixel point in the first updated gray scale image according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a second updated gray scale image, and so on, until the number of updates reaches a preset number, to obtain a final gray scale image; obtaining a gray scale image data set and a training set, inputting the final gray scale image into a food packaging bag piece detection neural network and outputting a probability of defects of the food packaging bag; and determining whether the food packaging bag has defects according to the probability of defects of the food packaging bag.
2. The computer-aided based food packaging bag defect detection method according to claim 1, wherein The method comprises:
3. The computer-aided based food packaging bag defect detection method according to claim 1, wherein acquiring a surface image of a food packaging bag and performing noise reduction processing; converting the image after noise reduction processing to obtain a surface gray scale image and an HSV image of the food packaging bag; 4. The computer-aided based food packaging bag defect detection method according to claim 3, wherein, obtaining a hue factor of each pixel point according to an H channel value and an S channel value of each pixel point in the HSV image and a standard deviation of H channel values of all pixel points in the HSV image; 5. The computer-aided based food packaging bag defect detection method according to claim 1, wherein, in the surface gray scale image of the food packaging bag, the product of the hue factor of each pixel point and the gradient value of each pixel point in different directions in its neighborhood is the hue gradient value of each pixel point in different directions; obtaining an adjustment factor of each pixel point in each direction based on the hue gradient value of each pixel point in each direction; 6. The computer-aided based food packaging bag defect detection method according to claim 5, wherein, acquiring neighborhood pixel points of each pixel point; updating the gray scale value of each pixel point according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a first updated gray scale image; obtaining the hue gradient value and the adjustment factor of each pixel point in different directions based on the first updated gray scale image; updating the gray scale value of each pixel point in the first updated gray scale image according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a second updated gray scale image, and so on, until the number of updates reaches a preset number, to obtain a final gray scale image; obtaining a gray scale image data set and a training set, inputting the final gray scale image into a food packaging bag piece detection neural network and outputting a probability of defects of the food packaging bag; and determining whether the food packaging bag has defects according to the probability of defects of the food packaging bag. The method comprises: acquiring a surface image of a food packaging bag and performing noise reduction processing; converting the image after noise reduction processing to obtain a surface gray scale image and an HSV image of the food packaging bag; obtaining a hue factor of each pixel point according to an H channel value and an S channel value of each pixel point in the HSV image and a standard deviation of H channel values of all pixel points in the HSV image; in the surface gray scale image of the food packaging bag, the product of the hue factor of each pixel point and the gradient value of each pixel point in different directions in its neighborhood is the hue gradient value of each pixel point in different directions; obtaining an adjustment factor of each pixel point in each direction based on the hue gradient value of each pixel point in each direction; acquiring neighborhood pixel points of each pixel point; updating the gray scale value of each pixel point according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a first updated gray scale image; obtaining the hue gradient value and the adjustment factor of each pixel point in different directions based on the first updated gray scale image; updating the gray scale value of each pixel point in the first updated gray scale image according to the gray scale value, the hue gradient value in different directions and the adjustment factor to obtain a second updated gray scale image, and so on, until the number of updates reaches a preset number, to obtain a final gray scale image; obtaining a gray scale image data set and a training set, inputting the final gray scale image into a food packaging bag piece detection neural network and outputting a probability of defects of the food packaging bag; and determining whether the food packaging bag has defects according to the probability of defects of the food packaging bag.
7. The computer-aided based food packaging bag defect detection method according to claim 6, wherein, The updating of the gray value of each pixel point according to the gray value of each pixel point, the hue gradient value in different directions and the adjustment factor comprises: obtaining an average value of the product of the hue gradient value in each direction of the pixel point and the adjustment factor; and the sum of the average value and the gray value of the pixel point is the updated gray value of the pixel point.
8. The computer-aided based food packaging bag defect detection method according to claim 1, wherein, The obtaining of the gray image data set comprises: obtaining at least two final gray images to form a final gray image data set; and labeling the final gray image data set by using an artificial labeling method to form a training set, wherein the artificial labeling is to label the final gray images in the final gray image data set into two categories of defective and non-defective, and the defective is labeled as 1 and the non-defective is labeled as 0.
9. The computer-aided based food packaging bag defect detection method according to claim 8, wherein, The inputting of the final gray image into the food packaging bag piece detection neural network and the outputting of the probability of the food packaging bag defect comprise: the food packaging bag piece detection neural network is a full connection neural network, and a loss function is a cross-entropy loss function; the food packaging bag piece detection neural network is trained by using the training set to obtain a trained food packaging bag piece detection neural network; and the final gray image is inputted into the trained food packaging bag piece detection neural network to output the probability of the food packaging bag defect.
10. The computer-aided based food packaging bag defect detection method according to claim 1, wherein, The judging of whether the food packaging bag is defective according to the probability of the food packaging bag defect comprises: setting a judgment threshold value, and if the probability of the food packaging bag defect is greater than the judgment threshold value, the food packaging bag is defective.
Citation Information
Patent Citations
Mechanical part stress corrosion detection method and system based on image processing
CN113689428A
Packaging bag cover printing defect automatic detection system and method
CN114092375A