A method and system for detecting defects in a packaging box using image processing

By combining scale-invariant feature transformation and the K-nearest neighbor algorithm in image processing, the accuracy problem of surface defect detection for packaging boxes is solved. This method enables efficient identification of complex surface deformations and detection of minute defects, generates detailed defect reports, and improves the quality control efficiency of the production line.

CN119671984BActive Publication Date: 2025-12-26ZHAOQING JIAWANG PAPER PACKAGING CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411739809.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-12-26
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

Existing technologies struggle to simultaneously analyze both feature point density and texture features when detecting defects on the surface of packaging boxes, resulting in insufficient detection accuracy, especially when dealing with complex surface geometric deformations.

Method used

Feature points are extracted using the scale-invariant feature transform algorithm, and feature point matching and deformation-tolerant image alignment are performed using the K-nearest neighbor algorithm. Texture feature analysis is conducted through feature point density analysis and gray-level co-occurrence matrix, and a detection report is generated.

Benefits of technology

It improves the comprehensiveness and accuracy of surface defect detection for packaging boxes, enabling rapid identification of minor defects and generating detailed reports on defect types and severity, thereby improving the quality control efficiency of the production line.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119671984B_ABST
    Figure CN119671984B_ABST
Patent Text Reader

Abstract

The application discloses a kind of methods and systems for detecting packaging box flaw using image processing, it is related to the field of automated production technology, including, obtain the high-resolution image of packaging box surface key area, and carry out pretreatment;By K nearest neighbor algorithm, the feature points in the feature descriptor matrix Euclidean are matched with the feature points of standard template image, and the matched feature points are aligned using a deformation tolerant image alignment algorithm;The feature point density analysis is carried out to the aligned packaging box image, and the grid area where the feature points exist potential flaw is identified;Based on the identified potential flaw area, texture feature analysis is carried out using gray level co-occurrence matrix, to further judge whether the change of packaging box surface texture conforms to the characteristics of flaw;Through feature point density analysis, the area where surface may exist flaw can be quickly identified, and texture feature analysis is carried out based on GLCM, to further improve the detection accuracy of subtle flaw.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of automation production technology, and particularly relates to a method and system for detecting packaging box flaws by using image processing. BACKGROUND

[0002] With the continuous development of automation production technology, quality detection methods based on image processing have been widely applied in industrial production. Especially for packaging boxes and other products, the detection of surface quality becomes particularly important. Traditional visual detection methods usually rely on simple image processing techniques such as edge detection, region segmentation, etc., which can meet the basic quality detection requirements, but when facing complex surface flaws (such as poor printing, scratches, depressions, etc.), the accuracy of these methods is insufficient. In addition, with the improvement of product appearance requirements and the requirement of production efficiency, the traditional methods have great limitations in real-time detection and accurate positioning.

[0003] The prior art often has difficulty in simultaneously considering the analysis of feature point density and texture features when detecting packaging box surface flaws. Some technologies are limited to using a single feature matching algorithm, resulting in low accuracy of flaw detection. While other detection methods based on texture analysis perform poorly when facing large deformations, and lack effective image alignment means, making it difficult to cope with complex geometric deformations of packaging box surfaces. 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 a problem to be solved by the prior art. SUMMARY

[0004] In view of the above existing problems, the present application is proposed.

[0005] Therefore, the present application provides a method for detecting packaging box flaws by using image processing to solve the problem of how to accurately identify packaging box surface flaws and generate a detection report by combining feature point density analysis and texture feature analysis.

[0006] To solve the above technical problems, the present application provides the following technical solutions:

[0007] In a first aspect, the present application provides a method for detecting packaging box flaws by using image processing, comprising,

[0008] obtaining a high-resolution image of a key area on the surface of the packaging box and pre-processing the image;

[0009] using a scale-invariant feature transform algorithm to extract feature points from the pre-processed image and generate a feature descriptor matrix;

[0010] The feature points in the feature descriptor matrix O are matched with the feature points of the standard template image by a K-neighbor algorithm, and a deformation tolerant image alignment algorithm is used to align the matched feature points.

