A resin product defect detection method and system

By combining the oblique template Sobel operator and gradient descent method with Gibbs energy minimization and covariance matrix fusion, and utilizing a pre-trained random forest model, the inefficiency and error problems caused by manual inspection of resin products are solved, achieving high-precision and efficient automated inspection.

CN120747095BActive Publication Date: 2025-11-07JIANGSU SUQING WATER TREATMENT ENG GROUP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511249796.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-03
Publication Date
2025-11-07
Estimated Expiration
2045-09-03

AI Technical Summary

Technical Problem

Existing defect detection of resin products relies on manual judgment, which is inefficient and prone to subjective errors, resulting in insufficient detection accuracy and affecting product quality.

Method used

Image edge enhancement is performed using the Sobel operator with oblique templates. Gradient descent is combined with RGB features and geometric contour features. Defect type identification is performed using a pre-trained random forest model through Gibbs energy minimization and covariance matrix fusion.

Benefits of technology

It improves the accuracy and reliability of defect detection, and can automatically complete defect detection of various types of resin products, thereby improving production quality and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120747095B_ABST
    Figure CN120747095B_ABST
Patent Text Reader

Abstract

The application provides a resin product defect detection method and system, and relates to the technical field of defect detection. The method comprises the following steps: collecting a to-be-detected image about a resin product; performing image edge enhancement on the to-be-detected image through a Sobel operator with an inclined direction template; extracting the RGB feature of the enhanced to-be-detected image; combining the gradient descent method, taking the Gibbs energy minimization of describing the geometric contour as the target, and extracting the geometric contour feature of the enhanced to-be-detected image; fusing the RGB feature and the geometric contour feature into a covariance matrix; splicing the RGB feature, the geometric contour feature and the covariance matrix to obtain the feature descriptor of the resin product; and inputting the feature descriptor into a pre-trained random forest model with a weighted voting factor to output the defect type of the resin product. In this way, the defect detection efficiency and accuracy of the resin product are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of defect detection, in particular to a resin product defect detection method and system. BACKGROUND

[0002] Resin products are industrial or daily products made of natural or synthetic resin as the main raw material, such as ion exchange resin, epoxy resin products, plastic parts, etc. They have wide application in chemical industry, environmental protection, medicine and other fields. Resin product defects refer to problems caused by process, raw materials or environment during resin product production, such as color difference, uneven size, out-of-tolerance roundness, hollow defects, etc. These will affect product performance and appearance quality.

[0003] Resin product defect detection is a key link to ensure product performance and quality. Defects such as color difference or size deviation will cause the product to fail to meet the use requirements, thereby affecting the equipment operation. Through detection, the production qualified rate can be improved, the rework and scrap cost can be reduced, and the reliability and consistency of the product in the competitive market can be ensured.

[0004] However, the existing resin product defect detection process often relies too much on manual judgment of the appearance defects of resin products, which is low in efficiency and prone to subjective errors, thereby affecting the accuracy of resin product defect detection and the production quality of products. SUMMARY

[0005] In order to solve the technical problems that the existing resin product defect detection process often relies too much on manual judgment of the appearance defects of resin products, which is low in efficiency and prone to subjective errors, thereby affecting the accuracy of resin product defect detection and the production quality of products, the present application provides a resin product defect detection method and system.

[0006] The technical scheme provided by the embodiments of the present application is as follows:

[0007] In a first aspect, the present application provides a resin product defect detection method, which comprises:

[0008] S1: collecting a to-be-detected image of a resin product;

[0009] S2: performing image edge enhancement on the to-be-detected image by using a Sobel operator with a slant direction template;

[0010] S3: extracting the RGB features of the enhanced to-be-detected image;

[0011] S4: combining the gradient descent method, and taking the Gibbs energy minimization of describing the geometric contour as the target, to extract the geometric contour features of the enhanced to-be-detected image;

[0012] S5: fuse the RGB feature and the geometric contour feature into a covariance matrix;

[0013] S6: splice the RGB feature, the geometric contour feature and the covariance matrix to obtain a feature descriptor of the resin product;

[0014] S7: input the feature descriptor into a pre-trained random forest model with a weighted voting factor to output a defect type of the resin product.

[0015] Optionally, S2 specifically comprises:

[0016] S201: extract horizontal direction gradient and vertical direction gradient of the image to be detected through a slant direction template;

[0017] S202: calculate gradient amplitude of different pixel points of the image to be detected according to the horizontal direction gradient and the vertical direction gradient;

[0018] S203: perform image edge enhancement on the image to be detected according to the gradient amplitude.

[0019] Optionally, S3 specifically comprises:

[0020] extract the RGB feature through an OpenCV tool or a Pillow tool.

[0021] Optionally, S4 specifically comprises:

[0022] S401: construct a marker set comprising different geometric line segments;

[0023] S402: establish a Gibbs energy function in inverse proportion to a matching goodness, wherein the Gibbs energy function comprises a consistency term for measuring matching degree of each geometric line segment and a contour line unit and a regularization constraint term for measuring overlapping degree of adjacent geometric line segments, and the matching goodness is a matching goodness between the geometric line segment and the contour line unit in the image to be detected;

[0024] S403: determine an addition acceptance probability of adding a geometric line segment selected from the marker set to the contour line unit by combining a gradient descent method, and add the geometric line segment according to the addition acceptance probability, with the goal of minimizing the Gibbs energy function;

[0025] S404: when the contour line unit has been added with the geometric line segment, arrange the added geometric line segments into a geometric line segment sequence according to adding time;

[0026] S405: output the geometric line segment sequence as the geometric contour feature.

