Method and system for detecting defects of packaging box by using image processing
By combining the method of feature point density analysis and texture feature analysis, the surface defects of the packaging box are detected, and the problems of low detection accuracy and difficulty in dealing with complex geometric deformation in the prior art are solved, achieving more efficient and accurate defect detection.
Patent Information
- Application Number
- CN202411739809.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-21
- Estimated Expiration
- 2044-11-29
AI Technical Summary
When detecting defects on the surface of packaging boxes, it is difficult to take into account the analysis of feature point density and texture characteristics at the same time, resulting in low detection accuracy, especially in poor performance when facing complex geometric deformation.
By acquiring high-resolution images of the packaging box surface, feature points are extracted using the scale-invariant feature transformation algorithm, and feature points match and alignment are combined with the K nearest neighbor algorithm and the image alignment algorithm of deformation tolerance. Then, feature point density analysis and texture feature analysis based on grayscale symbiosis matrix are performed to generate a detection report.
It improves the comprehensiveness and accuracy of surface defect detection of packaging boxes, can quickly identify potential defect areas, and accurately judge the type and severity of defects, improving the quality control efficiency in automated production.
Smart Images

Figure CN119671984A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automated production technology, and in particular to a method and system for detecting packaging box defects by using image processing. Background Art
[0002] With the continuous development of automated production technology, quality inspection methods based on image processing have been widely used in industrial production. Especially for products such as packaging boxes, surface quality inspection has become particularly important. Traditional visual inspection methods usually rely on simple image processing technologies, such as edge detection, area segmentation, etc. Although they can meet basic quality inspection needs, these methods are not accurate enough when facing complex surface defects (such as poor printing, scratches, dents, etc.). In addition, with the improvement of product appearance requirements and production efficiency requirements, traditional methods have great limitations in real-time detection and precise positioning.
[0003] When detecting surface defects on packaging boxes, existing technologies often find it difficult to analyze both feature point density and texture features at the same time. Some technologies are limited to using a single feature matching algorithm, resulting in low accuracy in defect detection. Other detection methods based on texture analysis perform poorly when faced with large deformations, and lack effective image alignment methods, making it difficult to cope with complex geometric deformations on the surface of packaging boxes. Therefore, how to combine feature point matching, density analysis, and multi-dimensional detection of texture features to improve the comprehensiveness and accuracy of detection has become an urgent problem to be solved in existing technologies. Summary of the invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a method for detecting packaging box defects using image processing to solve the problem of how to accurately identify packaging box surface defects and generate a detection report by combining feature point density analysis with texture feature analysis.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0007] In a first aspect, the present invention provides a method for detecting defects in a packaging box using image processing, comprising:
[0008] Obtain high-resolution images of key areas on the packaging box surface and perform preprocessing;
[0009] Using the scale-invariant feature transformation algorithm, feature points are extracted from the preprocessed image to generate a feature descriptor matrix;
[0010] The feature points in the feature descriptor matrix are matched with the feature points of the standard template image by using the K nearest neighbor algorithm, and the matched feature points are aligned by using the deformation tolerant image alignment algorithm;
[0011] Perform feature point density analysis on the aligned packaging box images to identify grid areas where potential defects exist in feature points;
[0012] Based on the identified potential defect areas, the gray-level co-occurrence matrix is used to perform texture feature analysis to further determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect;
[0013] Generate a detection report based on the image feature point density analysis and texture feature analysis results.
[0014] Preferably, the preprocessing includes denoising, grayscale and image enhancement.
[0015] Preferably, using a scale-invariant feature transformation algorithm, extracting feature points from the preprocessed image, and generating a feature descriptor matrix comprises the following steps:
[0016] Perform Gaussian smoothing of different scales on the preprocessed image to generate multiple Gaussian scale spaces, and calculate the difference Gaussian images between adjacent scales;
[0017] In the differential Gaussian image, find the local extreme point of each pixel in its neighborhood as a candidate key point;
[0018] For each candidate key point, the Taylor series expansion of the differential Gaussian image is calculated to locate the sub-pixel position of the key point;
[0019] Analyze the principal curvature and contrast of each key point after positioning to obtain the key point after accurate positioning;
[0020] Based on the key points after accurate positioning, the scale-invariant feature transformation algorithm is used to calculate the gradient amplitude and direction and determine the main direction of the key points;
[0021] Centered on the key point, rotate the gradient direction in the neighborhood to align;
[0022] For the aligned image of each key point neighborhood, divide it into equal sub-regions, and calculate the histogram of the gradient direction in each sub-region;
[0023] The gradient information of each sub-region is combined to form a feature descriptor matrix.
[0024] Preferably, matching the feature points in the feature descriptor matrix with the feature points of the standard template image by using a K-nearest neighbor algorithm, and aligning the matched feature points by using an elastic deformation model comprises the following steps:
[0025] Extracting a feature point descriptor matrix of the packaging box image from the feature descriptor matrix;
[0026] For each feature point descriptor in the packaging box image, the K nearest neighbor algorithm is used to find the two descriptors with the closest Euclidean distance from the descriptor matrix of the standard template image for matching, and a preliminary matching point pair set is generated;
[0027] Randomly select four pairs of points from the set of preliminary matched point pairs and calculate the homography matrix of the set of point pairs;
[0028] Using the calculated homography matrix, each pixel in the packaging box image is perspective transformed to a new position on the template image to obtain a globally aligned packaging box image.
[0029] N control points are selected from the remaining matching points in the preliminary matching point pair set, and the control points are fitted using an elastic deformation model. Local nonlinear deformation adjustment is performed on the globally aligned packaging box image to generate a locally aligned packaging box image.
[0030] Preferably, performing feature point density analysis on the aligned packaging box images to identify grid areas where potential defects exist in feature points includes the following steps:
[0031] Get the aligned packaging box image and the corresponding feature point set;
[0032] Divide the packaging box image into blocks evenly, generate grid areas, and calculate the density of feature points in each grid area;
[0033] Traverse all feature points and determine the grid area to which each feature point belongs;
[0034] According to the changes in the density of feature points, the image is divided into normal areas and abnormal areas, and the grid areas where the feature points have potential defects are identified.
[0035] Preferably, based on the identified potential defective area, the gray level co-occurrence matrix is used to perform texture feature analysis, and further determining whether the change in the surface texture of the packaging box meets the characteristics of the defect includes the following steps:
[0036] According to the result of feature point density analysis, the corresponding abnormal grid area in the packaging box image is extracted;
[0037] For each abnormal grid area, calculate its co-occurrence frequency at different directions and distances, and generate the corresponding gray-level co-occurrence matrix;
[0038] Extract texture features of energy, contrast, entropy and correlation from the gray-level co-occurrence matrix in each direction;
[0039] The texture features in different directions are weighted averaged to generate the final texture features of the abnormal area;
[0040] Extract the corresponding normal area in the packaging box image and obtain the corresponding texture features as the benchmark feature values;
[0041] The final texture features of the generated abnormal area are compared with the baseline feature values to determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect.
[0042] Preferably, generating a detection report according to the results of the feature point density analysis and the texture feature analysis of the image includes the following steps:
[0043] According to different texture characteristics, defects are divided into surface scratches, dents, poor printing and surface damage;
[0044] Based on the classification results of defects, the severity is divided into slight defects, medium defects and severe defects;
[0045] Integrate the time, location, type and severity of defect detection into a complete inspection report.
[0046] In a second aspect, the present invention provides a system for detecting defects in packaging boxes using image processing, comprising:
[0047] Image acquisition module, which acquires high-resolution images of key areas on the surface of the packaging box and performs preprocessing;
[0048] The feature extraction module uses a scale-invariant feature transformation algorithm to extract feature points from the preprocessed image and generate a feature descriptor matrix;
[0049] The feature matching module matches the feature points in the feature descriptor matrix with the feature points of the standard template image through the K-nearest neighbor algorithm, and aligns the matched feature points using the deformation-tolerant image alignment algorithm;
[0050] The density analysis module performs feature point density analysis on the aligned packaging box images and identifies grid areas where potential defects exist in feature points;
[0051] The texture analysis module uses the gray-level co-occurrence matrix to analyze the texture features based on the identified potential defect areas, and further determines whether the changes in the surface texture of the packaging box meet the characteristics of the defect;
[0052] The report generation module generates a detection report based on the image feature point density analysis and texture feature analysis results.
[0053] In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the method for detecting packaging box defects using image processing as described in the first aspect of the present invention is implemented.
[0054] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, any step of the method for detecting packaging box defects using image processing as described in the first aspect of the present invention is implemented.
[0055] The beneficial effects of the present invention are as follows: by extracting feature points on the surface of the packaging box through the SIFT algorithm, and using the K nearest neighbor algorithm to perform feature point matching and elastic deformation alignment, the problem of inconsistent feature points caused by surface deformation of the packaging box is effectively solved; secondly, through feature point density analysis, areas where defects may exist on the surface can be quickly identified, and texture feature analysis is performed based on GLCM, which further improves the detection accuracy of subtle defects, and by weighted averaging texture features, it is ensured that texture features in different directions can be comprehensively considered, thereby improving the comprehensiveness and reliability of defect detection; the test report finally generated can accurately indicate the type and severity of the defect, which is convenient for real-time removal of defective packaging boxes in automated production, thereby improving the quality control efficiency of the production line. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.
[0057] Figure 1 This is a flow chart of the method for detecting packaging box defects using image processing in Example 1.
[0058] Figure 2 Schematic diagram of a system for detecting packaging box defects using image processing in Example 1. DETAILED DESCRIPTION
[0059] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the accompanying drawings.
[0060] Example 1, reference Figure 1 and Figure 2 , which is the first embodiment of the present invention, provides a method for detecting packaging box defects using image processing, comprising the following steps:
[0061] S1. Obtain high-resolution images of key areas on the surface of the packaging box and perform preprocessing.
[0062] S1.1. Preprocessing includes denoising, grayscale and image enhancement.
[0063] Furthermore, Gaussian filtering is used for denoising, which can effectively smooth the image, remove high-frequency noise, and retain the edge details of the image.
[0064] Grayscale processing converts the color value of each pixel into a single brightness value. The grayscale image will reduce color information and retain brightness characteristics.
[0065] Image enhancement refers to histogram equalization, which redistributes the grayscale values of pixels in the image so that pixels of different grayscale levels are evenly distributed, thereby enhancing the contrast of the image. The image after histogram equalization will have a more uniform grayscale distribution, and the image contrast will be significantly improved, ensuring that the details in the image are clearer.
[0066] S2. Use the scale-invariant feature transformation algorithm to extract feature points from the preprocessed image and generate a feature descriptor matrix.
[0067] S2.1. Perform Gaussian smoothing of different scales on the preprocessed image to generate multiple Gaussian scale spaces, and calculate the differential Gaussian images between adjacent scales; in the differential Gaussian images, find the local extreme points of each pixel point in its neighborhood as candidate key points.
[0068] Specifically, the expression of Gaussian smoothing is:
[0069] L(x,y,σ)=G(x,y,σ)*I(x,y);
[0070] Among them, L(x,y,σ) represents the Gaussian smoothing value of the image at position (x,y) and scale σ, G(x,y,σ) represents the Gaussian kernel value of the image at position (x,y) and scale σ, I(x,y) represents the grayscale value or color value of the original image at position (x,y), x and y represent the horizontal and vertical coordinates of the pixel in the image, that is, the position of the image, and σ represents the scale parameter of Gaussian smoothing, that is, the degree of blur of the image.
[0071] The expression for calculating the difference Gaussian image between adjacent scales is:
[0072] D(x,y,σ)=L(x,y,kσ)-L(x,y,σ);
[0073] Where D(x,y,σ) represents the differential Gaussian image value of the image at position (x,y) and scale σ, L(x,y,kσ) represents the Gaussian smoothing value of the image at position (x,y) and scale kσ, and k represents the scale multiple, usually Indicates the scaling factor between adjacent scales.
[0074] S2.2. For each candidate key point, calculate the Taylor series expansion of the differential Gaussian image to locate the sub-pixel position of the key point; analyze the principal curvature and contrast of each located key point to obtain the accurately located key point; based on the accurately located key point, use the scale-invariant feature transformation algorithm to calculate its gradient amplitude and direction to determine the main direction of the key point; with the key point as the center, rotate the gradient direction in the neighborhood for alignment.
[0075] The Taylor series expansion expression of the difference Gaussian image is:
[0076]
[0077] Where D(n) represents the differential Gaussian image value of the displacement vector of the key point, D represents the differential Gaussian image value D(x, y, σ) at the initial key point position, and n represents the displacement vector of the key point, that is, the offset from the initial detected key point position. represents partial derivative and T represents transpose.
[0078] S2.3. After alignment, the image of each key point neighborhood is divided into equal sub-regions, and a histogram of the gradient direction is calculated in each sub-region; the gradient information of each sub-region is combined to form a feature descriptor matrix.
[0079] The expression for the gradient magnitude is:
[0080]
[0081] Among them, m(x,y) represents the gradient amplitude of the image at the position (x,y), L(x+1,y) represents the Gaussian smoothing value of the image at the position (x+1,y), L(x-1,y) represents the Gaussian smoothing value of the image at the position (x-1,y), L(x,y+1) represents the Gaussian smoothing value of the image at the position (x,y+1), and L(x,y-1) represents the Gaussian smoothing value of the image at the position (x,y-1).
[0082] The expression of the gradient direction is:
[0083]
[0084] Among them, β(x,y) represents the gradient direction of the image at position (x,y), the main direction of the point, and tan-1 Represents the inverse tangent function, which is used to calculate angles.
[0085] The specific operations of feature descriptor generation are as follows:
[0086] The pixels around the key point are divided, usually into 4×4 sub-blocks, each sub-block contains a 4×4 pixel neighborhood; in each sub-block, the gradient histograms in 8 directions are counted; finally, the gradient histograms in the 4×4 sub-blocks are combined into a 128-dimensional feature vector (i.e. 4×4×8=128).
[0087] S3. Match the feature points in the feature descriptor matrix with the feature points of the standard template image through the K nearest neighbor algorithm, and align the matched feature points using the elastic deformation model.
[0088] S3.1. Extract the feature point descriptor matrix of the packaging box image from the feature descriptor matrix; for each feature point descriptor in the packaging box image, use the K nearest neighbor algorithm to find the two descriptors with the closest Euclidean distance from the descriptor matrix of the standard template image for matching, and generate a preliminary matching point pair set.
[0089] Specifically, given the descriptor vector f of two feature points i and f j , their Euclidean distance can be expressed as:
[0090]
[0091] Among them, g(f i ,f j ) represents the Euclidean distance between the feature point descriptor in the packaging box image and the feature point descriptor in the standard template image, f i represents the i-th feature point descriptor in the packaging box image, f j represents the j-th feature point descriptor in the standard template image, a represents the dimension index of the descriptor vector, i represents the feature point index in the packaging box image, and j represents the feature point index in the standard template image.
[0092] S3.2. Randomly select four pairs of points from the set of preliminary matched point pairs and calculate the homography matrix of the set of point pairs.
[0093] Specifically, the expression for calculating the homography matrix of this set of point pairs is:
[0094]
[0095] Where A represents the homography matrix, h 11 Indicates controlling the horizontal scaling and rotation of the image, h 12 Indicates the control of image shearing (similar to skewing) and rotation, h13 Indicates the horizontal translation of the image, h 21 Indicates the control of the vertical scaling and rotation of the image, h 22 Indicates the control of image shearing and rotation, h 23 Indicates the vertical translation of the image, h 31 and h 32 Represents the perspective transformation that controls the image.
[0096] S3.3. Use the calculated homography matrix to perform perspective transformation on each pixel in the packaging box image to a new position on the template image to obtain a globally aligned packaging box image; select N control points from the remaining matching points in the preliminary matching point pair set, use the elastic deformation model to fit the control points, perform local nonlinear deformation adjustment on the globally aligned packaging box image, and generate a locally aligned packaging box image.
[0097] S4. Perform feature point density analysis on the aligned packaging box images to identify grid areas where potential defects exist in feature points.
[0098] S4.1. Obtain the aligned packaging box image and the corresponding feature point set; divide the packaging box image into blocks evenly, generate grid areas, and calculate the density of feature points in each grid area.
[0099] Specifically, the specific operations of grid division are as follows:
[0100] Assuming the image size is W×H, we divide it into u×v grids, and the size of each grid area is Δr×Δs:
[0101]
[0102] Among them, Δr represents the horizontal length of the grid, Δs represents the vertical length of the grid, W represents the width of the image, H represents the height of the image, u represents the number of columns of the grid, and v represents the number of rows of the grid.
[0103] The density expression of feature points in each grid area is:
[0104]
[0105] Among them, ρ d,e represents the density of feature points in the grid area of row d and column e, which measures the number of feature points per unit area in the grid area. d,e | represents the total number of feature points in the grid area of the dth row and eth column, d represents the row index of the grid, and e represents the column index of the grid.
[0106] S4.2. Traverse all feature points and determine the grid area to which each feature point belongs; divide the image into normal areas and abnormal areas according to the change in density of feature points, and identify the grid areas where feature points have potential defects.
[0107] Normal area: On the surface of a normal packaging box, the density of feature points should be relatively evenly distributed, and the number of feature points should not be significantly more or less.
[0108] Abnormal area: An area where there may be defects, where the density of feature points will show abnormal changes. For example, the density of feature points may be significantly low (such as in a smooth damaged area), or abnormally high (such as in an area with abnormal texture).
[0109] S5. Based on the identified potential defective areas, a gray-level co-occurrence matrix is used to perform texture feature analysis to further determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect.
[0110] S5.1. According to the result of feature point density analysis, the corresponding abnormal grid area in the packaging box image is extracted; for each abnormal grid area, its co-occurrence frequency in different directions and distances is calculated to generate the corresponding grayscale co-occurrence matrix.
[0111] Specifically, four common directions θ are usually selected to calculate the gray-level co-occurrence matrix:
[0112] θ=0°: adjacent pixels in the horizontal direction.
[0113] θ=45°: adjacent pixels diagonally upward.
[0114] θ=90°: adjacent pixels in the vertical direction.
[0115] θ=135°: adjacent pixels diagonally downward.
[0116] The distance refers to the distance between two pixels, usually 1 (i.e., adjacent pixel pairs).
[0117] The expression of gray level co-occurrence matrix is:
[0118] P θ (b,c)=count(I gray (x1,y1)=b&I gray (x2,y2)=c);
[0119] Among them, P θ (b,c) represents the co-occurrence frequency of pixels with grayscale value b and pixels with grayscale value c in the image with direction θ and adjacent pixel distance 1 as conditions. Count represents the number of times the pixel pairs that meet the conditions appear. I gray(x1, y1) represents the gray value of the image at the position (x1, y1), I gray (x2, y2) represents the gray value of the image at the position (x2, y2), b and c represent two gray values in the gray level co-occurrence matrix, and & represents the logical AND operator, that is, the conditions are met at the same time.
[0120] S5.2. Extract the texture features of energy, contrast, entropy and correlation from the grayscale co-occurrence matrix in each direction; perform weighted averaging on the texture features in different directions to generate the final texture features of the abnormal area; extract the corresponding normal area in the packaging box image to obtain the corresponding texture features as the baseline feature values; compare the generated final texture features of the abnormal area with the baseline feature values to determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect.
[0121] Texture feature comparison criteria:
[0122] Significant increase in contrast: May indicate scratches or cracks in the area.
[0123] Significant reduction in energy: May indicate smooth wear or poor printing in the area.
[0124] A significant increase in entropy may indicate that the area has a chaotic texture and severe surface defects.
[0125] S6. Generate a detection report based on the image feature point density analysis and texture feature analysis results.
[0126] S6.1. According to different texture characteristics, defects are divided into surface scratches, dents, poor printing and surface damage; based on the classification results of defects, the severity is divided into minor defects, medium defects and severe defects; the time, location, type and severity of defect detection are integrated to form a complete test report.
[0127] The present embodiment also provides a system for detecting defects in packaging boxes using image processing, including: an image acquisition module, which acquires high-resolution images of key areas on the surface of the packaging box and performs preprocessing; a feature extraction module, which uses a scale-invariant feature transformation algorithm to extract feature points from the preprocessed image and generates a feature descriptor matrix; a feature matching module, which uses a K-nearest neighbor algorithm to match the feature points in the feature descriptor matrix with the feature points of a standard template image, and uses a deformation-tolerant image alignment algorithm to align the matched feature points; a density analysis module, which performs feature point density analysis on the aligned packaging box image and identifies grid areas where potential defects exist in the feature points; a texture analysis module, which uses a grayscale co-occurrence matrix to perform texture feature analysis based on the identified potential defect areas, and further determines whether the changes in the texture of the packaging box surface meet the characteristics of the defects; and a report generation module, which generates a detection report based on the results of the feature point density analysis and texture feature analysis of the image.
[0128] This embodiment also provides a computer device, which is suitable for the method of using image processing to detect packaging box defects, including: a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute computer executable instructions to implement the method of using image processing to detect packaging box defects as proposed in the above embodiment.
[0129] The computer device may be a terminal, and the computer device includes a processor, a memory, a communication interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device may be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device may be a touch layer covering the display screen, or a key, trackball or touchpad provided on the housing of the computer device, or an external keyboard, touchpad or mouse, etc.
[0130] This embodiment also provides a storage medium on which a computer program is stored. When the program is executed by a processor, the method for detecting packaging box defects by using image processing as proposed in the above embodiment is implemented; the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination of them, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read Only Memory, referred to as EPROM), programmable read-only memory (Programmable Red-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic storage, flash memory, magnetic disk or optical disk.
[0131] In summary, the present invention extracts feature points on the surface of the packaging box through the SIFT algorithm, and uses the K-nearest neighbor algorithm to perform feature point matching and elastic deformation alignment, which effectively solves the problem of inconsistent feature points caused by surface deformation of the packaging box; secondly, through feature point density analysis, it is possible to quickly identify areas where defects may exist on the surface, and perform texture feature analysis based on GLCM, which further improves the detection accuracy of subtle defects, and through weighted averaging of texture features, ensures that texture features in different directions can be comprehensively considered, thereby improving the comprehensiveness and reliability of defect detection; the final generated test report can accurately indicate the type and severity of the defect, which is convenient for real-time removal of defective packaging boxes in automated production, thereby improving the quality control efficiency of the production line.
[0132] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for detecting packaging box defects using image processing, characterized in that: include, Obtain high-resolution images of key areas on the packaging box surface and perform preprocessing; Using the scale-invariant feature transformation algorithm, feature points are extracted from the preprocessed image to generate a feature descriptor matrix; The feature points in the feature descriptor matrix are matched with the feature points of the standard template image by using the K nearest neighbor algorithm, and the matched feature points are aligned by using the deformation tolerant image alignment algorithm; Perform feature point density analysis on the aligned packaging box images to identify grid areas where potential defects exist in feature points; Based on the identified potential defect areas, the gray-level co-occurrence matrix is used to perform texture feature analysis to further determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect; Generate a detection report based on the image feature point density analysis and texture feature analysis results.
2. The method for detecting packaging box defects using image processing according to claim 1, characterized in that: The preprocessing includes denoising, grayscale and image enhancement.
3. The method for detecting packaging box defects by using image processing as claimed in claim 2, characterized in that: Using the scale-invariant feature transformation algorithm, feature points are extracted from the preprocessed image. Generating the feature descriptor matrix includes the following steps: Perform Gaussian smoothing of different scales on the preprocessed image to generate multiple Gaussian scale spaces, and calculate the difference Gaussian images between adjacent scales; In the differential Gaussian image, find the local extreme point of each pixel in its neighborhood as a candidate key point; For each candidate key point, the Taylor series expansion of the differential Gaussian image is calculated to locate the sub-pixel position of the key point; Analyze the principal curvature and contrast of each key point after positioning to obtain the key point after accurate positioning; Based on the key points after accurate positioning, the scale-invariant feature transformation algorithm is used to calculate the gradient amplitude and direction and determine the main direction of the key points; Centered on the key point, rotate the gradient direction in the neighborhood to align; For the aligned image of each key point neighborhood, divide it into equal sub-regions, and calculate the histogram of the gradient direction in each sub-region; The gradient information of each sub-region is combined to form a feature descriptor matrix.
4. The method for detecting packaging box defects by using image processing as claimed in claim 3, characterized in that: The feature points in the feature descriptor matrix are matched with the feature points of the standard template image by the K nearest neighbor algorithm, and the matched feature points are aligned by the elastic deformation model, including the following steps: Extracting a feature point descriptor matrix of the packaging box image from the feature descriptor matrix; For each feature point descriptor in the packaging box image, the K nearest neighbor algorithm is used to find the two descriptors with the closest Euclidean distance from the descriptor matrix of the standard template image for matching, and a preliminary matching point pair set is generated; Randomly select four pairs of points from the set of preliminary matched point pairs and calculate the homography matrix of the set of point pairs; Using the calculated homography matrix, each pixel in the packaging box image is perspective transformed to a new position on the template image to obtain a globally aligned packaging box image. N control points are selected from the remaining matching points in the preliminary matching point pair set, and the control points are fitted using an elastic deformation model. Local nonlinear deformation adjustment is performed on the globally aligned packaging box image to generate a locally aligned packaging box image.
5. The method for detecting packaging box defects by using image processing as claimed in claim 4, characterized in that: Performing feature point density analysis on the aligned packaging box images and identifying grid areas with potential defects in feature points includes the following steps: Get the aligned packaging box image and the corresponding feature point set; Divide the packaging box image into blocks evenly, generate grid areas, and calculate the density of feature points in each grid area; Traverse all feature points and determine the grid area to which each feature point belongs; According to the changes in the density of feature points, the image is divided into normal areas and abnormal areas, and the grid areas where the feature points have potential defects are identified.
6. The method for detecting packaging box defects by using image processing as claimed in claim 5, characterized in that: Based on the identified potential defective areas, the gray level co-occurrence matrix is used to perform texture feature analysis to further determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect. The following steps are included: According to the result of feature point density analysis, the corresponding abnormal grid area in the packaging box image is extracted; For each abnormal grid area, calculate its co-occurrence frequency at different directions and distances, and generate the corresponding gray-level co-occurrence matrix; Extract texture features of energy, contrast, entropy and correlation from the gray-level co-occurrence matrix in each direction; The texture features in different directions are weighted averaged to generate the final texture features of the abnormal area; Extract the corresponding normal area in the packaging box image and obtain the corresponding texture features as the benchmark feature values; The final texture features of the generated abnormal area are compared with the baseline feature values to determine whether the changes in the surface texture of the packaging box meet the characteristics of the defect.
7. The method for detecting packaging box defects by using image processing as claimed in claim 6, characterized in that: According to the results of feature point density analysis and texture feature analysis of the image, generating a test report includes the following steps: According to different texture characteristics, defects are divided into surface scratches, dents, poor printing and surface damage; Based on the classification results of defects, the severity is divided into slight defects, medium defects and severe defects; Integrate the time, location, type and severity of defect detection into a complete inspection report.
8. A system for detecting packaging box defects using image processing, based on the method for detecting packaging box defects using image processing according to any one of claims 1 to 7, characterized in that: include, Image acquisition module, which acquires high-resolution images of key areas on the surface of the packaging box and performs preprocessing; The feature extraction module uses a scale-invariant feature transformation algorithm to extract feature points from the preprocessed image and generate a feature descriptor matrix; The feature matching module matches the feature points in the feature descriptor matrix with the feature points of the standard template image through the K-nearest neighbor algorithm, and aligns the matched feature points using the deformation-tolerant image alignment algorithm; The density analysis module performs feature point density analysis on the aligned packaging box images and identifies grid areas where potential defects exist in feature points; The texture analysis module uses the gray-level co-occurrence matrix to analyze the texture features based on the identified potential defect areas, and further determines whether the changes in the surface texture of the packaging box meet the characteristics of the defect; The report generation module generates a detection report based on the image feature point density analysis and texture feature analysis results.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for detecting packaging box defects using image processing as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for detecting packaging box defects using image processing as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method for detecting defect on surface of bearing by image feature points
CN104680550A
Fluorescent tube surface defect classification method and system based on rotation-invariant texture features
CN106501278A
Label damage detection method based on Bag-of-Word characteristic
CN107180422A
Affine invariant descriptor used for product image searching and fusing multiple perspectives
CN107644227A
Fabric defect detection method and device, computer equipment and readable storage medium
CN114419004A
Cited By
Multi-mode industrial product dynamic defect detection system based on edge calculation
CN120707538A
Multi-modal industrial product dynamic defect detection system based on edge computing
CN120707538B