[0011] The feature point density of the aligned packaging box image is analyzed to identify a grid area where the feature points have potential defects;

[0012] Based on the identified potential defect area, texture feature analysis is performed using a gray level co-occurrence matrix to further determine whether the change in the surface texture of the packaging box conforms to the characteristics of defects;

[0013] According to the results of the feature point density analysis and the texture feature analysis of the image, a detection report is generated.

[0014] Preferably, the preprocessing includes denoising, graying, and image enhancement.

[0015] Preferably, the feature points are extracted from the preprocessed image using a scale-invariant feature transform algorithm, and the generation of the feature descriptor matrix includes the following steps,

[0016] The preprocessed image is subjected to Gaussian smoothing at different scales to generate multiple Gaussian scale spaces, and difference Gaussian images between adjacent scales are calculated;

[0017] In the difference Gaussian image, local extreme points of each pixel point in its neighborhood are found as candidate key points;

[0018] For each candidate key point, the Taylor series expansion of the difference Gaussian image is calculated to locate the sub-pixel position of the key point;

[0019] The principal curvatures and contrast of each located key point are analyzed to obtain the precisely located key points;

[0020] Based on the precisely located key points, the gradient amplitude and direction are calculated using the scale-invariant feature transform algorithm to determine the principal direction of the key points;

[0021] The gradient direction in the neighborhood is rotated around the key point as the center for alignment;

[0022] For the image in the neighborhood of each aligned key point, the image is divided into equal sub-regions, and the histogram of the gradient direction is counted in each sub-region;

[0023] The gradient information of each sub-region is combined to form a feature descriptor matrix.

[0024] Preferably, the feature points in the feature descriptor matrix O are matched with the feature points of the standard template image by a K-neighbor algorithm, and a deformation tolerant image alignment algorithm is used to align the matched feature points includes 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, using K-Nearest Neighbor algorithm, finding two descriptors with the closest Euclidean distance from the descriptor matrix of the standard template image to match, generating a set of preliminary matched point pairs;

[0027] Randomly selecting four point pairs from the set of preliminary matched point pairs, calculating the homography matrix of the group of point pairs;

[0028] Using the calculated homography matrix, performing perspective transformation on each pixel point in the packaging box image to a new position on the template image, obtaining a globally aligned packaging box image;

[0029] Selecting N control points from the remaining matched points of the set of preliminary matched point pairs, fitting the control points using an elastic deformation model, and adjusting the locally nonlinear deformation of the globally aligned packaging box image to generate a locally aligned packaging box image.

[0030] Preferably, the aligned packaging box image is subjected to feature point density analysis to identify grid areas where feature points have potential defects, including the following steps,

[0031] Obtaining the aligned packaging box image and the corresponding feature point set;

[0032] Uniformly dividing the packaging box image into grid areas, and calculating the density of feature points in each grid area;

[0033] Iterating through all feature points, determining the grid area to which each feature point belongs;

[0034] According to the change of feature point density, the image is divided into normal area and abnormal area, and the grid area where the feature points have potential defects is identified.

[0035] Preferably, based on the identified potential defect area, texture feature analysis is performed using a gray level co-occurrence matrix to further determine whether the change of packaging box surface texture conforms to the characteristics of defects, including the following steps,

[0036] According to the feature point density analysis result, extracting the corresponding abnormal grid area in the packaging box image;

[0037] For each abnormal grid area, calculating its co-occurrence frequency in different directions and distances to generate a corresponding gray level co-occurrence matrix;

[0038] Extracting energy, contrast, entropy and correlation texture features from the gray level co-occurrence matrix in each direction;

[0039] The texture features of different directions are weighted and averaged to generate the final texture feature of the abnormal area;

[0040] The corresponding normal area in the packaging box image is extracted to obtain a corresponding texture feature as a reference feature value;

[0041] The generated final texture feature of the abnormal area is compared with the reference feature value to determine whether the change of the packaging box surface texture conforms to the characteristics of the defect.