[0027] Optionally, S5 specifically comprises:

[0028] S501: Establish a feature vector set with two dimensions of RGB features and geometric contour features in units of pixels of the image to be detected;

[0029] S502: Establish a covariance matrix based on the feature vector set to complete the fusion of the RGB features and the geometric contour features.

[0030] Optionally, the defect types include color difference defects, color difference uniformity defects, size defects, and size uniformity defects.

[0031] Optionally, the training method of the random forest model specifically includes:

[0032] Obtaining sample images of the resin product with defect category labels;

[0033] Extracting feature descriptors of each sample image;

[0034] Inputting the extracted feature descriptors into the random forest model;

[0035] Inputting the extracted feature descriptors into the random forest model with the defect category labels as supervision information, training the random forest model until the accuracy of the predicted defect category labels output by the random forest model is greater than a preset accuracy;

[0036] Outputting the trained random forest model, i.e., a pre-trained random forest model.

[0037] Optionally, S7 specifically includes:

[0038] S701: Inputting the feature descriptors into the pre-trained random forest model;

[0039] S702: Calculating the similarity between the resin product and the reference feature covariance matrix of each decision tree, and determining a weighted voting factor based on the similarity;

[0040] S703: Determining the defect type of the resin product in combination with the weighted voting factor.

[0041] In a second aspect, an embodiment of the present application provides a resin product defect detection system, which includes:

[0042] A processor;

[0043] A memory, the memory storing computer readable instructions, the computer readable instructions being executed by the processor to implement the resin product defect detection method of the first aspect.

[0044] In a third aspect, an embodiment of the present application provides a computer readable storage medium storing a computer program, the program being executed by a processor to implement the resin product defect detection method of the first aspect.

[0045] The technical scheme provided by the embodiment of the present application has at least the following beneficial effects:

[0046] In the embodiment of the present application, first, the Sobel operator with a slant direction template is used to perform image edge enhancement on the to-be-detected image of the resin product, which can highlight the edge features in the image of the resin product, enhance the contrast of the defect area, and make the subtle color difference, geometric shape anomaly and other features more clear, thereby providing an accurate basis for subsequent feature extraction and defect recognition and effectively improving the detection accuracy and reliability. Then, the RGB features of the to-be-detected image are extracted, and the gradient descent method is combined to minimize the Gibbs energy of the geometric contour as the target, extract the geometric contour features of the enhanced to-be-detected image, accurately and quickly describe the geometric structure of the product, and fuse the two to obtain a covariance matrix, capture the correlation between the features, and comprehensively describe the color and shape features of the resin product. The geometric contour features are optimized by minimizing the Gibbs energy, the fitting accuracy of the complex structure is improved, the features are fused into the covariance matrix, the correlation between the features is captured, the comprehensive detection capability of the model on the color difference and shape anomaly is ensured, and the accuracy and robustness of the defect classification are further improved. Then, the feature descriptor obtained by combining the RGB features, the geometric contour features and the covariance matrix is input into the pre-trained random forest model with a weighted voting factor, and the defect type is output. The model is improved in terms of the accurate classification ability of the defect type and the recognition effect of the complex defect by dynamically adjusting the weight to highlight the decision trees that are better at classification. The defect detection of various types of resin products can be automatically completed, the defect detection efficiency and accuracy are effectively improved, the production quality of the resin product is improved, and the product competitiveness is improved. BRIEF DESCRIPTION OF DRAWINGS

[0047] In order to more clearly illustrate the technical solutions in 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.

[0048] Figure 1 The flowchart of the resin product defect detection method provided by the embodiment of the present application is shown in the figure.

[0049] Figure 2 The structure diagram of the resin product defect detection system provided by the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION

[0050] The technical solutions in the present application will be described below with reference to the drawings.

[0051] In the embodiments of the present application, the words such as "example", "for example", etc. are used to represent an example, illustration, or description. Any embodiment or design scheme described as "example" in the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the word "example" is intended to present the concept in a specific manner. In addition, in the embodiments of the present application, the meaning expressed by "and / or" can be both, or can be one of the two.

[0052] To make the technical problems, technical solutions and advantages to be solved by the present application clearer, the following will be described in detail in conjunction with the drawings and specific embodiments.

[0053] Referring to the drawings accompanying the Figure 1 , a flowchart of a resin product defect detection method provided by an embodiment of the present application is shown.

[0054] An embodiment of the present application provides a resin product defect detection method, which can be realized by a resin product defect detection device, which can be a terminal or a server. The processing flow of the resin product defect detection method can include the following steps:

[0055] S1: Collecting a to-be-detected image about a resin product.

[0056] It can be understood that the to-be-detected image is collected to provide basic data for resin product defect detection.

[0057] S2: Performing image edge enhancement on the to-be-detected image by using a Sobel operator with a slant direction template.

[0058] The Sobel operator is a classical image edge detection operator, which is used to calculate the gradient of an image to highlight edge features. The slant direction template is an extension of the Sobel operator, which is designed for specific directions (such as 67.5 degrees and 112.5 degrees), and highlights the gradient change in a specific slant direction by weighted combination of pixel gray values, so as to extract edge information in a specific direction. This template is more suitable for extracting detailed features of complex images than the standard Sobel operator in horizontal or vertical directions.

[0059] The slant direction template specifically includes a 67.5-degree slant direction template and a 112.5-degree slant direction template :

[0060] .

[0061] It should be noted that the complex image features to be detected can be extracted by the oblique direction template, so that subtle defects such as color difference or geometric anomaly are more obvious, thereby enhancing the defect features and avoiding the insufficient resin product defect detection precision caused by image blur. The enhanced image is helpful to improve the extraction precision of subsequent RGB features and geometric contour features, thereby improving the accuracy and reliability of defect detection.

