A method for detecting surface defects of a plastic pallet
By calculating the gradient value and eigenvalue in the grayscale image of the pallet surface, the low threshold and high threshold in the canny algorithm are adaptively obtained, which solves the problem of inaccurate edge line extraction in the prior art due to improper setting of low thresholds in the prior art, and improves the accuracy of pallet defect detection.
Patent Information
- Application Number
- CN202510339282.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2045-03-21
AI Technical Summary
In the existing pallet surface defect detection technology, too large or too small low threshold setting will lead to inaccurate edge line extraction, affecting the accuracy of neural network detection results.
By calculating the gradient value and eigenvalue of each pixel point in the grayscale image, a histogram of the eigenvalues is constructed and the tri-peak curve is fitted, and the inflection point between the first peak and the second peak in the tri-peak curve is calculated to obtain a low threshold. At the same time, high thresholds are adaptively calculated, and the group intelligence optimization algorithm is used to solve the objective function to improve the accuracy of edge line extraction of the canny algorithm in pallet detection.
The low threshold and high threshold are obtained adaptively, which improves the accuracy of edge line extraction of the canny algorithm in pallet detection and enhances the accuracy of the detection results of the pallet defect area.
Smart Images

Figure CN119850631B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of pallet detection, and particularly to a method for detecting surface defects of plastic pallets. Background Art
[0002] The handling of goods is one of the core tasks in warehousing logistics. Due to differences in the size, shape, quality, etc. of goods, it is not easy to handle them in batches. In actual industrial applications, pallets are usually used to handle goods. A pallet is an auxiliary device that serves as a bearing surface during transportation, handling, and storage. During the production process of pallets, it is necessary to detect the quality of pallets to determine whether there are defects on the pallet surface. The types of defects on the pallet surface mainly include depressions, scratches, cracks, etc.
[0003] The Chinese patent application document with the publication number CN116823717A discloses a neural network model for defect detection, its training method, system, and device. The neural network model includes a segmentation module and a classification module; the segmentation module is used to perform segmentation prediction on the original image, and the classification module is used to classify the image predicted by the segmentation module as defective or normal.
[0004] In the existing technologies for detecting scratches or cracks on the pallet surface, the edge line of the pallet is usually extracted, and then the image of the pallet is input into the neural network model, and the neural network model is used to detect the defects of the pallet, so as to determine whether there are scratches or cracks on the pallet surface. In the process of extracting the edge line of the pallet, the canny algorithm is usually used. The canny edge algorithm performs edge detection based on a low threshold and a high threshold to extract the edge line.
[0005] The low threshold and the high threshold are set artificially according to the actual situation. During the pallet detection process, if the low threshold is set too small, edge lines containing noise will be extracted, affecting the detection results of the neural network. If the low threshold is set too large, the edge lines in the crack area cannot be effectively extracted, resulting in missed detections and low accuracy of the detection results of the neural network. Summary of the Invention
[0006] In order to solve the problem of low accuracy of the detection results caused by setting the low threshold too large or too small, the present invention provides a method for detecting surface defects of plastic pallets.
[0007] The present invention provides a method for detecting surface defects of plastic pallets, adopting the following technical solutions:
[0008] Obtain the grayscale image of the plastic pallet, calculate the low threshold in the canny algorithm, and use the canny algorithm to perform edge detection on the grayscale image to obtain the edge line for defect detection of the plastic pallet;
[0009] Among them, the calculation method of the low threshold is as follows: calculate the gradient value and eigenvalue of each pixel point in the grayscale image, and the eigenvalue is positively correlated with the gradient value;
[0010] Construct a histogram of eigenvalues, and use the Gaussian mixture model to fit the histogram to obtain a three-peak curve; calculate the inflection point between the first peak and the second peak in the three-peak curve, and take the average gradient value of the pixel points corresponding to the inflection point eigenvalue as the low threshold.
[0011] Obtain the low threshold adaptively according to the grayscale image, so that the Canny algorithm can accurately extract the edge line of the defect area, avoiding the problem of low accuracy of the extracted edge line caused by too large or too small low threshold, thereby further improving the accuracy of the detection result of the tray defect area.
[0012] Preferably, the method further includes calculating the connectivity of pixel points, and the expression of connectivity is:
[0013] ;
[0014] In the formula, is the connectivity of the i-th pixel point, and b is the number of pixel points in the eight-neighborhood of the i-th pixel point that are greater than or equal to the gradient value of this pixel point.
[0015] The connectivity can be used to understand the connection tightness between the pixel point and its neighborhood pixel points.
[0016] Preferably, the expression of the eigenvalue is:
[0017]
[0018] In the formula, is the eigenvalue of the i-th pixel point, is the gradient value of the i-th pixel point, is the connectivity of the i-th pixel point.
[0019] Preferably, the expression of the eigenvalue is:
[0020]
[0021] In the formula, is the eigenvalue of the i-th pixel point, is the gradient value of the i-th pixel point, is the number of eight-neighborhood pixel points of the i-th pixel point whose difference in gradient direction from the eight-neighborhood pixel points is less than the angle threshold.
[0022] Through the above formula, the eigenvalue of each pixel point can be accurately calculated, which is convenient for classifying pixel points and provides a theoretical basis for calculating the high threshold.
[0023] Preferably, the method further includes:
[0024] Connect the pixel points with gradient values greater than or equal to the low threshold to obtain a connection line;
[0025] Take the sum of the feature values of each pixel point in the connection line as the outlier of the connection line;
[0026] Calculate the gradient differences between each pixel point in the connection line and the pixel points in its eight-neighborhood to obtain multiple gradient differences, and use the multiple gradient differences to construct the gradient difference sequence of the corresponding pixel points;
[0027] Calculate the similarity between the gradient difference sequences of adjacent pixel points in the connection line to further obtain multiple similarities, and take the mean value of the multiple similarities as the consistency of the connection line.
[0028] Preferably, it further includes calculating the high threshold in the canny algorithm:
[0029] Set the high threshold as H, take the pixel points with gradient values greater than H as strong edge points, and take the pixel points with gradient values greater than the low threshold and less than the high threshold as weak edge points;
[0030] Construct an objective function, and the expression is: ;
[0031] In the formula, represents the objective function with respect to the high threshold H, M is the number of connection lines containing strong edge points, represents the consistency of the m-th connection line containing strong edge points, is the number of pixel points in the m-th connection line containing strong edge points, is the set of outliers of the connection line containing only weak edge points;
[0032] Take the value of H corresponding to the maximum value of the objective function as the high threshold.
[0033] Obtain the high threshold adaptively according to the grayscale image, so that the canny algorithm can accurately extract the edge line of the defect area, thereby further improving the accuracy of the detection result of the tray defect area.
[0034] Preferably, use the swarm intelligence optimization algorithm to solve the objective function to obtain the value of H corresponding to the maximum value of the objective function.
[0035] Using the swarm intelligence optimization algorithm can find the global optimal solution and improve the accuracy of the high threshold calculation result.
[0036] Preferably, use the sobel operator to calculate the gradient value of each pixel point in the image.
[0037] Preferably, before performing edge detection on the grayscale image using the canny algorithm, it further includes the step of performing Gaussian denoising on the grayscale image.
[0038] Preferably, the method for calculating the inflection point between the first peak and the second peak in the three-peak curve is as follows: calculate the second derivative of the curve between the first peak and the second peak, and use the data point where the second derivative is 0 as the inflection point.
[0039] The present invention has the following technical effects:
[0040] 1. An adaptive low threshold is obtained according to the grayscale image, enabling the Canny algorithm to accurately extract the edge line of the defective area, avoiding the problem of low accuracy of the extracted edge line caused by too large or too small low threshold, thereby further improving the accuracy of the detection result of the tray defective area.
[0041] 2. An adaptive high threshold is obtained according to the grayscale image, solving the problem of low accuracy of the extracted edge line caused by setting the high threshold relying on experience in the traditional method, thereby further improving the accuracy of the extracted edge line and facilitating the detection of the tray defective area. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 is a flowchart of a method for detecting surface defects of a plastic tray according to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0043] 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 part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative efforts belong to the scope of protection of the present invention.
[0044] An embodiment of the present invention discloses a method for detecting surface defects of a plastic tray. Referring to Figure 1 , the method includes the following steps:
[0045] S1: Obtain the grayscale image of the plastic tray.
[0046] Align the industrial camera parallel to the tray surface, and take an image of the tray surface under uniform lighting conditions to ensure that the image covers the entire tray surface area. After obtaining the tray surface image, convert it into a grayscale image and perform Gaussian denoising on the grayscale image.
[0047] S2: Calculate the low threshold in the Canny algorithm.
[0048] In the Canny algorithm, the low threshold is less than the high threshold. Pixel points with gradient values greater than the low threshold and less than the high threshold are weak edge points, and pixel points with gradient values greater than the high threshold are strong edge points.
[0049] The calculation method of the low threshold is as follows:
[0050] S21: Calculate the gradient value and eigenvalue of each pixel in the grayscale image. The eigenvalue is positively correlated with the gradient value.
[0051] The Sobel operator is used to calculate the gradient value and gradient direction of each pixel in the grayscale image; the connectivity of the pixel is calculated, and the expression of connectivity is: ; In the formula, is the connectivity of the ith pixel, and b is the number of pixels in the eight neighborhoods of the ith pixel whose gradient value is greater than or equal to that of the pixel. Connectivity indicates the distribution of the gradient values of the neighboring pixels of the corresponding pixel, reflecting the degree of connection between pixel i and its neighboring pixels. The greater the connectivity, the greater the feasibility of the connection between the corresponding pixel and the surrounding pixels. Conversely, the smaller the connectivity, the less feasible the connection between the corresponding pixel and the surrounding pixels.
[0052] In one embodiment, the expression of the characteristic value is: ; In the formula, is the eigenvalue of the i-th pixel, is the gradient value of the i-th pixel, is the connectivity of the i-th pixel.
[0053] In one embodiment, the expression of the characteristic value is:
[0054]
[0055] In the formula, is the eigenvalue of the i-th pixel, is the gradient value of the i-th pixel, is the number of eight-neighborhood pixel points whose gradient direction difference between the i-th pixel point and the eight-neighborhood pixel points is less than the angle threshold. The threshold is artificially set according to actual conditions. Exemplarily, the angle threshold is 15°.
[0056] S22: construct a histogram of eigenvalues, and use a Gaussian mixture model to fit the histogram to obtain a tri-peak curve.
[0057] The histogram reflects the distribution of the eigenvalues of pixels in the grayscale image. Three Gaussian models are used to fit the histogram to obtain a trimodal curve. In the rectangular coordinate system where the trimodal curve is located, the horizontal axis is the eigenvalue and the vertical axis is the number. The trimodal curve has three peaks. The trimodal curve divides the pixels in the grayscale image into three categories according to the eigenvalues. The first category has a large gradient value but poor connectivity, corresponding to the first peak in the trimodal curve; the second category has moderate gradient values and connectivity, corresponding to the second peak in the trimodal curve; the third category has a small gradient value and good connectivity, corresponding to the third peak in the trimodal curve, so the distribution of the eigenvalues of the pixels is a trimodal distribution.
[0058] S23: Calculate the inflection point between the first peak and the second peak in the three-peak curve, and use the average gradient value of the pixel points corresponding to the inflection point eigenvalue as the low threshold.
[0059] Calculate the second derivative of the curve between the first peak and the second peak, and use the data points where the second derivative is 0 as the inflection points, so as to obtain the eigenvalues corresponding to the inflection points. In the grayscale image, obtain the pixel points with the same eigenvalue as the inflection point eigenvalue, and use the average gradient value of the obtained pixel points as the low threshold in the canny algorithm.
[0060] S3: Calculate the high threshold in the canny algorithm.
[0061] S31: Connect the pixel points with gradient values greater than or equal to the low threshold to obtain a connection line, and use the sum of the eigenvalues of each pixel point in the connection line as the outlier value of the connection line:
[0062] The expression for the outlier value is:
[0063]
[0064] In the formula, is the outlier value of the nth connection line, is the eigenvalue of the ith pixel point in the nth connection line, is the number of pixel points in the nth connection line.
[0065] If the connection line is composed of pixel points in an inconspicuous defect area, for example, composed of pixel points in a shallow crack area, then the connectivity of the connection line is strong, so the eigenvalue of each pixel point is large, and the number of pixel points forming this connection line is large. Correspondingly, the outlier value of the connection line is also large; on the contrary, if the connection line is formed by connecting noise points, then the number of pixel points in the connection line is small and the connectivity is not strong, so its outlier value is small. By the size of the outlier value, it can be preliminarily understood whether the pixel points on the connection line are pixel points in the defect area or noise pixel points.
[0066] S32: Calculate the gradient difference between each pixel point in the connection line and the pixel points in its eight-neighborhood to obtain multiple gradient differences, and use the multiple gradient differences to construct the gradient difference sequence of the corresponding pixel points.
[0067] Exemplarily, for the jth pixel point in the connection line, the gradient value of the jth pixel point is , and the gradient value of the pixel point in the 0° direction of the eight-neighborhood of the jth pixel point is , then the gradient difference in the 0° direction is: ; similarly, , , , , , 、 , , using , , , , , , , to construct a gradient difference sequence .
[0068] S33: Calculate the similarity between adjacent pixel point gradient difference sequences in the connection line, and further obtain multiple similarities. Take the mean of the multiple similarities as the consistency of the connection line.
[0069] Use the Frechet distance algorithm to calculate the similarity between adjacent pixel point gradient difference sequences in the connection line, so as to obtain the consistency of the connection line.
[0070] Exemplarily, the gradient difference sequence of the pixel points in the connection line is , , ,…, , calculate the gradient difference sequence and to obtain the similarity , calculate the gradient difference sequence and to obtain the similarity , ……, calculate the gradient difference sequence and to obtain the similarity , and take the mean of the similarities , , ……, as the consistency of the connection line.
[0071] S34: Construct an objective function.
[0072] The expression is: ;
[0073] In the formula, is the objective function with respect to the high threshold H, M is the number of connection lines containing strong edge points, represents the consistency of the m-th connection line containing strong edge points, is the number of pixel points in the m-th connection line containing strong edge points, is the set of outliers of the connection line containing only weak edge points.
[0074] The maximum value of the objective function is solved using a swarm intelligence optimization algorithm, and the value of the high threshold H corresponding to the maximum value of the objective function is used as the high threshold. Exemplarily, when the objective function is at its maximum value, the corresponding value of the high threshold H is 210, and 210 is then used as the high threshold in the canny algorithm.
[0075] S4: Use the canny algorithm to perform edge detection on the grayscale image to obtain an edge line for defect detection of the plastic tray.
[0076] Obtain the low threshold and high threshold in the canny algorithm, use the canny algorithm to perform edge detection on the grayscale image to obtain an edge line, and the edge line includes the contour line of the tray and the contour line of the defect area, such as the contour lines of the crack area and the scratch area. Input the grayscale image containing the edge line into the neural network model to detect the tray to determine whether there are cracks or scratches on the tray. Among them, the neural network model is a convolutional neural network model, and using the convolutional neural network model for defect detection is a prior art, and the specific process will not be elaborated here.
[0077] The present invention adaptively obtains the low threshold and high threshold according to the grayscale image, improves the accuracy of the low threshold and high threshold, enables the canny algorithm to accurately extract the edge line of the defect area, avoids the problem that the accuracy of edge line extraction is affected by setting the low threshold and high threshold too large or too small, and thus further improves the accuracy of the detection result of the defect area of the tray.
Claims
1. A method for detecting surface defects of a plastic pallet, characterized in that: Includes steps: Obtain a grayscale image of a plastic pallet, calculate the low threshold in the Canny algorithm, and use the Canny algorithm to perform edge detection on the grayscale image to obtain edge lines for defect detection of the plastic pallet; The calculation method of the low threshold is: calculate the gradient value and eigenvalue of each pixel in the grayscale image; the expression of the eigenvalue is: or , is the eigenvalue of the i-th pixel, is the gradient value of the i-th pixel, is the connectivity of the ith pixel, is the number of eight-neighborhood pixel points whose gradient direction difference between the i-th pixel point and the eight-neighborhood pixel points is less than the angle threshold; where the expression of connectivity is: , b is the number of pixels in the eight-neighborhood of the i-th pixel whose gradient value is greater than or equal to that of the pixel; A histogram of eigenvalues is constructed, and a Gaussian mixture model is used to fit the histogram to obtain a three-peak curve. The inflection point between the first peak and the second peak in the three-peak curve is calculated, and the mean gradient value of the pixel point corresponding to the eigenvalue of the inflection point is used as the low threshold.
2. A method for detecting surface defects of a plastic pallet according to claim 1, characterized in that: The method also includes: Connect the pixels whose gradient values are greater than or equal to the low threshold to get a connecting line; The sum of the feature values of each pixel in the connecting line is taken as the outlier value of the connecting line; Calculate the gradient difference between each pixel point in the connecting line and the pixel points in the eight neighborhoods to obtain multiple gradient differences, and use the multiple gradient differences to construct a gradient difference sequence of the corresponding pixel points; The similarity between the gradient difference sequences of adjacent pixels in the connecting line is calculated, and multiple similarities are further obtained, and the average of the multiple similarities is taken as the consistency of the connecting line.
3. A method for detecting surface defects of a plastic pallet according to claim 2, characterized in that: It also includes calculating the high threshold in the canny algorithm: Set the high threshold to H, and take the pixels with gradient values greater than H as strong edge points, and take the pixels with gradient values greater than the low threshold and less than the high threshold as weak edge points; Construct the objective function, the expression is: ; In the formula, represents the objective function about the high threshold H, M is the number of connecting lines containing strong edge points, Indicates the consistency of the mth connecting line containing strong edge points, is the number of pixels in the mth connecting line containing strong edge points, is a set of connection line outliers that only contain weak edge points; the value of H corresponding to the maximum value of the objective function is taken as the high threshold.
4. A method for detecting surface defects of a plastic pallet according to claim 3, characterized in that: The swarm intelligence optimization algorithm is used to solve the objective function and obtain the value of H corresponding to the maximum value of the objective function.
5. A method for detecting surface defects of a plastic pallet according to claim 1, characterized in that: The Sobel operator is used to calculate the gradient value of each pixel in the image.
6. A method for detecting surface defects of a plastic pallet according to claim 1, characterized in that: Before using the canny algorithm to perform edge detection on the grayscale image, a step of performing Gaussian denoising on the grayscale image is also included.
7. A method for detecting surface defects of a plastic pallet according to claim 1, characterized in that: The method for calculating the inflection point between the first peak and the second peak in the three-peak curve is: calculating the second-order derivative of the curve between the first peak and the second peak, and taking the data point where the second-order derivative is 0 as the inflection point.
Citation Information
Patent Citations
Neural network model for defect detection and training method, system and equipment thereof
CN116823717A
Edge detection method and device based on adaptive gradient threshold canny operator
CN115797300A
Character segmentation method and apparatus, and computer-readable storage medium
US20230009564A1