[0042] Preferably, the detection report is generated according to the feature point density analysis and texture feature analysis results of the image, including the following steps,

[0043] According to different texture feature performances, the defects are classified into surface scratches, depressions, poor printing and surface damage;

[0044] Based on the classification results of the defects, the severity is divided into slight defects, medium defects and serious defects;

[0045] The time, position, type and severity of the defect detection are integrated to form a complete detection report.

[0046] In a second aspect, the present application provides a system for detecting packaging box defects by using image processing, comprising,

[0047] An image acquisition module acquires a high-resolution image of a key area of the packaging box surface and performs preprocessing;

[0048] A feature extraction module uses a scale-invariant feature transform algorithm to extract feature points from the preprocessed image to generate a feature descriptor matrix;

[0049] A feature matching module matches the feature points in the feature descriptor matrix with the feature points of a standard template image by using a K-nearest neighbor algorithm, and aligns the matched feature points by using a deformation tolerant image alignment algorithm;

[0050] A density analysis module performs feature point density analysis on the aligned packaging box image to identify grid areas where potential defects exist in the feature points;

[0051] A texture analysis module performs texture feature analysis using a gray level co-occurrence matrix based on the identified potential defect areas to further determine whether the change of the packaging box surface texture conforms to the characteristics of the defect;

[0052] A report generation module generates a detection report according to the feature point density analysis and texture feature analysis results of the image.

[0053] In a third aspect, the present application provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and wherein the computer program, when executed by the processor, implements any step of the method for detecting defects on a packaging box by image processing according to the first aspect of the present application.

[0054] In a fourth aspect, the present application provides a computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements any step of the method for detecting defects on a packaging box by image processing according to the first aspect of the present application.

[0055] The present application has the following advantages: the SIFT algorithm is used to extract feature points on the surface of the packaging box, and the K-Nearest Neighbor algorithm is used for feature point matching and elastic deformation alignment, effectively solving the inconsistency of feature points caused by the deformation of the packaging box surface; secondly, through feature point density analysis, the area where the surface may have defects can be quickly identified, and texture feature analysis is performed based on GLCM, further improving the detection accuracy of subtle defects, and through weighted average of texture features, it is ensured that texture features in different directions can be considered comprehensively, improving the comprehensiveness and reliability of defect detection; and the final generated detection report can accurately indicate the type and severity of the defect, facilitating the real-time rejection of defective packaging boxes in automated production, and improving the quality control efficiency of the production line. BRIEF DESCRIPTION OF DRAWINGS

[0056] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiment description. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.

[0057] Figure 1 The flowchart of the method for detecting defects on a packaging box by image processing in embodiment 1.

[0058] Figure 2 The schematic diagram of the system for detecting defects on a packaging box by image processing in embodiment 1. DETAILED DESCRIPTION

[0059] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the specific embodiments of the present application will be described in detail below with reference to the drawings of the specification.

[0060] Embodiment 1, refer to Figure 1 and Figure 2 , the first embodiment of the present application provides a method for detecting defects on a packaging box by image processing, comprising the following steps:

[0061] S1, acquire a high-resolution image of the key area on the surface of the packaging box and perform preprocessing.

[0062] S1.1, the preprocessing includes denoising, grayscale processing, and image enhancement.

[0063] Further, the Gaussian filter is used for denoising, which can effectively smooth the image, remove high-frequency noise, and preserve the edge details of the image.

[0064] The grayscale processing is to convert the color value of each pixel to a single luminance value. The image after grayscale processing will reduce color information and preserve luminance features.