[0062] In a possible implementation, S2 specifically comprises:

[0063] S201: Extracting horizontal direction gradient and vertical direction gradient of the image to be detected by the oblique direction template.

[0064] The calculation formula of each gradient is specifically as follows:

[0065]

[0066] wherein, and respectively represent the horizontal direction gradient and the vertical direction gradient of the image to be detected, and respectively represent the horizontal and vertical coordinates of the qth pixel point of the image to be detected, represents the gray value of the pixel point.

[0067] S202: Calculating the gradient amplitude of the image to be detected at different pixel points according to the horizontal direction gradient and the vertical direction gradient.

[0068] The calculation formula of the gradient amplitude is specifically as follows:

[0069]

[0070] wherein, represents the gradient amplitude of the pixel point .

[0071] S203: Performing image edge enhancement on the image to be detected according to the gradient amplitude.

[0072] The enhancement formula is specifically as follows:

[0073]

[0074] wherein, respectively represent the pixel value of the image to be detected and the enhanced image to be detected at the pixel point , represents the enhancement coefficient.

[0075] The enhancement coefficient is an adjustable parameter for controlling the intensity of edge enhancement. Optionally, the enhancement coefficient is determined according to the average value of the gradient amplitude of the image to be detected. It is determined that the set can enhance the dynamic adaptation of the coefficient to different images, can dynamically adjust the enhancement effect, so that the high gradient area (such as the edge) is more strongly enhanced, and the low gradient area is less affected, thereby effectively improving the clarity of the edge details while maintaining the balance of the overall brightness and contrast of the image. In this way, while improving the clarity of the edge details, the distortion problem caused by the overall image over-enhancement can be avoided, and the accuracy and reliability of subsequent feature extraction can be ensured.

[0076] S3: Extract the RGB feature of the enhanced to-be-detected image.

[0077] The RGB feature is a color feature of the image. By extracting the RGB feature of the enhanced to-be-detected image, the color distribution and color difference information of the resin product can be accurately reflected, which is helpful for identifying defects caused by uneven color, color difference or brightness difference, and provides a key basis for classifying and detecting color difference defects, thereby improving the comprehensiveness and accuracy of detection.

[0078] In one possible implementation, S3 specifically includes:

[0079] The RGB feature is extracted by using OpenCV or Pillow.

[0080] S4: In combination with the gradient descent method, a geometric contour feature of the enhanced to-be-detected image is extracted by taking the minimization of the Gibbs energy describing the geometric contour as the target.

[0081] The gradient descent method is an optimization algorithm that finds the minimum value of the target function by continuously adjusting the parameters along the direction of the function gradient. The geometric contour refers to the geometric features describing the boundary of an object in an image, including straight lines, curves, and arcs. These contours reflect the shape of the object and are key features for detecting geometric defects (such as size abnormalities and hollows). Gibbs energy is a commonly used energy description in statistical physics and is used in image processing to evaluate the matching degree of a model and target data (such as geometric contours). By minimizing the Gibbs energy, the geometric model that best matches the actual data can be obtained.

[0082] It should be noted that by minimizing the Gibbs energy using the gradient descent method, the enhanced geometric contour feature can accurately and quickly describe the shape and boundary of the resin product, and discover geometric defects such as size abnormalities or insufficient roundness, thereby providing high-precision shape features for subsequent classification and improving the accuracy and robustness of defect detection.

[0083] In one possible implementation, S4 specifically includes:

[0084] S401: A marker set including different geometric line segments is constructed.

[0085] The geometric line segment includes straight lines and arc lines with different lengths, widths and direction angles, i.e., straight lines with different slopes, straight lines with different lengths, straight lines with different widths, straight lines with different lengths at different slopes, straight lines with different widths at different slopes, arc lines with different radian, arc lines with different lengths, arc lines with different widths, arc lines with different lengths at different radian, and arc lines with different thicknesses at different radian. Each geometric line segment in the label set is in the form of a vector.

[0086] S402: Establish a Gibbs energy function in inverse proportion to the matching degree of fit, wherein the Gibbs energy function includes a consistency term measuring the matching degree of fit of each geometric line segment with the contour line unit and a regularization constraint term measuring the overlapping degree of adjacent geometric line segments, and the matching degree of fit is the matching degree of fit between the geometric line segment and the contour line unit in the image to be detected.

[0087] The calculation formula of the Gibbs energy function is specifically:

[0088]

[0089] wherein, G(x) represents the Gibbs energy function about the contour line unit x, and Gconsistency(x) and Gregularization(x) represent the consistency term and the regularization constraint term about x respectively, and Gmean(x) and Gstd(x) represent the mean value and the standard deviation of the internal pixels of the contour line unit respectively, and Gmean(x) and Gstd(x) represent the mean value and the standard deviation of the internal pixels of the contour line unit respectively, and S represents the area of the geometric line segment to be fitted, Goverlap(x) represents the overlapping degree between the i-th contour line unit and the adjacent j-th contour line unit , if not overlapping, the overlapping degree is 0, if fully overlapping, the overlapping degree is 1, Goverlap(x) represents the overlapping degree penalty coefficient, and e represents the natural constant, and Goverlap(t) and Goverlap(t+1) represent the overlapping degree penalty coefficients at the time t and the time t+1 respectively, abs represents taking the absolute value, and max represents taking the maximum value, and Gconsistency(x) and Gregularization(x) represent the gradient values of and , Gupdate represents the update direction.

