Visual inspection method and system for beverage package defects
By establishing a standard image library under preset scenarios and analyzing the optical distortion effect of transparent packaging, the problem of insignificant characteristics in transparent packaging defect detection is solved, and efficient and accurate defect detection is achieved.
Patent Information
- Application Number
- CN202510406726.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-25
AI Technical Summary
The prior art has limited effect in the detection of defects of transparent packaging materials, and it is difficult to effectively extract features, especially the sensitivity to different types of defects, and the equipment cost is high.
The optical distortion effect of transparent packaging on background patterns was analyzed through image pre-processing, registration, difference and enhancement processing, and the adaptive enhancement strategy was used to highlight defect characteristics.
It improves the sensitivity and accuracy of transparent packaging defect detection, can effectively identify linear and point-shaped defects, suppress background noise, and provide reliable detection benchmarks.
Smart Images

Figure BDA0005341380340000031 
Figure BDA0005341380340000101 
Figure FDA0005341380330000031
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image data processing, and more specifically, to a visual detection method and system for beverage packaging defects. Background Art
[0002] With the rapid development of the consumer goods market and the continuous improvement of consumers' requirements for product quality, the quality control of beverage packaging has become particularly important. Beverage packaging is not only related to the appearance and market image of the product, but also directly affects the safety and shelf life of the product. Therefore, it is of great significance to perform efficient and accurate defect detection on beverage packaging.
[0003] During the production process of beverage packaging, various defects may occur, such as bubbles, cracks, impurities, deformation, etc. These defects not only affect the appearance of the product, but may also lead to poor packaging sealing, thereby causing product leakage or contamination. In recent years, with the development of computer vision and image processing technologies, automated visual detection systems have been widely used in the quality control of beverage packaging. These systems capture packaging images through camera devices and use image processing algorithms to automatically identify possible defects, greatly improving the detection efficiency and accuracy. However, these technologies have encountered significant challenges when applied to transparent packaging materials. Transparent packaging materials themselves hardly absorb visible light, resulting in very little information about the packaging itself in the directly captured images, and the defect features are not obvious, making it difficult to directly extract effective features through conventional image processing methods. Although some systems attempt to use special light sources (such as infrared light or ultraviolet light) to enhance the visibility of transparent materials, this method has a high equipment cost and different sensitivities to different types of defects, and the actual application effect is limited. Summary of the Invention
[0004] In order to overcome the problem of limited effectiveness in defect detection of transparent packaging in the prior art, the present invention proposes a visual detection method and system for beverage packaging defects to solve the above problems.
[0005] The present invention provides the following technical solutions:
[0006] A visual detection method for beverage packaging defects, comprising:
[0007] Obtaining standard images corresponding to different models of beverage packaging by photographing different models of beverage packaging under a preset scenario, and establishing a standard image library using all models of beverage packaging and their corresponding standard images; the preset scenario includes lighting conditions, background images, and camera parameters;
[0008] Collecting an image of the beverage packaging to be detected under the preset scenario, and performing pre-image processing to obtain a detection image, where the image pre-processing includes denoising and illumination equalization;
[0009] Obtain the model of the beverage package to be detected, select the corresponding standard image from the standard image library according to the obtained model, and record it as the reference image;
[0010] Register the detection image with the reference image according to the characteristics of the background image, perform a difference between the registered detection image and the reference image to obtain a difference image, and perform enhancement processing on the difference image to obtain an enhanced image;
[0011] Perform simple threshold processing on the enhanced image to extract the abnormal area;
[0012] Analyze the characteristics of the abnormal area, determine the defect position and defect size, and generate a detection result report.
[0013] Preferably, the step of obtaining the standard images corresponding to different models of beverage packages by taking pictures of different models of beverage packages under preset scenarios includes:
[0014] For each model of beverage package:
[0015] Select at least 10 defect-free beverage package samples;
[0016] Design a background board containing a preset background image, arrange it according to the preset lighting conditions, and use a camera with predetermined camera parameters in front of the background board to take pictures of each sample to obtain sample images;
[0017] Perform image preprocessing on the collected sample images;
[0018] Take the average value of the sample images after image preprocessing to generate the standard image corresponding to this model of beverage package.
[0019] Preferably, the background image is an image containing at least two different colors of stripes alternating; the lighting conditions include light source type, light source position, light intensity, and light source color temperature; the camera parameters include focal length, aperture size, exposure time, and ISO sensitivity.
[0020] Preferably, the registration of the detection image with the reference image according to the characteristics of the background image includes:
[0021] Extract the intersection points of the background stripes in the detection image as the first set of feature points;
[0022] Extract the intersection points of the background stripes in the reference image as the second set of feature points;
[0023] Based on the correspondence between the first set of feature points and the second set of feature points, use a feature point matching algorithm to calculate the spatial transformation matrix from the detection image to the reference image;
[0024] Use the spatial transformation matrix to apply an affine transformation to the detection image for geometric correction;
[0025] The phase correlation method is used to align the transformed detection image to complete the registration of the detection image and the reference image.
[0026] Preferably, the enhancing the differential image to obtain an enhanced image includes:
[0027] Calculating the gradient images Gx and Gy of the differential image in the horizontal and vertical directions;
[0028] Within an n×n window around each pixel position (x, y), calculating the sum of squares of the horizontal gradient Gxx, the sum of squares of the vertical gradient Gyy, and the sum of products of the horizontal gradient and the vertical gradient Gxy, where n is an integer greater than 3;
[0029] Constructing a 2×2 matrix M, M = [[Gxx, Gxy], [Gxy, Gyy]];
[0030] Solving the characteristic equation of the matrix M to obtain two eigenvalues λ1 and λ2;
[0031] According to the magnitude relationship between the eigenvalues λ1 and λ2, classifying the image region into a region with a main direction, a region without a main direction, and a flat region;
[0032] Applying different enhancement strategies to different types of regions to generate an enhanced image.
[0033] Preferably, the applying different enhancement strategies to different types of regions includes:
[0034] Dividing the eigenvalue λ1 by λ2 to obtain the eigenvalue ratio R;
[0035] When the ratio R is greater than a preset threshold T1, determining that the region has an obvious main direction and adopting the following enhancement strategy:
[0036] According to the matrix M, obtaining the main direction angle θ using the following formula:
[0037]
[0038] Constructing a one-dimensional Gaussian filter consistent with the main direction angle and applying the filter along the main direction angle to enhance the continuity along the main direction;
[0039] When the ratio R is less than a preset threshold T2 and both λ1 and λ2 are greater than the noise threshold Tn, determining that the region is a region without a main direction and adopting the following enhancement strategy:
[0040] Applying a circular Laplacian operator to enhance the contrast between the central pixel and the surrounding pixels;
[0041] When both λ1 and λ2 are less than the noise threshold Tn, determine that the area is a flat area and adopt the following enhancement strategy:
[0042] Reduce the pixel values in the area by at least 50%.
[0043] Preferably, the simple threshold processing of the enhanced image and the extraction of the abnormal area include:
[0044] Generate a binary image based on the enhanced image according to a preset pixel threshold;
[0045] Perform connected region labeling on the binary image to obtain a set of connected regions;
[0046] Filter out the connected regions with an area smaller than the preset area threshold, and extract the remaining connected regions as abnormal areas.
[0047] Preferably, the analysis of the abnormal area features, the determination of the defect position and size, and the generation of the detection result report include: calculating the number of pixels in the abnormal area as the defect area for each abnormal area, and calculating the centroid coordinates;
[0048] For the centroid coordinates of the abnormal area, convert them into the surface position coordinates of the beverage package through a preset coordinate mapping function;
[0049] For the pixel size of the abnormal area, convert it into the surface physical size of the beverage package through a preset size mapping function;
[0050] Generate a detection result report including the surface position coordinates and surface physical size of the beverage package.
[0051] Preferably, the preset coordinate mapping function is established as follows: establish a three-dimensional model of the beverage package, define a package surface coordinate system on the three-dimensional model of the beverage package, including height, circumferential angle, and radial distance; through pre-calibration, establish a mapping function between the image plane coordinate system and the package surface coordinate system;
[0052] The preset size mapping function is established as follows: place standard size markers in different surface areas of the beverage package, obtain the pixel size of the standard size markers in the image by shooting, and construct a conversion function from the image pixel size to the surface physical size.
[0053] The present invention also provides a visual detection system for beverage package defects, which is used to implement a visual detection method for beverage package defects, including:
[0054] A standard image library building module, which is used to obtain standard images corresponding to different models of beverage packages by taking pictures of different models of beverage packages under a preset scenario, and establish a standard image library using all models of beverage packages and their corresponding standard images; the preset scenario includes lighting conditions, background images, and camera parameters;
[0055] An image acquisition and processing module, which is used to acquire an image of the beverage package to be detected under a preset scenario, and perform pre-image processing to obtain a detection image. The image pre-processing includes denoising and illumination equalization;
[0056] A reference image acquisition module, which is used to obtain the model of the beverage package to be detected, select the corresponding standard image from the standard image library according to the obtained model, and record it as a reference image;
[0057] An image difference and enhancement module, which is used to register the detection image and the reference image according to the characteristics of the background image, perform difference on the registered detection image and the reference image to obtain a difference image, and perform enhancement processing on the difference image to obtain an enhanced image;
[0058] An abnormal area extraction module, which is used to perform simple threshold processing on the enhanced image to extract the abnormal area;
[0059] A defect analysis report module, which is used to analyze the characteristics of the abnormal area, determine the defect position and defect size, and generate a detection result report.
[0060] The present invention provides a visual detection method and system for beverage package defects, having the following beneficial effects:
[0061] By taking pictures of defect-free beverage packages of different models under a preset scenario and taking the average value to establish a standard image library, a reliable reference benchmark is provided for subsequent defect detection. This method does not directly observe the transparent package itself, but analyzes the optical distortion effect of the transparent package on the background pattern, converting the invisible defects of the transparent package into detectable changes in the background pattern, and solving the problem of less information and unclear features of transparent materials. Through the differential image enhancement processing based on the structure tensor, different enhancement strategies are adopted for different types of areas, which can effectively highlight different types of defect features. This adaptive enhancement method can not only enhance the continuity of linear defects (such as cracks and scratches), but also improve the contrast of point defects (such as bubbles and impurities), while suppressing background noise, greatly improving the sensitivity and accuracy of defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] Figure 1 It is a schematic flowchart of a visual detection method for beverage package defects of the present invention;
[0063] Figure 2Schematic diagram of the modules of a visual inspection system for beverage packaging defects of the present invention. Detailed implementation manners
[0064] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present invention.
[0065] Embodiment 1
[0066] Please refer to Figure 1 , in this embodiment, a visual inspection method for beverage packaging defects includes:
[0067] S1. Obtain standard images corresponding to different models of beverage packaging by photographing different models of beverage packaging under a preset scenario, and establish a standard image library using all models of beverage packaging and their corresponding standard images; the preset scenario includes lighting conditions, background images, and camera parameters;
[0068] The step of obtaining standard images corresponding to different models of beverage packaging by photographing different models of beverage packaging under a preset scenario includes:
[0069] For each model of beverage packaging:
[0070] Select at least 10 defect-free beverage packaging samples;
[0071] Design a background board containing a preset background image, arrange it according to the preset lighting conditions, and use a camera with predetermined camera parameters to photograph each sample in front of the background board to obtain sample images;
[0072] Perform image preprocessing on the collected sample images;
[0073] Take the average value of the sample images after image preprocessing to generate a standard image corresponding to this model of beverage packaging.
[0074] The background image is an image containing at least two different color stripes alternating; the lighting conditions include light source type, light source position, light intensity, and light source color temperature; the camera parameters include focal length, aperture size, exposure time, and ISO sensitivity.
[0075] In this embodiment, the process of establishing a standard image library can be:
[0076] First, determine the parameters of the preset scenario. The background image can be a red and blue striped pattern, and the stripe width can be 3 cm to form a distinct contrast. The lighting conditions are set as follows: The light source type can be an LED diffused light, the light source positions can be at a 45° angle from the top and 30° angles from the left and right sides respectively, the light intensity can be 600 lux, and the light source color temperature can be 5500K. The camera parameters are set as follows: The focal length can be 50 mm, the aperture size can be f / 8.0, the exposure time can be 1 / 100 second, and the ISO sensitivity can be 200.
[0077] For each type of beverage packaging, perform the following steps to establish a standard image:
[0078] First, randomly select 10 defect-free beverage packaging samples from the production line. These samples are confirmed by quality inspection personnel to ensure that there are no defects such as dents, deformations, scratches, etc. on the surface.
[0079] Then, set up a background board in the laboratory environment, with the preset striped pattern printed on it. Fix the background board on a bracket and arrange the light source according to the preset lighting conditions. The camera is fixed on a tripod, and the distance from the background board can be 200 cm, and the height is level with the sample placement position.
[0080] Next, place each sample in turn at a fixed position in front of the background board and take pictures using the preset camera parameters. One image is taken for each sample, and a total of 10 sample images are obtained.
[0081] Perform preprocessing on the collected sample images, including the following steps: First, perform image denoising, and a Gaussian filter can be used to reduce image noise; then, perform illumination equalization processing, and the histogram equalization method can be used to adjust the image brightness distribution to ensure the consistency of illumination conditions among different images.
[0082] Finally, take the average value of the preprocessed sample images. The calculation method is to calculate the average value of the RGB values at each pixel position for the 10 samples respectively. In this way, a standard image of this type of beverage packaging is generated.
[0083] Store the standard images of all types of beverage packaging by type to establish a complete standard image library. Each type in the standard image library corresponds to a standard image and related shooting parameter records, which are convenient for quick retrieval during subsequent inspections.
[0084] Through the above steps, an image library containing standard images of different types of beverage packaging is established, providing a reliable reference benchmark for subsequent defect detection.
[0085] S2. Collect the image of the beverage packaging to be detected in the preset scenario, and obtain a detection image after preprocessing the image. The image preprocessing includes denoising and illumination equalization;
[0086] S3. Obtain the model of the beverage package to be detected, select the corresponding standard image from the standard image library according to the obtained model, and record it as the reference image;
[0087] In this embodiment, the image acquisition and processing process of the beverage package to be detected can be as follows:
[0088] After the standard image library is established, install image acquisition on the production line for automated detection. Set the same preset scenario conditions as those when establishing the standard image library at an appropriate position on the production line, including the same background image, lighting conditions, and camera parameter settings, to ensure the comparability of the image to be detected and the standard image.
[0089] Specifically, when the beverage package passes through the detection point on the production line, the photoelectric sensor triggers the camera to automatically take pictures without manual intervention, realizing continuous and efficient image acquisition. Perform preprocessing on the collected original image, including denoising and illumination equalization processing. The denoising process can adopt the same Gaussian filtering method as the standard image, and the illumination equalization also adopts the same histogram equalization method to ensure that the processed detection image is consistent with the standard image in the processing method.
[0090] Next, the model of the beverage package to be detected can be obtained by entering production information, etc. According to the obtained model, select the standard image of the corresponding model from the previously established standard image library, and use it as the reference image for subsequent defect detection and analysis.
[0091] S4. Register the detection image and the reference image according to the characteristics of the background image, perform difference on the registered detection image and the reference image to obtain a difference image, and perform enhancement processing on the difference image to obtain an enhanced image;
[0092] The registration of the detection image and the reference image according to the characteristics of the background image includes:
[0093] Extract the intersection points of the background stripes in the detection image as the first set of feature points;
[0094] Extract the intersection points of the background stripes in the reference image as the second set of feature points;
[0095] Based on the correspondence between the first set of feature points and the second set of feature points, use the feature point matching algorithm to calculate the spatial transformation matrix from the detection image to the reference image;
[0096] Use the spatial transformation matrix to apply an affine transformation to the detection image for geometric correction;
[0097] Adopt the phase correlation method to align the transformed detection image to complete the registration of the detection image and the reference image.
[0098] In this embodiment, the registration and differential processing process of the detection image and the reference image can be as follows:
[0099] After obtaining the detection image and the reference image, it is necessary to accurately register the two to ensure the accuracy of subsequent differential analysis. The registration process mainly uses the stripe features in the background image as reference points.
[0100] First, process the detection image to extract the intersection points of the background stripes. The Canny edge detection algorithm can be used to detect the stripe edges in the background, and then the Hough transform is used to identify the straight-line equations of the stripes. According to these straight-line equations, calculate the intersection point coordinates between the stripes to form the first feature point set. Similarly, apply the same processing method to the reference image to extract the intersection points of the background stripes as the second feature point set.
[0101] Next, match the first feature point set and the second feature point set. The random sample consensus algorithm can be used in combination with the spatial distribution relationship of the feature points to establish the corresponding relationship between the two feature point sets. Based on this corresponding relationship, calculate the spatial transformation matrix from the detection image to the reference image. This matrix can describe the rotation, translation, and scaling relationships between the two images.
[0102] Then, use the calculated spatial transformation matrix to apply an affine transformation to the detection image for geometric correction. This step transforms the detection image to a similar spatial position and scale as the reference image.
[0103] To further improve the registration accuracy, the phase correlation method can be used to finely align the transformed detection image. The phase correlation method is based on the Fourier transform and determines the translation relationship between the two images by analyzing the phase differences between them.
[0104] After completing the registration, perform pixel-level differential operations on the registered detection image and the reference image, that is, for each pixel position, calculate the difference between the pixel value of the detection image minus the pixel value of the reference image to generate a differential image. When light passes through the transparent packaging material, optical phenomena such as refraction and scattering will occur, resulting in a specific distortion pattern of the background pattern during imaging. This distortion pattern is highly consistent for the same type of packaging without defects and can be regarded as the "optical fingerprint" of this type of packaging. When there are defects in the packaging (such as bubbles, cracks, impurities, etc.), these defects will change the optical properties of the local area, thereby causing changes in the distortion pattern of the background pattern at the corresponding positions. By comparing the image differences between the packaging to be detected and the standard defect-free packaging under the same background, these defects can be accurately located and identified. Compared with directly observing the transparent packaging itself, this method can significantly improve the sensitivity and accuracy of defect detection.
[0105] The enhancement processing of the differential image to obtain the enhanced image includes:
[0106] Calculating the gradient images Gx and Gy of the differential image in the horizontal and vertical directions;
[0107] Within an n×n window around each pixel position (x, y), calculating the sum of squares of horizontal gradients Gxx, the sum of squares of vertical gradients Gyy, and the sum of products of horizontal and vertical gradients Gxy, where n is an integer greater than 3;
[0108] Constructing a 2×2 matrix M, M = [[Gxx, Gxy], [Gxy, Gyy]];
[0109] Solving the characteristic equation of matrix M to obtain two eigenvalues λ1 and λ2;
[0110] According to the magnitude relationship between eigenvalues λ1 and λ2, classifying the image region into regions with a main direction, regions without a main direction, and flat regions;
[0111] Applying different enhancement strategies to different types of regions to generate the enhanced image.
[0112] The applying different enhancement strategies to different types of regions includes:
[0113] Using the eigenvalue λ1 divided by λ2 to obtain the eigenvalue ratio R;
[0114] When the ratio R is greater than a preset threshold T1, determining that the region has an obvious main direction and adopting the following enhancement strategy:
[0115] According to matrix M, obtaining the main direction angle θ using the following formula:
[0116]
[0117] Constructing a one-dimensional Gaussian filter consistent with the main direction angle and applying the filter along the main direction angle to enhance the continuity along the main direction;
[0118] When the ratio R is less than a preset threshold T2 and both λ1 and λ2 are greater than the noise threshold Tn, determining that the region is a region without a main direction and adopting the following enhancement strategy:
[0119] Applying a circular Laplacian operator to enhance the contrast between the central pixel and the surrounding pixels;
[0120] When both λ1 and λ2 are less than the noise threshold Tn, determining that the region is a flat region and adopting the following enhancement strategy:
[0121] Reducing the pixel values within the region by at least 50%.
[0122] In this embodiment, the enhancement process of the differential image can be as follows:
[0123] After obtaining the differential image, it is necessary to enhance it to highlight potential defect features. The enhancement process is based on image local structure analysis, and different enhancement strategies are adopted for different types of regions.
[0124] First, calculate the gradient images of the differential image in the horizontal and vertical directions. The Sobel operator can be used for gradient calculation. The horizontal Sobel operator is used to calculate the horizontal gradient, and the vertical Sobel operator is used to calculate the vertical gradient.
[0125] Next, for each pixel position of the differential image, select the surrounding 7×7 window area and calculate the gradient statistics within this window. Specifically, calculate the sum of the squares of the horizontal gradients, the sum of the squares of the vertical gradients, and the sum of the products of the horizontal and vertical gradients.
[0126] Based on the above statistics, construct a 2×2 structure tensor matrix. This matrix describes the gradient distribution characteristics of the local area.
[0127] Then, solve the characteristic equation of the matrix to obtain two eigenvalues. These eigenvalues reflect the intensity of the gradient change in the local area in different directions.
[0128] According to the magnitude relationship of the eigenvalues, classify the image regions into three types: regions with a main direction, regions without a main direction, and flat regions.
[0129] Apply different enhancement strategies to different types of regions. First, calculate the eigenvalue ratio by dividing the larger eigenvalue by the smaller eigenvalue.
[0130] When the ratio is greater than a preset threshold (which can be set to 4.0), it is determined that the region has an obvious main direction. At this time, use the formula to calculate the main direction angle, then construct a one-dimensional Gaussian filter consistent with the main direction angle (the length can be 11 pixels and the standard deviation can be 1.5), and apply this filter along the main direction angle to enhance the continuity along the main direction. This processing method is beneficial to retaining the continuity of linear defects, such as cracks and scratches.
[0131] When the ratio is less than another preset threshold (which can be set to 2.0) and both eigenvalues are greater than the noise threshold (which can be set to 10.0), it is determined that the region is a region without a main direction. At this time, apply a circular Laplacian operator (the radius can be 3 pixels) to enhance the contrast between the central pixel and the surrounding pixels. This processing method is suitable for enhancing dot-like or block-like defects, such as bubbles and impurities.
[0132] When both eigenvalues are less than the noise threshold, the region is determined to be a flat region, that is, a region without obvious gradient changes. At this time, the pixel values within the region are reduced to 50% of the original to suppress background noise and highlight meaningful defect features.
[0133] For regions that do not belong to the above three cases, the original pixel values can be kept unchanged without special processing. This can avoid overprocessing of regions of uncertain types and retain the original information.
[0134] S5. Perform simple threshold processing on the enhanced image to extract abnormal regions;
[0135] The simple threshold processing of the enhanced image to extract abnormal regions includes:
[0136] Generate a binary image based on the enhanced image according to a preset pixel threshold;
[0137] Perform connected component labeling on the binary image to obtain a set of connected components;
[0138] Filter out connected components with an area smaller than a preset area threshold, and extract the remaining connected components as abnormal regions.
[0139] In this embodiment, the process of extracting abnormal regions from the enhanced image can be as follows:
[0140] After completing the enhancement processing of the difference image, it is necessary to extract potential abnormal regions from the enhanced image for subsequent defect analysis. The extraction process uses a simple and effective threshold processing method.
[0141] First, perform binarization processing on the enhanced image according to a preset pixel threshold. An appropriate threshold can be set (usually set according to the pixel value range of the background image), and the pixels in the enhanced image greater than the threshold are set to 255 (white), and the pixels less than or equal to the threshold are set to 0 (black), thereby generating a binary image.
[0142] Next, perform connected component labeling on the binary image. Scan the binary image, assign a unique label to each connected white pixel region to form a set of connected components. Then, calculate the area of each connected component (that is, the number of pixels within the region) and compare it with a preset area threshold. The area threshold can be set based on empirical values, such as 5 to 10 pixels, to filter out small regions that may be caused by noise. Retain the connected components with an area greater than the preset threshold, and regard these regions as potential abnormal regions.
[0143] Finally, extract these processed connected components as the final abnormal regions, and assign a unique identifier to each abnormal region for subsequent feature analysis and report generation.
[0144] S6. Analyze the characteristics of the abnormal regions, determine the defect positions and defect sizes, and generate a detection result report.
[0145] The step of analyzing the characteristics of the abnormal regions, determining the defect positions and defect sizes, and generating a detection result report includes: calculating the number of pixels in each abnormal region as the defect area, and calculating the centroid coordinates.
[0146] For the centroid coordinates of the abnormal regions, convert them to the surface position coordinates of the beverage package through a preset coordinate mapping function.
[0147] For the pixel size of the abnormal regions, convert it to the surface physical size of the beverage package through a preset size mapping function.
[0148] Generate a detection result report including the surface position coordinates and surface physical size of the beverage package.
[0149] The preset coordinate mapping function is established as follows: establish a three-dimensional model of the beverage package, define a package surface coordinate system on the three-dimensional model of the beverage package, including height, circumferential angle, and radial distance; through pre-calibration, establish a mapping function between the image plane coordinate system and the package surface coordinate system.
[0150] The preset size mapping function is established as follows: place standard size markers in different surface regions of the beverage package, obtain the pixel size of the standard size markers in the image by shooting, and construct a conversion function from the image pixel size to the surface physical size.
[0151] In this embodiment, the process of analyzing the detected abnormal regions and generating a report can be as follows:
[0152] After completing the processing of the enhanced image and extracting the abnormal regions, it is necessary to analyze the characteristics of these abnormal regions, determine the positions and sizes of the defects, and generate a detection result report.
[0153] First, perform basic feature calculations on each abnormal region. Count the number of pixels in the abnormal region and use it as an indication of the defect area. At the same time, calculate the centroid coordinates of the abnormal region as an indication of the defect position. The centroid coordinates can be obtained by calculating the average value of all pixel coordinates in the abnormal region.
[0154] After obtaining the pixel-level features of the abnormal regions, it is necessary to convert these features into the actual physical features on the surface of the beverage package. For the centroid coordinates of the abnormal regions, convert them to the position coordinates on the surface of the beverage package through a preset coordinate mapping function.
[0155] In this embodiment, the coordinate mapping function can be established as follows: First, a three-dimensional model of the beverage packaging is established, such as a cylindrical beverage can or a square paper box. A packaging surface coordinate system is defined on the three-dimensional model, which can include height (distance from the bottom of the packaging), circumferential angle (for cylindrical packaging, representing the angle around the central axis), and radial distance (for cylindrical packaging, representing the distance from the central axis).
[0156] Then, through pre-calibration, the mapping relationship between the image plane coordinate system and the packaging surface coordinate system is established. The calibration process can use a calibration board with marked points. The calibration board is attached to different positions on the packaging surface, and images are taken and the positions of the marked points in the images and the corresponding packaging surface coordinates are recorded. Based on these corresponding relationships, a mapping function can be constructed using polynomial fitting or look-up table methods.
[0157] For the pixel size of the abnormal area, it is converted into the physical size on the beverage packaging surface through a preset size mapping function. The size mapping function can be established as follows: Markers of known sizes, such as 1 cm × 1 cm square marks, are placed in different surface areas of the beverage packaging. The pixel sizes of these markers in the images are obtained through shooting, and the corresponding relationships between the pixel sizes at different positions and the actual physical sizes are established.
[0158] Finally, a detection result report is generated, including the surface position coordinates and surface physical sizes of each defect. The report can be presented in the form of a table, etc., and can optionally include a screenshot of the defect area for subsequent manual review. At the same time, according to the preset defect criteria, it can be automatically determined whether the product is qualified and corresponding processing suggestions are given.
[0159] In this way, the defect detection results at the pixel level can be converted into defect descriptions with actual physical meanings, which is convenient for production management and quality control.
[0160] Embodiment 2
[0161] Please refer to Figure 2 , the present invention provides a visual detection system for beverage packaging defects, which is used to implement a visual detection method for beverage packaging defects, including:
[0162] A standard image library establishment module, which is used to obtain standard images corresponding to different models of beverage packaging by taking pictures of different models of beverage packaging under preset scenarios, and establish a standard image library using all models of beverage packaging and their corresponding standard images; the preset scenarios include lighting conditions, background images, and camera parameters;
[0163] An image acquisition and processing module, which is used to acquire an image of the beverage packaging to be detected under a preset scenario, and perform pre-image processing to obtain a detection image. The image pre-processing includes denoising and illumination equalization;
[0164] A reference image acquisition module, configured to acquire the model of the beverage package to be detected, select the corresponding standard image from the standard image library according to the acquired model, and record it as the reference image;
[0165] An image difference and enhancement module, configured to register the detection image and the reference image according to the features of the background image, perform difference on the registered detection image and the reference image to obtain a difference image, and perform enhancement processing on the difference image to obtain an enhanced image;
[0166] An abnormal area extraction module, configured to perform simple threshold processing on the enhanced image to extract the abnormal area;
[0167] A defect analysis report module, configured to analyze the features of the abnormal area, determine the defect position and the defect size, and generate a detection result report.
[0168] In several embodiments provided by the present invention, it should be understood that the disclosed system, device and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is only one type, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point, the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.
[0169] As mentioned above, it is only the specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, and all should be covered by the protection scope of the present invention.
[0170] Finally: The above is only the preferred embodiment of the present invention and is not used to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A visual inspection method for beverage packaging defects, characterized in that, Including: Obtaining standard images corresponding to different models of beverage packages by photographing different models of beverage packages under a preset scenario, and establishing a standard image library using all models of beverage packages and their corresponding standard images; the preset scenario includes lighting conditions, background images, and camera parameters; Collecting an image of the beverage package to be detected under the preset scenario, and performing pre-image processing to obtain a detection image, where the image pre-processing includes denoising and illumination equalization; Obtaining the model of the beverage package to be detected, selecting the corresponding standard image from the standard image library according to the obtained model, and recording it as a reference image; Registering the detection image and the reference image according to the characteristics of the background image, obtaining a difference image by taking the difference between the registered detection image and the reference image, and performing enhancement processing on the difference image to obtain an enhanced image; Performing simple threshold processing on the enhanced image to extract the abnormal region; Analyzing the characteristics of the abnormal region, determining the defect position and defect size, and generating a detection result report.
2. The visual inspection method for beverage packaging defects according to claim 1, wherein The step of obtaining standard images corresponding to different models of beverage packages by photographing different models of beverage packages under a preset scenario includes: For each model of beverage package: Selecting at least 10 defect-free beverage package samples; Designing a background board containing the preset background image, arranging it according to the preset lighting conditions, and using a camera with predetermined camera parameters to photograph each sample in front of the background board to obtain sample images; Performing image pre-processing on the collected sample images; Taking the average value of the sample images after image pre-processing to generate a standard image corresponding to the beverage package of this model.
3. The visual inspection method for beverage packaging defects according to claim 2, wherein The background image is an image with at least two different colors of stripes alternating; the lighting conditions include light source type, light source position, light intensity, and light source color temperature; the camera parameters include focal length, aperture size, exposure time, and ISO sensitivity.
4. The visual inspection method for beverage packaging defects according to claim 3, wherein, The registering the detection image and the reference image according to the characteristics of the background image includes: Extracting the intersection points of the background stripes in the detection image as the first set of feature points; Extracting the intersection points of the background stripes in the reference image as the second set of feature points; Based on the correspondence between the first set of feature points and the second set of feature points, using a feature point matching algorithm to calculate the spatial transformation matrix from the detection image to the reference image; Using the spatial transformation matrix to apply an affine transformation to the detection image for geometric correction; Adopting the phase correlation method to align the transformed detection image to complete the registration of the detection image and the reference image.
5. A visual inspection method for beverage packaging defects according to claim 1, characterized in that The performing enhancement processing on the difference image to obtain an enhanced image includes: Calculating the gradient images Gx and Gy of the difference image in the horizontal and vertical directions; Within an n×n window around each pixel position (x,y), calculating the sum of squares of the horizontal gradient Gxx, the sum of squares of the vertical gradient Gyy, and the sum of products of the horizontal gradient and the vertical gradient Gxy, where n is an integer greater than 3; Constructing a 2×2 matrix M, M = [[Gxx, Gxy], [Gxy, Gyy]]; Solving the characteristic equation of the matrix M to obtain two eigenvalues λ1 and λ2; Classify the image regions into regions with a main direction, regions without a main direction, and flat regions according to the magnitude relationship between the eigenvalues λ1 and λ2; Apply different enhancement strategies to different types of regions to generate an enhanced image.
6. The visual inspection method for beverage packaging defects according to claim 5, characterized in that, The applying different enhancement strategies to different types of regions includes: Obtain the eigenvalue ratio R by dividing the eigenvalue λ1 by λ2; When the ratio R is greater than a preset threshold T1, determine that the region has an obvious main direction, and adopt the following enhancement strategy: According to the matrix M, obtain the main direction angle θ using the following formula: Construct a one-dimensional Gaussian filter consistent with the main direction angle and apply the filter along the main direction angle to enhance the continuity along the main direction; When the ratio R is less than a preset threshold T2 and both λ1 and λ2 are greater than the noise threshold Tn, determine that the region is a region without a main direction, and adopt the following enhancement strategy: Apply a circular Laplacian operator to enhance the contrast between the central pixel and the surrounding pixels; When both λ1 and λ2 are less than the noise threshold Tn, determine that the region is a flat region, and adopt the following enhancement strategy: Reduce the pixel values in the region by at least 50%.
7. The visual inspection method for beverage packaging defects according to claim 6, characterized in that, The performing simple threshold processing on the enhanced image and extracting abnormal regions includes: Generate a binary image based on the enhanced image according to a preset pixel threshold; Perform connected region labeling on the binary image to obtain a set of connected regions; Filter out the connected regions with an area smaller than a preset area threshold, and extract the remaining connected regions as abnormal regions.
8. The visual inspection method for beverage packaging defects according to claim 7, characterized in that, The analyzing the characteristics of abnormal regions, determining the defect position and defect size, and generating a detection result report includes: calculating the number of pixels in the abnormal region as the defect area for each abnormal region, and calculating the centroid coordinates; For the centroid coordinates of the abnormal region, convert them to the surface position coordinates of the beverage package through a preset coordinate mapping function; For the pixel size of the abnormal region, convert it to the surface physical size of the beverage package through a preset size mapping function; Generate a detection result report including the surface position coordinates and surface physical size of the beverage package.
9. A visual inspection method for beverage package defects according to claim 8, characterized in that The preset coordinate mapping function is established as follows: establish a three-dimensional model of the beverage package, define a package surface coordinate system on the three-dimensional model of the beverage package, including height, circumferential angle, and radial distance; through pre-calibration, establish a mapping function between the image plane coordinate system and the package surface coordinate system; The preset size mapping function is established as follows: place standard size markers in different surface regions of the beverage package, obtain the pixel size of the standard size markers in the image by shooting, and construct a conversion function from the image pixel size to the surface physical size.
10. A visual inspection system for beverage packaging defects, which is used to implement a visual inspection method for beverage packaging defects according to any one of claims 1-9, characterized in that, Including: A standard image library establishment module, which is used to obtain standard images corresponding to different models of beverage packages by shooting different models of beverage packages under preset scenarios, and establish a standard image library using all models of beverage packages and their corresponding standard images; the preset scenarios include lighting conditions, background images, and camera parameters; An image acquisition and processing module, which is used to acquire an image of a beverage package to be detected under a preset scenario, and perform pre-image processing to obtain a detection image. The image pre-processing includes denoising and illumination equalization; A reference image acquisition module, which is used to obtain the model of the beverage package to be detected, select the corresponding standard image from the standard image library according to the obtained model, and record it as the reference image; An image difference and enhancement module, which is used to register the detection image and the reference image according to the characteristics of the background image, perform difference on the registered detection image and the reference image to obtain a difference image, and perform enhancement processing on the difference image to obtain an enhanced image; An abnormal area extraction module, which is used to perform simple threshold processing on the enhanced image to extract the abnormal area; A defect analysis and reporting module, which is used to analyze the characteristics of the abnormal area, determine the defect position and defect size, and generate a detection result report.
Citation Information
Cited By
Chip surface defect detection method, electronic equipment and readable medium
CN121033048A
Image preprocessing method and system for laser lighting imaging
CN121095105A
Image preprocessing method and system for laser light imaging
CN121095105B
Defect detection method and device for image data of integrated circuit AVI equipment
CN121147142A