[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 uniformly distributed, thereby enhancing the contrast of the image. The image after histogram equalization will have a more uniform grayscale distribution, the image contrast is significantly improved, and the details in the image are clearer.

[0066] S2, use the scale-invariant feature transform 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 difference Gaussian image between adjacent scales. In the difference Gaussian image, find the local extreme points in the neighborhood of each pixel point as candidate key points.

[0068] Specifically, the expression of Gaussian smoothing processing is:

[0069] L(x, y, σ) = G(x, y, σ) * I(x, y);

[0070] where 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 or color value of the original image at position (x, y), x and y represent the coordinates of the pixel in the horizontal and vertical directions of the image, i.e., the position of the image, and σ represents the scale parameter of the Gaussian smoothing, i.e., the degree of blurring 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 difference of 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σ, k represents the scale multiple, usually taken as represents the scale factor between adjacent scales.

[0074] S2.2, for each candidate key point, the Taylor series expansion of the difference of Gaussian image is calculated, and the sub-pixel position of the key point is located; the principal curvature and contrast of each key point after positioning are analyzed, and the key point after accurate positioning is obtained; based on the key point after accurate positioning, the gradient amplitude and direction are calculated using the scale invariant feature transformation algorithm, and the principal direction of the key point is determined; the gradient direction in the neighborhood is aligned by rotating the key point as the center.

[0075] The Taylor series expansion expression of the difference of Gaussian image is:

[0076]

[0077] where D(n) represents the difference of Gaussian image value of the displacement vector of the key point, D represents the difference of Gaussian image value of the difference of Gaussian image value D(x, y, σ) at the initial key point position, n represents the displacement vector of the key point, that is, the offset from the initially detected key point position, represents the partial derivative, and T represents the transpose.

[0078] S2.3, for the image of each key point neighborhood after alignment, it is divided into equal sub-regions, and the histogram of gradient direction is counted in each sub-region; the gradient information of each sub-region is combined to form a feature descriptor matrix.

[0079] The expression of the gradient amplitude is:

[0080]

[0081] where m(x, y) represents the gradient amplitude of the image at position (x, y), L(x+1, y) represents the Gaussian smoothing value of the image at position (x+1, y), L(x-1, y) represents the Gaussian smoothing value of the image at position (x-1, y), L(x, y+1) represents the Gaussian smoothing value of the image at position (x, y+1), and L(x, y-1) represents the Gaussian smoothing value of the image at position (x, y-1).

[0082] The expression of the gradient direction is:

[0083]

[0084] where β(x, y) represents the gradient direction of the image at position (x, y), the principal direction of the point, tan-1 denotes the arctangent function for calculating the angle.

[0085] The specific operation of feature descriptor generation is as follows:

[0086] The pixels around the key points are divided into subblocks, usually 4x4, each containing a 4x4 pixel neighborhood; in each subblock, the gradient histogram of 8 directions is counted; finally, the gradient histograms in 4x4 subblocks are combined into a 128-dimensional feature vector (i.e. 4x4x8=128).

[0087] S3, match the feature points in the feature descriptor matrix E with the feature points of the standard template image by K nearest neighbor algorithm, and align the matched feature points by using 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, find the two descriptors with the closest Euclidean distance from the descriptor matrix of the standard template image to match by using K nearest neighbor algorithm, and generate a preliminary matched point pair set.

[0089] Specifically, given two feature point descriptor vectors f i and f j , their Euclidean distance can be expressed as:

[0090]

[0091] where 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 point pairs from the preliminary matched point pair set, and calculate the homography matrix of the point pair set.

[0093] Specifically, the expression for calculating the homography matrix of the point pair set is:

[0094]

[0095] where A represents the homography matrix, h 11 represents the horizontal scaling and rotation of the control image, h 12 represents the shear (similar to diagonal tension) and rotation of the control image, h13 denotes translation of the image in horizontal direction, h 21 denotes control of vertical scaling and rotation of the image, h 22 denotes control of shearing and rotation of the image, h 23 denotes translation of the image in vertical direction, h 31 and h 32 denotes control of perspective transformation of the image.

[0096] S3.3, using the calculated homography matrix, performing perspective transformation on each pixel point in the packaging box image to a new position on the template image to obtain a globally aligned packaging box image; selecting N control points from the remaining matching points of the preliminary matched point pair set, fitting the control points using an elastic deformation model, and adjusting the globally aligned packaging box image for local nonlinear deformation to generate a locally aligned packaging box image.

[0097] S4, performing feature point density analysis on the aligned packaging box image to identify grid areas where feature points have potential defects.

[0098] S4.1, obtaining the aligned packaging box image and the corresponding feature point set; dividing the packaging box image into uniform blocks to generate grid areas, and calculating the density of feature points in each grid area.

[0099] Specifically, the specific operation of grid division is as follows:

[0100] Assuming the image size is WxH, we divide it into u x v grids, and the size of each grid area is Δr x Δs:

[0101]

[0102] Where Δ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] Where ρ d,e represents the feature point density in the dth row and e th column grid area, which measures the number of feature points per unit area in the grid area, |P d,e | represents the total number of feature points in the dth row and e th column grid area, d represents the row index of the grid, and e represents the column index of the grid.