[0090] The contour line unit is a basic constituent unit after discretization of the contour line in the image to be detected, which is a small geometric segment used to describe local contour features. The contour not only includes the external contour, but also the internal contour which may have a hollow state. Specifically, the contour line unit can be extracted by the Canny algorithm, and then discretized according to the standard geometric line segment (such as a straight line or a curve). Direct discretization can be realized by OpenCV (Open Source Computer Vision Library).

[0091] The overlap degree is defined by the ratio of the intersection area of the geometric line segment to the area of the smaller shape. The overlap penalty coefficient is used to control the degree of negative impact of the overlap. If the overlap is very large, even a small overlap will be significantly penalized. The exponential function amplifies the impact of the overlap, ensuring that the penalty increases exponentially as the overlap increases. In addition, by linking the gradient size of , and , the value of can be adjusted at different optimization stages to make the optimization more stable and efficient. According to the sensitivity of the data consistency term and the regularization term, the value of is dynamically adjusted to ensure that the value of is always within a reasonable range during the optimization process. Avoiding excessive or insufficient values leads to unstable optimization, improving the convergence speed and the quality of the optimization results.

[0092] It should be noted that if the average of the "internal" and "external" pixels of the geometric line segment is very different (such as a bright line segment and a dark background), it indicates that the geometric line segment is more consistent with the image features. On the contrary, if it is very close, it indicates that the closed curve may not be suitable for the geometric line segment. If the pixel values of the "internal" or "external" region fluctuate (standard deviation) greatly, it indicates that the fitting of the geometric line segment is not good enough, and the matching degree will be reduced. The area ensures that the size of the geometric object will not have an unreasonable impact on the matching degree. Through this formula, the model will automatically select the geometric line segment that best matches the image features, such as the position, length, and direction of the line segment that best matches the image data, thereby improving the accuracy of the geometric contour feature extraction of the resin product. Optionally, the neighborhood in the neighborhood pixel mean and the neighborhood pixel standard deviation can be the eight-neighborhood.

[0093] S403: Determine the addition acceptance probability of adding a geometric line segment selected from the label set to the contour line unit according to the gradient descent method, and add the geometric line segment according to the addition acceptance probability.

[0094] The calculation formula of the addition acceptance probability is as follows:

[0095]

[0096] wherein, represents an addition acceptance probability, min represents taking the minimum value, represents a jump probability from a geometric segment to a geometric segment represents a jump probability from a geometric segment to a geometric segment exp represents a natural exponential function, and respectively represent Gibbs energy functions when x selects a geometric segment and a geometric segment T represents an annealing temperature, represents a change amount of x at each iteration, i.e., at different times t, represents a partial derivative, represents an initial annealing temperature, represents an annealing temperature at time t, represents an annealing coefficient, represents a contour line unit x at time t, represents Brownian noise at time t, represents a normal distribution with a mean of 0 and a variance of represents a candidate geometric segment in a label set that is not equal to and represents a scale parameter for controlling a range of a jump probability distribution.

[0097] The addition acceptance probability is used to determine whether to accept a newly selected geometric segment as a part of a matching contour line unit. In the Gibbs energy optimization process, the system attempts to add a new geometric segment in each iteration. Specifically, an addition acceptance probability threshold can be set, and if the threshold is greater, the addition is performed, otherwise the addition is not performed. Alternatively, a random selection is directly performed according to the addition acceptance probability to determine whether to perform the addition, i.e., the random addition adopted in the above scheme, so as to introduce a certain randomness in the optimization process, which is helpful to avoid falling into a local optimal solution.

[0098] It should be noted that this step describes an adjustment manner of the geometric segment in the optimization process. In this process, gradient descent and random disturbance are combined to balance between global search and local optimization. Specifically, the geometric segment and the geometric segment ​​​All belong to the label set. The introduction of random disturbance can increase the global exploration ability. Brown noise can introduce randomness in the optimization process, and the change range of the random increment increases with the increase of the time step. The shorter the time, the smaller the increment. The longer the time, the larger the increment, so that the selected geometric line segment parameters do not move completely in the direction of gradient descent, but there is a certain probability to jump out of the local optimal solution. In addition, the setting of the annealing temperature ensures that the randomness is large in the early stage, and gradually decreases with the decrease of the annealing temperature, and the optimization process gradually transitions from global exploration to local optimization.

[0099] wherein, As continuous adjustment information, it plays a "direction guiding" role in the discrete jump probability, so that the jump process is no longer completely random, but is affected by the current geometric state change trend. If the dynamic adjustment has approached a certain target, the probability of jumping to the target is increased to speed up the convergence. When the scale parameter is large, the jump probability distribution is more smooth, and the system is more inclined to global exploration. When it is small, the jump probability is more concentrated, and the system is more inclined to local optimization.

[0100] Optionally, the annealing coefficient is in the range of The scale parameter that controls the range of the jump probability distribution is in the range of , and the unit is pixel. All line segments involved are in vector form, and the calculation of the jump probability is also in pixel units.

[0101] wherein, The energy function is minimized, the Gibbs energy function, which describes the matching degree between the current geometric line segment and the image contour and the regularization constraint. In the entire optimization process, by selecting the state with the minimum energy, the geometric line segment that best matches the target data is found, ensuring that the optimization result can accurately describe the geometric features of the image. In addition, the distance difference is used to evaluate the jump direction, and the global exploration and local optimization are dynamically balanced. The denominator is normalized to ensure a reasonable probability distribution and avoid single solution bias. Brown noise introduces randomness and enhances the possibility of jumping out of the local optimum. At the same time, the scale parameter flexibly controls the jump range, adapts to different optimization stages, and improves the robustness and convergence effect of the algorithm.

