A machine vision-based food packaging visual inspection method and system
By analyzing the pixel value deviation and light response of food packaging can images and standard images from multiple perspectives, light interference is eliminated, achieving efficient and accurate defect detection of food packaging cans and solving the detection error problem caused by light differences.
Patent Information
- Application Number
- CN202510880606.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-27
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-06-27
AI Technical Summary
Existing machine vision-based food packaging can inspection methods suffer from defect misjudgment or omission due to differences in lighting conditions, resulting in insufficient accuracy and reliability of inspection results.
By acquiring images of food packaging cans from multiple perspectives and standard images, we analyze pixel value deviation, light response, and positional light interference. We then use the degree of light interference to eliminate the influence of light and filter out defective pixels, thus achieving accurate defect detection.
It improves the precision and accuracy of visual inspection of food packaging cans, simplifies the calculation process, increases inspection efficiency, and reduces reliance on complex calculations.
Smart Images

Figure CN120525858B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of image processing. More particularly, the present application relates to a food packaging visual inspection method and system based on machine vision. BACKGROUND
[0002] In the field of food industry, the quality of food packaging cans directly affects the safety, aesthetics and market competitiveness of products, so efficient and accurate packaging visual inspection is crucial. Food packaging can detection technology based on machine vision has gradually become the mainstream detection method due to its non-contact, automation and high-speed detection advantages. Currently, a common detection method is to acquire images of food packaging cans to be detected and compare them with pre-acquired images of defect-free food packaging cans, and use image gray difference to locate the defect area on the packaging surface. This method can quickly identify scratches, stains, printing defects and other problems on the packaging surface.
[0003] However, this method faces a key problem in practical application. Due to factors such as changes in environmental light during food packaging can production, position deviation of acquisition equipment, and differences in light reflectivity of different batches of packaging materials, there are often light differences between the images of food packaging cans to be detected and the images of defect-free food packaging cans. Such light differences can significantly affect image gray values, and different colors of food packaging cans have different sensitivities to light differences. For example, light-colored packaging materials such as white and light yellow have high reflectivity, so when the light intensity changes slightly, the image gray value will fluctuate greatly. For dark-colored packaging materials such as black and dark blue, the gray value changes relatively little when the light intensity changes greatly because of their strong light absorption ability. The difference in gray value changes of different colored packaging under the influence of light further complicates the complexity of gray difference judgment, making the gray difference possibly caused by light changes rather than real defects, thus leading to defect misjudgment or omission, reducing the accuracy and reliability of the detection results, and failing to meet the needs of high-quality food packaging can detection. Therefore, how to effectively eliminate the interference of light differences and improve the accuracy of food packaging can visual inspection methods based on image comparison has become a technical problem to be solved. SUMMARY
[0004] To solve the problem of how to effectively eliminate the interference of light differences and improve the accuracy of food packaging can visual inspection methods based on image comparison, the present application provides a food packaging visual inspection method and system based on machine vision.
[0005] In a first aspect, the present application provides a food packaging visual inspection method based on machine vision, comprising:
[0006] acquiring food packaging can images under several viewing angles and standard food packaging can images;
[0007] Obtaining a standard food packaging can image corresponding to the food packaging can image as a reference image, and recording the absolute value of the pixel value difference between each pixel in the food packaging can image and the matching pixel of the reference image as the pixel value deviation of each pixel in the food packaging can image;
[0008] For any pixel in the food packaging can image, obtaining the pixel with the same position as the pixel in the food packaging can image under each viewing angle as a same-light condition pixel, obtaining the position light interference degree of the pixel according to the pixel value deviation of the same-light condition pixel of the pixel, obtaining the matching pixel of the pixel in the food packaging can image under other viewing angles as a same-object pixel, obtaining the light response degree of the pixel according to the pixel value variance of the same-object pixel of the pixel, and obtaining the light interference degree of the pixel according to the light response degree and the position light interference degree, wherein the light interference degree is positively correlated with the light response degree and the position light interference degree; and removing the pixel value deviation caused by light from the pixel value deviation of the pixel by using the light interference degree to obtain the defect possibility of the pixel.
[0009] According to the defect possibility, the defect pixels are screened out to realize defect area detection.
[0010] The present application can realize defect detection only by some simple pixel values, and compared with the neural network algorithm, the defect detection method does not need network training and complex calculation formula, so that the detection efficiency is higher; further, considering that the pixel values of the defect area of the food packaging can with defects and the defect area of the food packaging can without defects are different, the defect detection is realized by analyzing the pixel value difference between the food packaging can to be detected and the standard food packaging can; further, considering that the light difference also causes the pixel value difference between the food packaging can to be detected and the standard food packaging can, when the defect detection is performed by using the pixel value difference, the light interference is excluded by introducing the light interference degree, and thus the accuracy of the defect detection is improved; further, when the light interference is analyzed, considering that the light at the same spatial position has high similarity in a short time, the pixel value difference of the same-light condition pixel is analyzed to accurately reflect the influence of the light difference on the spatial position; further, when the light interference is analyzed, considering that different structures and colors have different responses to light, the light response degree is introduced to accurately reflect the light response of each point; further, the position light interference degree and the light response degree are combined to accurately reflect the light interference of each pixel, so that the pixel value difference caused by the light interference is effectively excluded, and thus accurate defect detection is realized.
[0011] Preferably, the method for obtaining the position light interference degree comprises:
[0012] The box plot method is used to filter out abnormal pixel value deviations in all pixel value deviations of the same light condition pixels of the pixel, and the mean value of the remaining pixel value deviations is taken as the light interference degree of the pixel.
[0013] The application considers that the light difference of the same spatial position in a short time is small, and the pixel value difference under the same light condition is small if there is no defect, so that the box plot method is used to filter out the similar pixel value deviations, and the remaining pixel value deviations accurately reflect the light interference of the spatial position.
[0014] Preferably, the method for obtaining the light response degree comprises:
[0015] The column pixels where the pixel is located are taken as radial pixels, the difference between the pixel value variance of the same object pixel of the pixel and the mean value of the pixel value variance of the same object pixel of all radial pixels is normalized to obtain the light response degree.
[0016] The application reflects the pixels of a point of the food packaging can at different spatial positions through the same object pixel, and the pixel value difference of the same object pixel is mainly affected by the light difference, so that the pixel value variance of the same object pixel is used to reflect the response of the pixel to the light.
[0017] Preferably, the method for obtaining the light interference degree comprises:
[0018] The product of the light response degree and the position light interference degree of the pixel is taken as the light interference degree of the pixel.
[0019] The application combines the light response degree and the position light interference degree in the form of product, and the combination is relatively simple and has high implementation efficiency.
[0020] Preferably, the method for obtaining the light interference degree comprises:
[0021] The pixel value deviation of the pixel is divided by the light interference degree to obtain the adjusted pixel value deviation of the pixel.
[0022] The adjusted pixel value deviation of the same object pixel of the pixel is compared with the preset deviation threshold value, if the adjusted pixel value deviation is greater than the preset deviation threshold value, the same object pixel is recorded as a suspected defect pixel, and the ratio of the number of suspected defect pixels to the number of same object pixels of the pixel is taken as the defect possibility of the pixel.
[0023] Preferably, the method for screening out the defect pixel according to the defect possibility comprises:
[0024] Pixels with a defect possibility greater than a preset possibility threshold in the food packaging can image are recorded as defect pixels.
[0025] The present application screens defect pixels by simple threshold comparison, and the implementation calculation is simple and efficient.
[0026] Preferably, the implementation of the defect area detection comprises:
[0027] The area formed by the defect pixels in the food packaging can image is recorded as a defect area and is marked out.
[0028] Preferably, the standard food packaging can image corresponding to the food packaging can image is obtained as a reference image, comprising:
[0029] The food packaging can image is matched with the standard food packaging can image, and the standard food packaging can image with the largest matching area among all the standard food packaging can images is obtained as the reference image of the food packaging can image.
[0030] Preferably, the standard food packaging can image is a defect-free food packaging can image of the same type as the food packaging can to be detected.
[0031] In the second aspect, the present application provides a food packaging visual detection system based on machine vision, comprising a processor and a memory, wherein the memory stores computer program instructions, and when the computer program instructions are executed by the processor, the above-mentioned food packaging visual detection method based on machine vision is realized.
[0032] By using the above technical solution, the above-mentioned food packaging visual detection method based on machine vision is generated into a computer program and stored in the memory to be loaded and executed by the processor, so that a terminal device is made according to the memory and the processor, and the use is convenient.
[0033] The present application has the following advantages:
[0034] The present application can realize defect detection only by some simple pixel values, and compared with the neural network algorithm, the defect detection method does not need network training and complex calculation formula, so the detection efficiency is higher.
[0035] Further, considering that there is a difference in pixel values between the defect area of the food packaging can with defects and the defect area of the food packaging can without defects, the defect detection is realized by analyzing the difference in pixel values between the food packaging can to be detected and the standard food packaging can.
[0036] Further, considering that the light difference also causes the pixel value difference between the food packaging can to be detected and the standard food packaging can, when the pixel value difference is used for defect detection, the light interference degree is introduced to eliminate the light interference, and thus the accuracy of the defect detection is improved.
[0037] Further, when the light interference is analyzed, considering that the light at the same space position has high similarity in a short time, the pixel value difference of the same light condition pixel is analyzed to accurately reflect the influence of the light difference at the space position.
[0038] Further, when the light interference is analyzed, considering that different structures and colors have different responses to light, the light response degree is introduced to accurately reflect the light response of each point.
[0039] Further, the position light interference degree and the light response degree are combined to accurately reflect the light interference of each pixel, so that the pixel value difference caused by the light interference is effectively eliminated, and thus accurate defect detection is realized. BRIEF DESCRIPTION OF DRAWINGS
[0040] Figure 1 is a step flow chart of a food packaging visual detection method based on machine vision according to an embodiment of the present application. DETAILED DESCRIPTION
[0041] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of the present application.
[0042] The specific embodiments of the present application will be described in detail below with reference to the drawings.
[0043] Please refer to Figure 1 which shows a step flow chart of a food packaging visual detection method based on machine vision according to an embodiment of the present application. The method comprises the following steps:
[0044] S1: Obtain food packaging can images under several viewing angles and several standard food packaging can images.
[0045] Specifically, the food packaging can to be detected is rotated around the axis for one revolution, and during the rotation, images are collected at a preset collection interval to obtain food packaging can images under several viewing angles.
[0046] In the memory, the image of the food packaging can without defects of the same type as the food packaging can to be detected is called a standard food packaging can image.
[0047] It should be noted that the method in the embodiment mainly aims at defect detection of food packaging cans, and the defect detection effect of the method in the embodiment on food packaging cans or packaging bags cannot be guaranteed.
[0048] S2: Obtain a standard food packaging can image corresponding to the food packaging can image as a reference image, and record the absolute value of the pixel value difference between each pixel in the food packaging can image and the matching pixel of the reference image as the pixel value deviation of each pixel in the food packaging can image.
[0049] It should be noted that the pixel values of the same position area of the food packaging can with defects and the food packaging can without defects will be different, so if there is a defect in the food packaging can image, the pixel values of the defect area in the food packaging can image to be detected and the corresponding area of the standard food packaging can image will be different, so the defect area can be detected by the pixel value difference.
[0050] Preferably, as an example, obtaining a standard food packaging can image corresponding to the food packaging can image as a reference image, and recording the difference between the food packaging can image and the matching pixel of the reference image as the pixel value deviation of each pixel in the food packaging can image, comprising:
[0051] Matching the food packaging can image with the standard food packaging can image, and obtaining the standard food packaging can image with the largest matching area of the food packaging can image as the reference image of the food packaging can image in all standard food packaging can images.
[0052] Recording the absolute value of the pixel value difference between each pixel in the food packaging can image and the matching pixel of the reference image as the pixel value deviation of each pixel in the food packaging can image.
[0053] S3: For any pixel in the food packaging can image, obtaining the pixel with the same position as the pixel in the food packaging can image under each viewing angle as the same light condition pixel, obtaining the position light interference degree of the pixel according to the pixel value deviation of the same light condition pixel of the pixel, obtaining the matching pixel of the pixel in the food packaging can image under other viewing angles as the same object pixel, obtaining the light response degree of the pixel according to the pixel value variance of the same object pixel of the pixel, obtaining the light interference degree of the pixel according to the light response degree and the position light interference degree, and the light interference degree is positively correlated with the light response degree and the position light interference degree; using the light interference degree to exclude the pixel value deviation caused by light in the pixel value deviation of the pixel to obtain the defect possibility of the pixel.
[0054] It should be noted that, due to the difference of light conditions of the food factory in each period, the light of the food packaging can image and the standard food packaging can image may be different. The difference of light will also cause the difference of pixel value of the food packaging can image and the standard food packaging can image. Therefore, in order to realize the food packaging can defect detection by the way of pixel value difference, the interference of light needs to be excluded.
[0055] S30: for any pixel in the food packaging can image, the pixel with the same position in the food packaging can image under each view angle is recorded as the same light condition pixel, and the position light interference degree of the pixel is obtained according to the pixel value deviation of the same light condition pixel of the pixel.
[0056] It should be noted that, due to the similarity of light conditions of the food factory in the same space position in a short time. Therefore, the pixel value deviation of different points in the food packaging can at a space position can reflect the light interference at the space position.
[0057] Optionally, as an example, the position light interference degree of the pixel is obtained according to the pixel value deviation of the same light condition pixel of the pixel, comprising:
[0058] The average of the pixel value deviation of all same light condition pixels of the pixel is taken as the position light interference degree of the pixel.
[0059] It should be noted that, the factors causing large pixel value deviation are not only light interference, but also defects; if there are defect pixels in the same light condition pixels, the calculated position light interference degree will be inaccurate.
[0060] Preferably, as an example, the position light interference degree of the pixel is obtained according to the pixel value deviation of the same light condition pixel of the pixel, comprising:
[0061] The abnormal pixel value deviation is screened out from the pixel value deviation of all same light condition pixels of the pixel by using the box plot method, and the average of the remaining pixel value deviation is taken as the position light interference degree of the pixel.
[0062] It can be understood that, the same light condition pixel is the pixel collected when the different points in the food packaging can rotate to a space position. Since the light condition of a space position will not change in a short time, the pixel value deviation of all same light condition pixels should be similar, so the average of the pixel value deviation of the same light condition pixel can reflect the light interference of the space position.
[0063] S31: the matching pixel of the pixel in the food packaging can image under other view angles is recorded as the same object pixel, and the light response degree of the pixel is obtained according to the pixel value variance of the same object pixel of the pixel.
[0064] It should be noted that, due to different response degrees of each color or structure to light, some colors or structures have large pixel differences under different light conditions, and some colors or structures have small pixel differences under different light conditions. For example, there are some concave-convex structures in the food packaging can, the A point of the food packaging can is a convex structure, and the pixel value of the point under the strong light condition is greatly different from the pixel value under the dark light condition. The B point of the food packaging can is a flat structure, and the pixel value of the food packaging can B under the strong light condition is less different from the pixel value under the dark light condition. Thus, the response degrees of each position of the food packaging can to light are different. To accurately reflect the light interference of each pixel, the response degree of light also needs to be considered.
[0065] It should be further noted that, the difference of the pixel value of a point of the food can rotating to different spatial positions is mainly caused by light. If the pixel value of a point of the food can rotating to different spatial positions is greatly different, it indicates that the response degree of the point of the food can to light is large.
[0066] Optionally, as an example, the response degree of light of the pixel is obtained according to the pixel value variance of the homologous pixels of the pixel, including:
[0067] The range of the pixel values of all the homologous pixels of the pixel is taken as the response degree of light of the pixel.
[0068] It should be noted that, the range mainly reflects the limit difference, and cannot comprehensively reflect the pixel difference, thus the accuracy of the response degree of light obtained by this method is relatively poor.
[0069] Preferably, as an example, the response degree of light of the pixel is obtained according to the pixel value variance of the homologous pixels of the pixel, including:
[0070] The column pixels where the pixel is located are taken as radial pixels, the difference between the pixel value variance of the homologous pixels of the pixel and the average of the pixel value variances of the homologous pixels of all the radial pixels is normalized to obtain the response degree of light.
[0071] It can be understood that the homothetic pixel represents a pixel of a point of the food can rotating to a different spatial position. The pixel value variance of the homothetic pixel can reflect the pixel value difference of the pixel of the point of the food can rotating to the different spatial position, and the greater the value is, the greater the pixel value difference of the pixel under different light conditions is, and thus the greater the response degree of the pixel to the light is. Since the food can rotates around the axis, the point of the food can rotates one circle around the axis, and the meridian pixel is a point coinciding with the path of the point, and thus the spatial position passed by the radial pixel is the same as the point. Thus, the light condition of the radial pixel is similar to the point, and thus the comparison of the pixel value variance of the point and the radial pixel can exclude the interference caused by the light difference, and more accurately reflect the response of the point to the light.
[0072] S32: obtaining the light interference degree of the pixel according to the light response degree and the position light interference degree.
[0073] Optionally, as an example, obtaining the light interference degree of the pixel according to the light response degree and the position light interference degree comprises:
[0074] adding the light response degree and the position light interference degree to obtain the light interference degree of the pixel.
[0075] Preferably, as an example, obtaining the light interference degree of the pixel according to the light response degree and the position light interference degree comprises:
[0076] multiplying the light response degree and the position light interference degree to obtain the light interference degree of the pixel.
[0077] It can be understood that the position light interference degree reflects the light condition of a spatial position, and the light response degree reflects the response of a point of the food can to the light interference; the greater the light interference degree of the pixel is, the greater the spatial position of the point of the food can corresponding to the pixel is interfered by the light, and at the same time, the greater the response of the point of the food can to the light interference is, and thus the greater the light interference degree of the point of the food can is, i.e. the greater the light interference degree of the pixel is.
[0078] S33: obtaining the defect possibility of the pixel by excluding the pixel value deviation caused by the light from the pixel value deviation of the pixel according to the light interference degree.
[0079] Preferably, as an example, obtaining the defect possibility of the pixel by excluding the pixel value deviation caused by the light from the pixel value deviation of the pixel according to the light interference degree comprises:
[0080] dividing the pixel value deviation of the pixel by the light interference degree to obtain the adjusted pixel value deviation of the pixel;
[0081] The adjusted pixel value deviation of the same-pixel of the pixel is compared with a preset deviation threshold, if the adjusted pixel value deviation is greater than the preset deviation threshold, the same-pixel is recorded as a suspected defect pixel, and a ratio of a number of suspected defect pixels to a number of same-pixels of the pixel is taken as a defect possibility of the pixel.
[0082] It can be understood that the light interference is excluded by dividing the pixel value deviation by the light interference degree, and the suspected defect pixel is screened by comparing the pixel value deviation after excluding the light interference with the preset deviation threshold. Since the same-pixel reflects the pixels of a point of the food can at different spatial positions, if the pixels of the point of the food can at multiple spatial positions are all determined as the suspected defect pixel, the point of the food can has a higher possibility of defects, and the defect possibility is calculated based on this.
[0083] S4: screening a defect pixel according to the defect possibility to realize defect area detection.
[0084] Preferably, as an example, the defect pixel is screened according to the defect possibility to realize the defect area detection, including:
[0085] Pixels with a defect possibility greater than a preset possibility threshold in the food packaging can image are recorded as defect pixels.
[0086] An area formed by the defect pixels in the food packaging can image is recorded as a defect area, and is marked out.
[0087] The embodiment of the present application also discloses a food packaging visual detection system based on machine vision, including a processor and a memory, the memory stores computer program instructions, when the computer program instructions are executed by the processor, a food packaging visual detection method based on machine vision according to the present application is realized.
[0088] The above system also includes a communication bus and a communication interface and other components familiar to those skilled in the art, the settings and functions of which are known in the art, and thus will not be repeated here.
[0089] In the present application, the aforementioned memory can be any tangible medium containing or storing a program, which can be used or combined with an instruction execution system, device or apparatus. For example, the computer readable storage medium can be any appropriate magnetic storage medium or magneto-optical storage medium, such as resistive random access memory, dynamic random access memory, static random access memory, enhanced dynamic random access memory, high bandwidth memory, hybrid memory cube, etc., or any other medium that can be used to store the required information and can be accessed by an application program, module or both. Any such computer storage medium can be part of the device or accessible or connectable to the device.
Claims
1. A machine vision-based visual inspection method for food packaging, characterized in that, include: Acquire images of food packaging cans from several different perspectives, as well as images of several standard food packaging cans; Obtain a standard food packaging can image corresponding to the food packaging can image as a reference image, and record the absolute value of the pixel value difference between each pixel in the food packaging can image and the matching pixel in the reference image as the pixel value deviation of each pixel in the food packaging can image. For any pixel in the image of the food packaging can: In the food packaging can image from various viewpoints, the pixels with the same position as the pixel are recorded as pixels under the same lighting conditions; the degree of light interference at the position of the pixel is obtained based on the average value deviation of the pixel values of all pixels under the same lighting conditions. In food packaging can images from other perspectives, the matching pixels of the pixel are obtained and recorded as the same object pixels; the light response of the pixel is obtained based on the variance of the pixel values of all the same object pixels; The light interference level of the pixel is obtained based on the light response level and the positional light interference level, wherein the light interference level is positively correlated with both the light response level and the positional light interference level; The pixel value deviation of the pixel is adjusted by utilizing the degree of light interference to obtain the adjusted pixel deviation, and the defect probability of the pixel is obtained based on the adjusted pixel deviation; Defect pixels are selected based on their probability of defects in order to achieve defect area detection.
2. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that: Abnormal pixel value deviations are eliminated from the pixel value deviations of all pixels with the same lighting conditions for that pixel using the box plot method. The average of the remaining pixel value deviations is taken as the degree of light interference at the position of that pixel.
3. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that: The pixel in the column containing the given pixel is taken as the radial pixel. The difference between the variance of the pixel value of the same pixel and the mean variance of the pixel value of the same pixel of all radial pixels is normalized to obtain the light response degree.
4. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that, The method for obtaining the degree of light interference includes: The light interference level of a pixel is calculated by multiplying its light response level by the light interference level at its location.
5. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that, The process of adjusting the pixel value deviation of the pixel based on the degree of light interference to obtain the adjusted pixel deviation, and determining the defect probability of the pixel based on the adjusted pixel deviation, includes: The adjusted pixel value deviation is obtained by dividing the pixel value deviation by the degree of light interference. The adjusted pixel value deviation of the same pixel is compared with a preset deviation threshold. If the adjusted pixel value deviation is greater than the preset deviation threshold, the same pixel is recorded as a suspected defective pixel. The ratio of the number of suspected defective pixels to the number of same pixels is taken as the defect probability of the pixel.
6. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that, The step of filtering defective pixels based on defect probability includes: Pixels in the food packaging can image with a defect probability greater than a preset probability threshold are recorded as defect pixels.
7. The machine vision-based visual inspection method for food packaging according to claim 6, characterized in that, The method for achieving defect area detection includes: The area formed by defective pixels in the image of the food packaging can is recorded as the defect area and marked.
8. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that, The step of obtaining a standard food packaging can image corresponding to the food packaging can image as a reference image includes: The food packaging can image is matched with standard food packaging can images. Among all standard food packaging can images, the standard food packaging can image with the largest matching area is selected as the reference image for the food packaging can image.
9. The machine vision-based visual inspection method for food packaging according to claim 1, characterized in that, The standard food packaging can image is an image of a defect-free food packaging can of the same type as the food packaging can to be inspected.
10. A machine vision-based visual inspection system for food packaging, characterized in that, include: A processor and a memory, the memory storing computer program instructions that, when executed by the processor, implement a machine vision-based visual inspection method for food packaging according to any one of claims 1-9.
Citation Information
Patent Citations
Planar printing defect detection method, device and system
CN110956630A
Automobile pipe fitting defect detection method and system
CN119810098A