[0106] S4.2, traverse all feature points, judge the grid area to which each feature point belongs; according to the change of feature point density, divide the image into normal area and abnormal area, and identify the grid area in which the feature points exist potential defects.

[0107] Normal area: on the normal packaging box surface, the feature point density should present relatively uniform distribution, and the number of feature points will not be significantly more or less.

[0108] Abnormal area: the area in which defects may exist, and the feature point density will show abnormal change. For example, the feature point density may be significantly low (such as in the smooth damaged area), or the feature point density is abnormally high (such as in the area with abnormal texture).

[0109] S5, based on the identified potential defect area, texture feature analysis is performed using a gray level co-occurrence matrix to further judge whether the change of the packaging box surface texture conforms to the characteristics of defects.

[0110] S5.1, according to the feature point density analysis result, extract the corresponding abnormal grid area in the packaging box image; for each abnormal grid area, calculate its co-occurrence frequency in different directions and distances, and generate the corresponding gray level co-occurrence matrix.

[0111] Specifically, four commonly used directions θ are usually selected to calculate the gray level co-occurrence matrix:

[0112] θ = 0°: horizontally adjacent pixels.

[0113] θ = 45°: diagonally adjacent pixels.

[0114] θ = 90°: vertically adjacent pixels.

[0115] θ = 135°: diagonally adjacent pixels.

[0116] The distance refers to the distance between two pixels, and 1 (i.e. adjacent pixel pair) is usually selected.

[0117] The expression of the gray level co-occurrence matrix is:

[0118] P θ (b,c) = count(I gray (x1,y1) = b & I gray (x2,y2) = c);

[0119] Wherein, P θ (b,c) represents the co-occurrence frequency of the pixel with gray value b and the pixel with gray value c in the image with the condition of direction θ and adjacent pixel distance 1, count represents the number of times of the occurrence of the pixel pair meeting the condition, I gray(x1,y1) represents the gray value of the image at position (x1,y1), I gray (x2,y2) represents the gray value of the image at position (x2,y2), b and c represent two gray values in the gray co-occurrence matrix, and & represents the logical AND operator, i.e. the condition is met simultaneously.

[0120] S5.2, extract the texture features of energy, contrast, entropy and correlation from the gray co-occurrence matrix of each direction; weight and average the texture features of 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 reference feature value; compare the generated final texture features of the abnormal area with the reference feature value to determine whether the change of the packaging box surface texture meets the characteristics of the defect.

[0121] Texture feature comparison criteria:

[0122] Significant increase in contrast: may indicate that there are scratches or cracks in the area.

[0123] Significant decrease in energy: may indicate that there is a smooth damage or unclear printing in the area.

[0124] Significant increase in entropy: may indicate that the texture of the area is chaotic, and there is a serious surface defect.

[0125] S6, generate a detection report according to the feature point density analysis and texture feature analysis results of the image.

[0126] S6.1, according to the different texture feature performance, the defects are divided into surface scratches, depressions, poor printing and surface damage; based on the classification results of the defects, the severity is divided into slight defects, medium defects and serious defects; the time, position, type and severity of the defect detection are integrated to form a complete detection report.