[0102] S404: In the case where all contour line units have added geometric line segments, the added geometric line segments are grouped into a geometric line segment sequence according to the time of addition.

[0103] S405: Output the geometric line segment sequence as a geometric contour feature.

[0104] It should be noted that by constructing a label set containing multiple geometric segments, using Gibbs energy function combined with gradient descent and random disturbance for optimization, a dynamic balance between global exploration and local optimization is achieved, effectively avoiding falling into local optimal solution. By introducing Brownian noise and annealing temperature control, the robustness and adaptability of the algorithm are enhanced, ensuring the best matching of the final geometric segments and image features. At the same time, distance difference and overlap regularization are used to optimize the energy function, making the extracted geometric contour features more accurate and effectively capturing the shape and boundary defects in the image, providing high-quality feature input for the subsequent classification model and improving the accuracy and efficiency of defect detection.

[0105] S5: Fuse the RGB features and geometric contour features into a covariance matrix.

[0106] The covariance matrix is a statistical tool used to describe the relationship between multiple variables. Each element of the matrix represents the covariance between two features, reflecting how they change together. If the covariance is positive, the two variables are positively correlated. For negative, they are negatively correlated. Through the covariance matrix, the correlation between data features can be captured. The covariance matrix can capture the correlation between color and shape features, providing more comprehensive description information for subsequent classification. More accurately reflect the dynamic changes between features, especially in the presence of light changes or complex scenes, and improve the accuracy of defect detection.

[0107] In one possible implementation, S5 specifically includes:

[0108] S501: Establish a feature vector set with two dimensions of RGB features and geometric contour features in units of pixel points of the image to be detected.

[0109] The establishment formula of the feature vector set is specifically:

[0110]

[0111] wherein, represents the feature vector of the kth pixel point with RGB features and geometric contour features, , and n represents the total number of pixel points of the image to be detected.

[0112] S502: Establish a covariance matrix based on the feature vector set to complete the fusion of RGB features and geometric contour features.

[0113] The fusion formula is specifically:

[0114]

[0115] wherein, represents the mean of the feature vector, Covariance matrix representing the image to be detected, the subscript T represents the transpose.

[0116] Specifically, The covariance matrix is a tool to describe the linear correlation between different features. By taking it as input, the relationship information between features can be explicitly passed to the random forest. If there is significant correlation between features, for example, the synergistic change of certain features has a significant influence on the target classification, the covariance matrix can help the model capture these patterns, rather than relying on the individual values of the features. It compensates for the limitations of single feature splitting (feature independent assumption) of random forest, making the model more sensitive to the combined patterns between features. More suitable for classification tasks where the target class depends on the relationship between features (such as time series analysis, image processing and high-dimensional data problems).

[0117] It should be noted that by means of the mean of the feature vector and the covariance relationship between samples, the RGB features and geometric contour features are fully integrated, and the linear correlation and distribution rules between features are captured. The covariance matrix provides rich feature combination information, which can explicitly reflect the synergistic change between features, has a significant influence on the target classification, and improves the classification accuracy and robustness of the model in complex environments.

[0118] S6: The RGB features, geometric contour features and covariance matrix are spliced to obtain the feature descriptor of the resin product.

[0119] Among them, the feature descriptor is a mathematical vector or structured data used to represent the characteristics of the target object. It integrates various feature information (such as color, shape, etc.) to describe the key attributes of the target in the image. The splicing of RGB features, geometric contour features and covariance matrix is to integrate these features into a high-dimensional vector or matrix.

[0120] S7: The feature descriptor is input into a pre-trained random forest model with a weighted voting factor, and the defect type of the resin product is output.

[0121] Among them, the weighted voting factor is a dynamic weight mechanism introduced in the random forest model, used to adjust the voting weight of each decision tree. According to the similarity between the feature descriptor and the reference feature of a certain decision tree, the weight is assigned, and the decision tree with high similarity will get more voting weight, so that the model pays more attention to the decision tree that is good at classifying the current sample. The pre-trained random forest model is a model trained based on the random forest algorithm. Random forest is composed of multiple decision trees, each tree is trained based on a random feature subset, and the result is output by a voting mechanism. In the "pre-training" stage, the model has learned using labeled training data and can identify different defect types.

[0122] It can be understood that by inputting the feature descriptors into the pre-trained random forest model and combining the weighted voting factor, the voting weight is dynamically adjusted according to the classification ability of each decision tree, so that the model can more accurately judge the defect type of the resin product. Compared with the traditional method, this way shows higher classification accuracy and robustness when dealing with complex defects and diversified scenes, and automatically completes defect identification, improves detection efficiency and quality.

[0123] In a possible implementation, the defect types include color difference defects, color difference uniformity defects, size defects, and size uniformity defects.

[0124] It should be noted that if it is an ion exchange resin, the size defects further include roundness defects and hollow defects.

[0125] In a possible implementation, the training manner of the random forest model specifically includes:

[0126] Obtaining sample images with defect category labels about the resin product.

[0127] Extracting feature descriptors of each sample image.

[0128] Inputting the extracted feature descriptors into the random forest model.

[0129] Inputting the extracted feature descriptors into the random forest model with the defect category labels as supervision information, training the random forest model until the accuracy rate of the output predicted defect category labels is greater than a preset accuracy rate.

[0130] It should be noted that the size of the preset accuracy rate can be set according to actual needs by those skilled in the art, and the present application does not limit it.

[0131] Outputting the trained random forest model, i.e., a pre-trained random forest model.

