Plastic tray surface defect detection method
By adaptively calculating the low threshold and high threshold in the grayscale image of the pallet surface, the problem of inaccurate edge line extraction in the prior art is solved, and the accuracy of pallet defect detection is improved.
Patent Information
- Application Number
- CN202510339282.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-04-18
- 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 about the eigenvalue is constructed, a three-peak curve is fitted using Gaussian mixed model to obtain a three-peak curve, and the inflection point between the first and second peaks in the three-peak curve is calculated to obtain a low threshold. At the same time, high thresholds are calculated adaptively and the group intelligence optimization algorithm is used to solve the objective function.
The low threshold and high threshold are obtained according to the grayscale image adaptively, so that the canny algorithm can accurately extract the edge lines of the defect area, and improve the accuracy of the detection results of the tray defect area.
Smart Images

Figure CN119850631A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of pallet detection, and in particular to a method for detecting surface defects of a plastic pallet. Background Art
[0002] Cargo handling is one of the core tasks of warehousing logistics. Due to the differences in size, shape, quality, etc., it is not easy to transport goods in batches. In actual industrial applications, pallets are usually used to transport goods. Pallets are auxiliary devices used as load-bearing surfaces during transportation, handling and storage. During the production process of pallets, the quality of pallets needs to be tested to determine whether there are defects on the surface of the pallets. The types of defects on the surface of pallets mainly include dents, scratches, cracks, etc.
[0003] The Chinese patent application document with publication number CN116823717A discloses a neural network model for defect detection and its training method, system and equipment. 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 technology for detecting scratches or cracks on the surface of a pallet, the edge line of the pallet is usually extracted, and then the image of the pallet is input into a neural network model. The neural network model is used to detect defects in the pallet to determine whether the surface of the pallet has scratches or cracks. The Canny algorithm is usually used in the process of extracting the edge line of the pallet. The Canny edge algorithm extracts the edge line by performing edge detection based on low thresholds and high thresholds.
[0005] The low threshold and high threshold are set manually 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 of the crack area cannot be effectively extracted, resulting in missed detections, resulting in low accuracy of the neural network detection results. Summary of the invention
[0006] In order to solve the problem that the accuracy of the detection result is low due to the low threshold being set too large or too small, the present invention provides a method for detecting surface defects of a plastic pallet.
[0007] The present invention provides a method for detecting surface defects of a plastic pallet, which adopts the following technical solution: 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 as follows: the gradient value and the eigenvalue of each pixel in the grayscale image are calculated, and the eigenvalue is positively correlated with the gradient value; 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.
[0008] The low threshold is adaptively obtained according to the grayscale image, so that the Canny algorithm can accurately extract the edge line of the defective area, avoiding the problem of low accuracy of the extracted edge line due to the low threshold being too large or too small, thereby further improving the accuracy of the detection results of the defective area of the pallet.
[0009] Preferably, the method further comprises calculating the connectivity of the pixels, and the expression of the connectivity is: ; In the formula, is the connectivity of the ith pixel, and b is the number of pixels in the eight-neighborhood of the ith pixel whose gradient value is greater than or equal to that of the pixel.
[0010] Connectivity can be used to understand how closely a pixel is connected to its neighboring pixels.
[0011] Preferably, the expression of the eigenvalue is:
[0012] 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.
[0013] Preferably, the expression of the eigenvalue is:
[0014] 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.
[0015] The above formula can accurately calculate the characteristic value of each pixel, which is convenient for classifying pixels and provides a theoretical basis for calculating high thresholds.
[0016] Preferably, the method further comprises: 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.
[0017] Preferably, 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 connecting 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.
[0018] A high threshold is adaptively obtained according to the grayscale image, so that the Canny algorithm can accurately extract the edge line of the defective area, thereby further improving the accuracy of the detection results of the defective area of the pallet.
[0019] Preferably, the objective function is solved using a swarm intelligence optimization algorithm to obtain the value of H corresponding to the maximum value of the objective function.
[0020] The use of swarm intelligence optimization algorithm can find the global optimal solution and improve the accuracy of high-threshold settlement results.
[0021] Preferably, the Sobel operator is used to calculate the gradient value of each pixel in the image.
[0022] Preferably, before performing edge detection on the grayscale image using the Canny algorithm, a step of performing Gaussian denoising on the grayscale image is also included.
[0023] Preferably, 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.
[0024] The present invention has the following technical effects: 1. The low threshold is adaptively obtained according to the grayscale image, so that the Canny algorithm can accurately extract the edge line of the defective area, avoiding the problem of low accuracy of the extracted edge line due to the low threshold being too large or too small, thereby further improving the accuracy of the detection results of the defective area of the pallet.
[0025] 2. The high threshold is adaptively obtained according to the grayscale image, which solves the problem that the traditional high threshold is set based on experience, which ultimately leads to low accuracy in edge line extraction, thereby further improving the accuracy of edge line extraction and facilitating the detection of defective areas of the pallet. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 The present invention is a flow chart of a method for detecting surface defects of a plastic pallet. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0028] The embodiment of the present invention discloses a method for detecting surface defects of a plastic pallet, referring to Figure 1 , including the following steps: S1: Get a grayscale image of a plastic pallet.
[0029] The industrial camera is placed parallel to the pallet surface and the pallet surface image is captured under uniform lighting conditions to ensure that the image covers the entire pallet surface area. After the pallet surface image is obtained, it is converted into a grayscale image and Gaussian denoising is performed on the grayscale image.
[0030] S2: Calculate the low threshold in the canny algorithm.
[0031] In the Canny algorithm, the pixel points whose low threshold is smaller than the high threshold and whose gradient value is larger than the low threshold and smaller than the high threshold are weak edge points, and the pixel points whose gradient value is larger than the high threshold are strong edge points.
[0032] The calculation method of the low threshold is: S21: Calculate the gradient value and eigenvalue of each pixel in the grayscale image. The eigenvalue is positively correlated with the gradient value.
[0033] 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.
[0034] 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 ith pixel.
[0035] In one embodiment, the expression of the characteristic value is:
[0036] 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. For example, the angle threshold is 15°.
[0037] S22: construct a histogram of eigenvalues, and use a Gaussian mixture model to fit the histogram to obtain a tri-peak curve.
[0038] 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.
[0039] S23: Calculate the inflection point between the first peak and the second peak in the tri-peak curve, and use the average gradient value of the pixel points of the characteristic value corresponding to the inflection point as the low threshold.
[0040] Calculate the second-order derivative of the curve between the first peak and the second peak, and take the data point where the second-order derivative is 0 as the inflection point to obtain the eigenvalue corresponding to the inflection point. In the grayscale image, obtain the pixel point with the same eigenvalue as the inflection point, and take the mean of the gradient values corresponding to the obtained pixel points as the low threshold in the Canny algorithm.
[0041] S3: Calculate the high threshold in the canny algorithm.
[0042] S31: Connect the pixel points whose gradient values are greater than or equal to the low threshold to obtain a connecting line, and take the sum of the characteristic values of each pixel point in the connecting line as the abnormal value of the connecting line: The expression for the outlier is:
[0043] In the formula, is the outlier value of the nth connecting line, is the characteristic value of the i-th pixel in the n-th connecting line, is the number of pixels in the nth connecting line.
[0044] If the connecting line is composed of pixels in an inconspicuous defect area, for example, pixels in a shallow crack area, then the connectivity of the connecting line is strong, the characteristic value of each pixel is large, and the number of pixels that make up this connecting line is large, and accordingly, the outlier value of the connecting line is also large; conversely, if the connecting line is connected by noise points, then the number of pixels in the connecting line is small and the connectivity is not strong, so its outlier value is small. The size of the outlier value can be used to preliminarily understand whether the pixel on the connecting line is a pixel in a defect area or a noise pixel.
[0045] S32: 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.
[0046] For example, for the j-th pixel point in the connecting line, the gradient value of the j-th pixel point is , the gradient value of the pixel point in the 0° direction of the eight neighborhoods of the jth pixel is , then the gradient difference in the 0° direction is: ; Similarly, we get , , , , , , , ,use , , , , , , , Constructing gradient difference sequence .
[0047] S33: Calculate the similarity between the gradient difference sequences of adjacent pixel points in the connecting line, further obtain multiple similarities, and use the average of the multiple similarities as the consistency of the connecting line.
[0048] The Frechet distance algorithm is used to calculate the similarity between the gradient difference sequences of adjacent pixels in the connecting line, so as to obtain the consistency of the connecting line.
[0049] Exemplarily, the gradient difference sequence of the pixels in the connecting line is , , , …, , calculate the gradient difference sequence and Similarities between , calculate the gradient difference sequence and Similarities between , ..., calculate the gradient difference sequence and Similarities between , the similarity , ,……, The mean of is used as the consistency of the connecting line.
[0050] S34: Construct objective function.
[0051] The expression is: ; In the formula, is 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 connecting line outliers that only contain weak edge points.
[0052] The maximum value of the objective function is solved by 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. For example, when the objective function is at the maximum value, the corresponding high threshold H value is 210, and 210 is used as the high threshold in the canny algorithm.
[0053] S4: Use the canny algorithm to perform edge detection on the grayscale image to obtain edge lines for defect detection of plastic pallets.
[0054] The low threshold and high threshold in the Canny algorithm are obtained, and the Canny algorithm is used to perform edge detection on the grayscale image to obtain edge lines, which include the contour lines of the pallet and the contour lines of the defective area, for example, the contour lines of the crack area and the scratch area. The grayscale image containing the edge lines is input into the neural network model, and the pallet is detected to determine whether there are cracks or scratches on the pallet. Among them, the neural network model is a convolutional neural network model, and defect detection using a convolutional neural network model is an existing technology, and the specific process is not repeated here.
[0055] The present invention adaptively obtains a low threshold and a high threshold according to a grayscale image, improves the accuracy of the low threshold and the high threshold, enables the Canny algorithm to accurately extract the edge line of the defective area, avoids the problem of affecting the accuracy of edge line extraction due to excessively large or too small settings of the low threshold and the high threshold, thereby further improving the accuracy of the detection result of the defective area of the pallet.
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 as follows: the gradient value and the eigenvalue of each pixel in the grayscale image are calculated, and the eigenvalue is positively correlated with the gradient value; 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 calculating the connectivity of the pixels, and the expression of the connectivity is: ; In the formula, is the connectivity of the ith pixel, and b is the number of pixels in the eight-neighborhood of the ith pixel whose gradient value is greater than or equal to that of the pixel.
3. A method for detecting surface defects of a plastic pallet according to claim 2, characterized in that: The expression of the eigenvalue 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 ith pixel.
4. A method for detecting surface defects of a plastic pallet according to claim 1, characterized in that: The expression of the eigenvalue is: 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.
5. 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.
6. A method for detecting surface defects of a plastic pallet according to claim 5, 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.
7. A method for detecting surface defects of a plastic pallet according to claim 6, 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.
8. 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.
9. 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.
10. 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
Edge detection method and device based on adaptive gradient threshold canny operator
CN115797300A
Method for detecting surface defects of whole-core flame-retardant conveying belt
CN116012384A
Neural network model for defect detection and training method, system and equipment thereof
CN116823717A
Vision-assisted display screen defect detection method
CN117764989A
Image edge detection method based on Canny algorithm
CN118552746A
Cited By
Peak value calculation method and system
CN122265420A
A peak calculation method and system
CN122265420B