[0127] The embodiment also provides a system for detecting defects of a packaging box by using image processing, comprising: an image acquisition module, which acquires a high-resolution image of a key area on a surface of the packaging box and performs preprocessing; a feature extraction module, which extracts feature points from the preprocessed image by using a scale-invariant feature transform algorithm and generates a feature descriptor matrix; a feature matching module, which matches the feature points in the feature descriptor matrix with feature points of a standard template image by using a K-nearest neighbor algorithm, and aligns the matched feature points by using a deformation-tolerant image alignment algorithm; a density analysis module, which performs feature point density analysis on the aligned packaging box image, and identifies a grid area in which the feature points have potential defects; a texture analysis module, which performs texture feature analysis on the identified potential defect area by using a gray level co-occurrence matrix, and further determines whether a change in a surface texture of the packaging box conforms to a defect feature; and a report generation module, which generates a detection report according to the feature point density analysis and the texture feature analysis results of the image.

[0128] The embodiment also provides a computer device suitable for the method for detecting defects of a packaging box by using image processing, comprising: a memory and a processor; the memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions to implement the method for detecting defects of a packaging box by using image processing proposed in the above embodiment.

[0129] The computer device can be a terminal, and the computer device comprises a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device comprises 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 running of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to perform wired or wireless communication with external terminals. The wireless communication can be achieved by WIFI, an operator network, NFC (near field communication) or other technologies. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer overlaid on the display screen, or can be a key, a trackball or a touchpad arranged on the shell of the computer device, or can be an external keyboard, a touchpad or a mouse, etc.

[0130] The embodiment also provides a storage medium on which a computer program is stored, the program being executed by a processor to implement the method for detecting flaws of a packaging box by using image processing proposed in the above embodiment; the storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk, or an optical disk.

[0131] To sum up, the application extracts feature points on the surface of the packaging box by using the SIFT algorithm, and performs feature point matching and elastic deformation alignment by using the K nearest neighbor algorithm, effectively solving the inconsistency of feature points caused by the deformation of the surface of the packaging box; secondly, through feature point density analysis, the area where the surface may have flaws can be quickly identified, and texture feature analysis is performed based on GLCM, further improving the detection accuracy of subtle flaws, and through weighted average of the texture features, it is ensured that the texture features in different directions can be considered comprehensively, improving the comprehensiveness and reliability of the flaw detection; finally, the generated detection report can accurately indicate the type and severity of the flaws, facilitating real-time rejection of packaging boxes with flaws in automated production, and 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 application and not to limit the application. Although the application has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the application can be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the application, and all should be covered in the scope of the claims of the application.

Claims

1. A method for detecting defects in packaging boxes using image processing, characterized in that: include, Acquire high-resolution images of key areas on the surface of the packaging box and perform preprocessing; The process of extracting feature points from a preprocessed image and generating a feature descriptor matrix using a scale-invariant feature transform algorithm includes the following steps. The preprocessed image is subjected to Gaussian smoothing at different scales to generate multiple Gaussian scale spaces, and the difference Gaussian image between adjacent scales is calculated. In a difference Gaussian image, find the local extrema of each pixel in its neighborhood as candidate keypoints; For each candidate keypoint, calculate the Taylor series expansion of the difference Gaussian image to locate the sub-pixel position of the keypoint; The principal curvature and contrast of each key point after positioning are analyzed to obtain the key points after precise positioning; Based on the precisely located key points, the scale-invariant feature transformation algorithm is used to calculate the gradient magnitude and direction to determine the main direction of the key points. Align the gradient directions within the neighborhood centered on the keypoint by rotating them. For each aligned keypoint neighborhood image, divide it into equal sub-regions and calculate a histogram of gradient directions in each sub-region; The gradient information of each sub-region is combined to form a feature descriptor matrix; The feature points in the feature descriptor matrix are matched with the feature points of the standard template image using the K-nearest neighbor algorithm, and the matched feature points are aligned using a deformation-tolerant image alignment algorithm. Feature point density analysis was performed on the aligned packaging box image to identify grid areas with potential defects in the feature points; Based on the identified potential defect areas, texture feature analysis is performed using a gray-level co-occurrence matrix to further determine whether the changes in the surface texture of the packaging box conform to the characteristics of a defect. This includes the following steps. Based on the feature point density analysis results, extract the corresponding abnormal grid regions in the packaging box image; For each abnormal grid region, calculate its co-occurrence frequency under 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 from different directions are weighted and averaged to generate the final texture features of the abnormal region. Extract the corresponding normal regions from the packaging box image to obtain the corresponding texture features, which are used as the baseline feature values; The final texture features of the generated abnormal areas are compared with the baseline feature values ​​to determine whether the changes in the surface texture of the packaging box conform to the characteristics of a defect. A detection report is generated based on the results of feature point density analysis and texture feature analysis of the image.