[0132] It should be noted that this process uses sample images with defect category labels to supervise and train the random forest model, comprehensively extracts color, shape and correlation features by using feature descriptors, and improves the classification ability of the model for multiple defect types by combining the multi-decision tree structure of the random forest. At the same time, the training process takes accuracy rate as the target, flexibly adjusts the model parameters, ensures that the classification precision reaches the expectation, and effectively improves the robustness and practical application performance of the model.

[0133] In a possible implementation, S7 specifically includes:

[0134] S701: Inputting the feature descriptors into the pre-trained random forest model.

[0135] S702: Calculate the similarity between the resin product and the reference feature covariance matrix of each decision tree, and determine the weighted voting factor based on the similarity.

[0136] The calculation formula of the weighted voting factor is specifically:

[0137]

[0138] wherein, denotes the weighted voting factor of the vth decision tree, denotes the reference feature covariance matrix of the vth decision tree T v in the pre-trained random forest model, denotes the similarity between and , and ln denotes the natural logarithm function, denotes and the generalized eigenvalue in the dth feature dimension, and D denotes the total feature dimension of the covariance matrix.

[0139] wherein, the generalized eigenvalue is a concept of extended eigenvalue in linear algebra, which describes the relative characteristics between two matrices. Here, it is used to describe the similarity between the input feature covariance matrix and the reference covariance matrix of the decision tree in each feature dimension, and the global matching degree of the two matrices can be comprehensively evaluated through the sum of squares of their logarithms. This way improves the sensitivity and accuracy of similarity calculation.

[0140] It should be noted that the weighted voting factor thus determined adjusts the voting weight of each decision tree by calculating the similarity between the sample and the reference feature covariance matrix of each decision tree, so that the decision tree good at classifying the current sample contributes more to the result, avoiding classification errors caused by fixed weights. At the same time, the sensitivity of similarity calculation is enhanced by using the generalized eigenvalue and the natural logarithm, further improving the accuracy of classification and the adaptability of the model to complex samples.

[0141] Optionally, the calculation method of the reference feature covariance matrix is specifically:

[0142]

[0143] wherein, denotes the covariance matrix of the mth reference feature, i.e., the training image, and M denotes the total number of training images of the decision tree T v .

[0144] It should be noted that this method of calculating the reference feature covariance matrix, by averaging the covariance matrices of the training images, integrates the feature distribution information of all training samples, eliminating the bias that may be introduced by a single sample, and making the reference matrix more representative and robust. This method can effectively reflect the overall correlation between different features, providing a stable and accurate foundation for subsequent similarity calculations and classification, and improving the model's adaptability and classification performance under different sample conditions.

[0145] S703: Determine the defect type of resin product by combining weighted voting factors.

[0146] The specific formula for determining the defect type is as follows:

[0147]

[0148] in, Indicates descriptor The classification result represents the defect type of the resin product, and V represents the total number of decision trees in the pre-trained random forest model. Represents the v-th decision tree pair Predicted defect categories, The indicator function is defined as follows: when the predicted defect category of decision tree v is l, the indicator function takes a value of 1; otherwise, the indicator function takes a value of 0. Indicates taking such that Take the maximum value of l as .

[0149] It's important to note that the weights of each tree are dynamically adjusted based on the features of different images to be detected, avoiding the problem of fixed voting weights for each tree in traditional random forests. By introducing similarity, the predictions of trees that are better at classifying the current sample are given priority, thereby improving the accuracy of defect category identification.

[0150] In practical applications, the process begins with acquiring the image to be inspected, providing foundational data for subsequent analysis. Then, the Sobel operator with a slanted template is used to enhance the image's edges, highlighting edge features and improving defect visibility. Next, RGB features and geometric contour features are extracted from the enhanced image to accurately describe the product's color and geometric shape. These are then fused into a covariance matrix to capture the correlation between color and shape. Furthermore, the RGB features, geometric contour features, and covariance matrix are concatenated into a feature descriptor, forming a comprehensive feature representation. Finally, the feature descriptor is input into a pre-trained random forest model, where weights are dynamically adjusted using weighted voting factors to output the defect type. This method integrates color, shape, and their correlation information, offering advantages such as high detection accuracy, strong robustness, and high classification accuracy, significantly improving detection efficiency and the production quality of resin products.

[0151] The technical scheme provided by the embodiment of the present application has at least the following beneficial effects:

[0152] In the embodiment of the present application, first, the Sobel operator with a slant direction template is used to perform image edge enhancement on the to-be-detected image of the resin product, which can highlight the edge features in the image of the resin product, enhance the contrast of the defect area, make the subtle color difference, geometric shape anomaly and other features more clear, provide an accurate basis for subsequent feature extraction and defect recognition, and effectively improve the detection accuracy and reliability. Then, the RGB features of the to-be-detected image are extracted, and the gradient descent method is combined to minimize the Gibbs energy of the geometric contour as the target, extract the geometric contour features of the enhanced to-be-detected image, accurately and quickly describe the geometric structure of the product, and fuse the two to obtain a covariance matrix, capture the correlation between the features, and comprehensively describe the color and shape features of the resin product. The geometric contour features are optimized by minimizing the Gibbs energy, the fitting accuracy of the complex structure is improved, the features are fused into the covariance matrix, the correlation between the features is captured, the comprehensive detection capability of the model on the color difference and shape anomaly is ensured, and the accuracy and robustness of the defect classification are further improved. Then, the feature descriptor obtained by combining the RGB features, the geometric contour features and the covariance matrix is input into the pre-trained random forest model with a weighted voting factor, and the defect type is output. By dynamically adjusting the weight to highlight the decision trees that are better at classification, the accurate classification ability of the model on the defect type and the recognition effect on complex defects are improved. The defect detection of various types of resin products can be automatically completed, the defect detection efficiency and accuracy are effectively improved, and the production quality of the resin product is improved, and the product competitiveness is improved.

[0153] Reference is made to the accompanying drawings Figure 2 , which shows a structural schematic diagram of a resin product defect detection system provided by the present application.

[0154] The present application also provides a resin product defect detection system 20, which is applied to the resin product defect detection method described above, and comprises:

[0155] The processor 201.

[0156] The memory 202, wherein the memory 202 stores computer readable instructions, and the computer readable instructions are executed by the processor 201 to realize the resin product defect detection method of the method embodiment.

[0157] The resin product defect detection system 20 provided by the present application can execute the resin product defect detection method described above, and realize the same or similar technical effects. To avoid repetition, the present application will not be described again.

[0158] The technical scheme provided by the embodiment of the present application has at least the following beneficial effects:

[0159] In the embodiment of the present application, first, the Sobel operator with a slant direction template is used to perform image edge enhancement on the resin product image to be detected, which can highlight the edge features in the resin product image, enhance the contrast of the defect area, make the subtle color difference, geometric shape anomaly and other features more clear, provide an accurate basis for subsequent feature extraction and defect recognition, and effectively improve the detection accuracy and reliability. Then the RGB features of the image to be detected are extracted, and the gradient descent method is combined to minimize the Gibbs energy of the geometric contour description as the target, extract the geometric contour features of the enhanced image to be detected, accurately and quickly describe the geometric structure of the product, and fuse the two to obtain the covariance matrix, capture the correlation between the features, and comprehensively describe the color and shape features of the resin product. The geometric contour features are optimized by minimizing the Gibbs energy, the fitting accuracy of the complex structure is improved, the features are fused into the covariance matrix, the correlation between the features is captured, the comprehensive detection ability of the model on color difference and shape anomaly is ensured, and the accuracy and robustness of the defect classification are further improved. Then the feature descriptor obtained by combining the RGB features, the geometric contour features and the covariance matrix is input into the pre-trained random forest model with a weighted voting factor, and the defect type is output. By dynamically adjusting the weight to highlight the decision tree that is better at classification, the accurate classification ability of the model on the defect type and the recognition effect on complex defects are improved. The defect detection of various types of resin products can be automatically completed, the defect detection efficiency and accuracy are effectively improved, and the production quality of the resin product is improved, and the product competitiveness is improved.

[0160] It should be understood that the processor in the embodiment of the present application can be a central processing unit (CPU), and the processor can also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor.

[0161] It should also be understood that the memory in the embodiments of the present application can be volatile or nonvolatile memory, or can include both volatile and nonvolatile memory. The nonvolatile memory can be read-only memory (ROM), programmable ROM (PROM), erasable PROM (EPROM), electrically EPROM (EEPROM), or flash memory. The volatile memory can be random access memory (RAM) used as external cache. By way of example, and not limitation, many forms of random access memory (RAM) are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchlink DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0162] The above-described embodiments can be implemented in whole or in part by software, hardware (such as a circuit), firmware, or any combination thereof. When implemented in software, the above-described embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the processes or functions described in the embodiments of the present application are wholly or partially generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transferred from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transferred from one website, computer, server, or data center to another website, computer, server, or data center through a wired (such as infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. containing one or more available medium collections. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state disk.

[0163] It should be understood that the term "and / or" herein merely describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can represent the following three cases: A exists alone, A and B exist together, and B exists alone, where A and B can be singular or plural. In addition, the character " / " herein generally represents that the associated objects before and after it are in an "or" relationship, but it can also represent an "and / or" relationship, which can be understood according to the context before and after it.

[0164] In the present application, "at least one" means one or more, and "multiple" means two or more. "At least one of the following" or the like means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b, or c can represent a, b, c, a-b, a-c, b-c, or a-b-c, where a, b, and c can be single or multiple.

[0165] It should be understood that in various embodiments of the present application, the size of the sequence number of the above-described processes does not mean the order of execution, and the execution order of the processes should be determined according to their functions and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0166] Those skilled in the art can clearly understand that the units and algorithm steps of each example described in combination with the embodiments disclosed herein can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0167] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the devices, apparatuses and units described above can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.

[0168] In several embodiments provided by the present application, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0169] The units described as separate components can or can not be physically separated, and the components shown as units can or can not be physical units, that is, they can be located in one place, or can be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0170] In addition, each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically independently, or two or more units can be integrated into one unit.

[0171] If the functions are realized in the form of software function units and sold or used as independent products, the functions can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the present application that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.

[0172] The embodiment of the present application provides a computer readable storage medium, which stores a computer program. The program is executed by a processor to realize the resin product defect detection method described in the method embodiment.

[0173] The computer readable storage medium provided by the present application can realize the steps and effects of the resin product defect detection method of the method embodiment. To avoid repetition, the present application will not be described again.

[0174] The technical solutions provided by the embodiment of the present application have at least the following beneficial effects:

[0175] In the embodiment of the present application, first, the image edge of the resin product to be detected is enhanced by the Sobel operator with a slant direction template, which can highlight the edge features in the image of the resin product, enhance the contrast of the defect area, make the subtle color difference, geometric shape anomaly and other features more clear, provide an accurate basis for subsequent feature extraction and defect recognition, and effectively improve the detection accuracy and reliability. Then the RGB features of the to-be-detected image are extracted, and the gradient descent method is combined to minimize the Gibbs energy of the geometric contour description, extract the geometric contour features of the enhanced to-be-detected image, accurately and quickly describe the geometric structure of the product, and fuse the two to obtain a covariance matrix, capture the correlation between the features, and comprehensively describe the color and shape features of the resin product. The geometric contour features are optimized by minimizing the Gibbs energy, the fitting accuracy of the complex structure is improved, the features are fused into a covariance matrix, the correlation between the features is captured, the comprehensive detection ability of the model on color difference and shape anomaly is ensured, and the accuracy and robustness of defect classification are further improved. Then the feature descriptor obtained by combining the RGB features, the geometric contour features and the covariance matrix is input into the pre-trained random forest model with a weighted voting factor, and the defect type is output. By dynamically adjusting the weight to highlight the decision trees that are better at classification, the accurate classification ability of the model on the defect type and the recognition effect on complex defects are improved. The defect detection of various types of resin products can be automatically completed, the defect detection efficiency and accuracy are effectively improved, and the production quality of the resin product is improved, and the product competitiveness is improved.

[0176] The above merely illustrates the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which shall be covered within the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

[0177] The following points need to be explained:

[0178] (1) The drawings of the embodiments of the present application only involve the structures involved in the embodiments of the present application, and other structures can refer to the usual design.

[0179] (2) For the sake of clarity, the thickness of the layer or region is magnified or reduced in the drawings used to describe the embodiments of the present application, that is, the drawings are not drawn according to the actual proportion. It can be understood that when an element such as a layer, a film, a region or a substrate is referred to as being located "on" or "under" another element, the element can be "directly" located on or under another element or there can be an intermediate element.

[0180] (3) In the case of no conflict, the embodiments of the present application and the features in the embodiments can be combined with each other to obtain new embodiments.

[0181] The above merely illustrates the specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A resin product defect detection method characterized by, The method comprises: S1: collecting an image to be detected about the resin product; S2: performing image edge enhancement on the image to be detected by a Sobel operator with a slant direction template; S3: extracting an RGB feature of the enhanced image to be detected; S4: combining a gradient descent method to extract a geometric contour feature of the enhanced image to be detected, aiming at minimizing the Gibbs energy of describing the geometric contour; S5: fusing the RGB feature and the geometric contour feature into a covariance matrix; S6: splicing the RGB feature, the geometric contour feature and the covariance matrix to obtain a feature descriptor of the resin product; S7: inputting the feature descriptor into a pre-trained random forest model with a weighted voting factor to output a defect type of the resin product. The S4 specifically comprises: S401: constructing a label set comprising different geometric line segments; S402: establishing a Gibbs energy function in inverse proportion to a matching goodness, wherein the Gibbs energy function comprises a consistency term for measuring the matching degree of each geometric line segment and a contour line unit, and a regularization constraint term for measuring the overlapping degree of adjacent geometric line segments, wherein the matching goodness is the matching goodness between the geometric line segment and the contour line unit in the image to be detected; S403: determining an addition acceptance probability of adding a geometric line segment selected from the label set to the contour line unit by combining a gradient descent method, aiming at minimizing the Gibbs energy function, and adding the geometric line segment according to the addition acceptance probability; S404: when the contour line unit has added the geometric line segment, arranging the added geometric line segments into a geometric line segment sequence according to the time of addition; S405: outputting the geometric line segment sequence as the geometric contour feature.

2. The resin product defect detection method according to claim 1, characterized by, The S2 specifically comprises: S201: extracting a horizontal direction gradient and a vertical direction gradient of the image to be detected by the slant direction template; S202: calculating a gradient amplitude of different pixel points of the image to be detected according to the horizontal direction gradient and the vertical direction gradient; S203: performing image edge enhancement on the image to be detected according to the gradient amplitude.

3. The resin product defect detection method according to claim 1, characterized by, The S3 specifically comprises: extracting the RGB feature by OpenCV tool or Pillow tool.

4. The resin product defect detection method according to claim 1, wherein The S5 specifically comprises: S501: establishing a feature vector set with two dimensions of RGB feature and geometric contour feature in units of pixel points of the image to be detected; S502: establishing the covariance matrix based on the feature vector set to complete the fusion of the RGB feature and the geometric contour feature.

5. The resin product defect detection method according to claim 1, characterized by, The defect type comprises color difference defect, color difference uniformity defect, size defect and size uniformity defect.

6. The resin product defect detection method according to claim 4, characterized by, The training method of the random forest model specifically comprises: obtaining sample images with defect category labels about the resin product; extracting feature descriptors of each sample image; inputting the extracted feature descriptors into the random forest model; The extracted feature descriptor is input into the random forest model with the defect category label as supervision information, and the random forest model is trained until the accuracy of the output predicted defect category label is greater than a preset accuracy; The trained random forest model, i.e., the pre-trained random forest model, is output.

7. The resin product defect detection method according to claim 1, characterized by, The S7 specifically includes: S701: inputting the feature descriptor into the pre-trained random forest model; S702: calculating the similarity between the resin product and the reference feature covariance matrix of each decision tree, and determining the weighted voting factor based on the similarity; S703: determining the defect type of the resin product in combination with the weighted voting factor.

8. A resin product defect detection system characterized by comprising: It includes: a processor; a memory having computer readable instructions stored thereon, the computer readable instructions being executed by the processor to implement the resin product defect detection method of any one of claims 1 to 7.

9. A computer readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the resin product defect detection method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Road vision detection method combined with laser point cloud data

    CN110378196A

  • Defect detection model training method and apparatus, and electronic device

    WO2024169750A1