2. The method for detecting defects in packaging boxes using image processing as described in claim 1, characterized in that: The preprocessing includes denoising, grayscale conversion, and image enhancement.

3. The method for detecting defects in packaging boxes using image processing as described in claim 2, characterized in that: The K-nearest neighbor algorithm is used to match feature points in the feature descriptor matrix with feature points in the standard template image, and an elastic deformation model is used to align the matched feature points. The process includes the following steps: 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, 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 and match them to generate a preliminary set of matched point pairs. Randomly select four pairs of points from the initially matched set of 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 initially matched point pair set. The control points are fitted using an elastic deformation model. Local nonlinear deformation adjustment is then applied to the globally aligned packaging box image to generate a locally aligned packaging box image.

4. The method for detecting defects in packaging boxes using image processing as described in claim 3, characterized in that: The steps involved in performing feature point density analysis on the aligned packaging box image to identify grid regions with potential defects in the feature points include: Obtain the aligned image of the packaging box and the corresponding feature point set; The packaging box image is divided into uniform blocks to generate grid regions, and the density of feature points in each grid region is calculated. Iterate through all feature points and determine the grid region to which each feature point belongs; Based on the changes in feature point density, the image is divided into normal and abnormal regions, and grid areas with potential defects in feature points are identified.

5. The method for detecting defects in packaging boxes using image processing as described in claim 4, characterized in that: Generating a detection report based on the image's feature point density analysis and texture feature analysis results includes the following steps: Based on different texture characteristics, defects are classified into surface scratches, dents, printing defects, and surface damage. Based on the classification results of defects, the severity is divided into minor defects, moderate defects, and severe defects; The time, location, type, and severity of defect detection are integrated to form a complete inspection report.

6. A system for detecting defects in packaging boxes using image processing, based on the method for detecting defects in packaging boxes using image processing as described in any one of claims 1 to 5, characterized in that: include, The image acquisition module acquires high-resolution images of key areas on the surface of the packaging box and performs preprocessing. The feature extraction module uses the scale-invariant feature transform algorithm to extract feature points from the preprocessed image and generate a feature descriptor matrix. The feature matching module uses the K-nearest neighbor algorithm to match feature points in the feature descriptor matrix with feature points in the standard template image, and then uses a deformation-tolerant image alignment algorithm to align the matched feature points. The density analysis module performs feature point density analysis on the aligned packaging box image to identify grid areas where feature points have potential defects. The texture analysis module uses gray-level co-occurrence matrix to perform texture feature analysis based on the identified potential defect areas, and further determines whether the changes in the surface texture of the packaging box conform to the characteristics of defects. The report generation module generates a detection report based on the results of feature point density analysis and texture feature analysis of the image.

7. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, it implements the steps of the method for detecting defects in packaging boxes using image processing as described in any one of claims 1 to 5.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the steps of the method for detecting defects in packaging boxes using image processing as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Label damage detection method based on Bag-of-Word characteristic

    CN107180422A

  • Template matching method and system for fabric defect detection

    CN115131332A

  • Surface flaw detection method, system, equipment and terminal

    CN117853765A