Workpiece surface defect image recognition method
By generating force field cloud maps of the contact area and calibrating predicted texture images, and combining support vector machine models and particle swarm optimization algorithms, the problem of high defect misjudgment rate in existing technologies is solved, and accurate identification and type differentiation of workpiece surface defects are achieved.
Patent Information
- Application Number
- CN202511767678.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-28
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2045-11-28
AI Technical Summary
Existing methods for detecting surface defects on workpieces cannot effectively distinguish between normal texture fluctuations during processing and genuine surface defects. They are easily affected by processing deviations such as tool wear and feed rate errors, resulting in a high rate of false defect detection and failing to meet the accuracy requirements of precision machining.
By collecting CNC machining parameters, generating a force field cloud map of the contact area and simulating the tool cutting process, calculating the pixel mean square error for calibration, and constructing a defect type identification model by combining support vector machine, the model parameters are optimized by particle swarm optimization algorithm to achieve accurate identification of potential defect areas.
It significantly improves the accuracy and robustness of defect identification, effectively distinguishes different types of surface defects, and meets the inspection requirements of precision fields such as aerospace and medical devices.
Smart Images

Figure CN121236065B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect recognition engineering, specifically to a method for recognizing surface defects on workpieces. Background Technology
[0002] With the rapid development of intelligent manufacturing and precision machining technologies, the quality of workpiece surfaces has become an important indicator for measuring the stability of processing technology and the reliability of products. Especially in fields such as aerospace, energy equipment, medical devices, optical components, and high-end CNC manufacturing, even minor defects on the workpiece surface can lead to decreased fatigue strength, deterioration of contact performance, or coating failure, thereby directly affecting the safety and service life of the entire machine.
[0003] Existing methods for detecting surface defects on workpieces mostly employ traditional visual algorithms based on edge recognition. These algorithms directly extract edges and analyze features from acquired workpiece surface images, determining the presence of defects by comparing edge morphology, size, and other characteristics. However, these methods rely directly on the acquired images for analysis, lacking a theoretical texture benchmark constructed from CNC machining parameters. They cannot effectively distinguish between normal texture fluctuations during machining and genuine surface defects, making them susceptible to interference from machining deviations such as tool wear and feed rate errors. Ultimately, this results in a high false defect rate, failing to meet the stringent requirements for surface quality inspection accuracy in the precision machining field. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a method for recognizing surface defects on workpieces, which solves the problem of being unable to effectively distinguish between normal texture fluctuations during processing and genuine surface defects.
[0005] To achieve the above objectives, the present invention provides the following technical solution: a method for recognizing surface defects in a workpiece, comprising the following steps:
[0006] Step S1: Collect CNC machining parameters, calculate the CNC machining parameters using the cutting surface morphology theory, generate a contact area force field cloud map, and simulate the tool cutting process using computer graphics tools based on the contact area force field cloud map to generate a predicted texture image;
[0007] Step S2: Collect images of the surface of qualified workpieces, calculate the pixel mean square error between the surface images of qualified workpieces and the predicted texture image, and calibrate the predicted texture image based on the pixel mean square error using the least squares method to obtain a calibrated predicted texture image.
[0008] Step S3: Acquire an image of the surface of the workpiece to be inspected, and compare the image of the surface of the workpiece to be inspected with the calibration predicted texture image to determine potential defect areas;
[0009] Step S4: First, perform feature enhancement on the detected workpiece surface image of the potential defect area to obtain an enhanced potential defect area image; perform feature extraction on the enhanced potential defect area image to obtain a defect feature vector; and perform standardization processing on the defect feature vector to obtain a standardized defect feature vector.
[0010] Step S5: Based on support vector machine, construct a workpiece surface defect type identification model, input the standardized feature vector of the defect into the workpiece surface defect type identification model, output the surface defect type, bind the surface defect type with the coordinates of the potential defect area, and generate surface defect coordinates and type.
[0011] Preferably, the process involves collecting CNC machining parameters, calculating these parameters using cutting surface morphology theory, and generating a force field cloud map of the contact area, including:
[0012] The CNC machining parameters are collected as follows:
[0013] Tool parameters include tool radius, rake angle, and tool type;
[0014] Machining motion parameters include feed rate, spindle speed, and depth of cut;
[0015] For path parameters that include tool trajectory coordinate sequences, the reverse spiral or straight reciprocating path can be extracted by parsing G-code.
[0016] Based on the core assumption of the Oxley model, a theory of cutting surface morphology, that cutting force is linearly related to depth of cut and feed rate, three types of cutting force components are calculated:
[0017] Main cutting force for:
[0018]
[0019] in The unit cutting force is 1 unit. The compatibility between materials and cutting tools is determined by material and tool matching experiments. For depth of cut, the unit is . , The feed per revolution is expressed in mm / rev. This linear relationship model is applicable to finishing conditions of low carbon steel and aluminum alloys with cutting speeds of 50-200 m / min and workpiece material hardness HRC≤35.
[0020] This further enhances resistance. for:
[0021]
[0022] in, This is the feed resistance coefficient;
[0023] Back force for:
[0024]
[0025] in, This is the back force coefficient;
[0026] The calculated , , The force field cloud map of the contact area between the tool and the workpiece is generated by mapping the spatial location to the contact area using Python's Matplotlib library.
[0027] Preferably, the generation of predicted texture images based on the force field cloud map of the contact area and by simulating the tool cutting process using computer graphics tools includes:
[0028] The surf function in MATLAB, a computer graphics tool, is used to simulate the cutting process of a cutting tool. The details of the steps are as follows:
[0029] Tool scanning generation is based on the workpiece CAD model and the spatial coordinate sequence of the tool center point. ,in Given the total number of tool trajectory points, the tool scanning surface is generated using the trajectory stretching method;
[0030] For turning, the tool position at each time point is stretched along the helical trajectory to form a continuous helical surface. The normal vector of the surface is determined by the helical tangent direction and the radial direction of the workpiece.
[0031] For milling, the tool position is stretched along the straight feed direction to form a parallel stripe surface;
[0032] The contact area force field cloud map generated by micro-texturing is imported, and the vertex height of the scanned surface is perturbed according to the positive correlation between cutting force and surface roughness.
[0033] Extract the cutting force at each location in the force field contour map. Calculate the roughness increment at that location:
[0034]
[0035] in, It is a rough increment. The coefficients determined by the experiment, ;
[0036] By adding random Perlin noise, and adding [something] to the vertices of the scanned face, [something] is added. Matching height fluctuations to simulate microscopic textures;
[0037] The lighting model and output are as follows:
[0038] Set the equipment lighting parameters as follows: use a ring-shaped LED light source, position the light source at 45° around the workpiece, light intensity of 5000 lux, and light source color of cool white.
[0039] The brightness I of each pixel is calculated using the Phong lighting model, with the following formula:
[0040] I=
[0041] in, This represents the ambient light reflectance, with a value of 0.2. It is the diffuse reflectance coefficient, with a value of 0.7; represents the specular reflection coefficient, with a value of 0.3; N is the specular index, set to 20; It is the surface normal vector; The direction vector of the light source; The reflection direction vector; To observe the direction vector; For ambient light intensity, The intensity of diffuse reflected light. This represents the intensity of the specular reflected light, and its value is set according to the actual light source parameters.
[0042] The final output is an 8-bit texture prediction image:
[0043] The resolution is 4096×3072 pixels, the pixel physical size is 3μm, the image format is BMP, and the dominant texture direction is guaranteed. ,cycle The features are clearly discernible at the pixel level.
[0044] Preferably, collecting images of qualified workpiece surfaces and calculating the pixel mean square error between the qualified workpiece surface images and the predicted texture images includes:
[0045] The process of collecting images of qualified workpiece surfaces is as follows:
[0046] The camera has a resolution of 4096x2160 pixels, a global shutter, and motion blur of <1%; the light source is a high-uniformity LED ring light source with a color temperature of 5500K and illumination uniformity of >90%; the lens is a telecentric lens with a working distance of 100mm, a maximum magnification of 1x, and distortion of <0.1%.
[0047] For 3-5 defect-free workpieces confirmed by quality inspection, 3 typical processing areas are collected for each workpiece, and a total of 9-15 qualified surface images are obtained, covering the texture changes throughout the entire processing process;
[0048] For each preprocessed normal image, the mean square error (MSE) is calculated pixel-by-pixel with the predicted texture image generated in step S1, using the following formula:
[0049]
[0050] Where M and N are the image height and width, The predicted texture grayscale value in step S1, The grayscale values are the normal image values; the mean value is obtained by calculating the mean value of the MSE of all normal images. and standard deviation The formula uses i and j as the calibration reference; i and j are the coordinate indices of the pixel; i represents the row index of the pixel in the image, ranging from 1 to M; j represents the column index of the pixel in the image, ranging from 1 to N.
[0051] Preferably, based on the pixel mean square error, the predicted texture image is calibrated using the least squares method to obtain a calibrated predicted texture image, including:
[0052] The calibration process for the predicted texture image using the least squares method is as follows:
[0053] Select the key parameters affecting texture in step S1: tool equivalent radius compensation value Δr, used to compensate for actual tool wear; feed rate correction coefficient kv, used to compensate for actual feed error of CNC system; and light reflection coefficient. This is used to match the differences between actual and simulated lighting;
[0054] Least squares optimization aims to minimize the sum of the MSE of all normal images and the calibrated predicted textures, and constructs an optimization function as follows:
[0055]
[0056] Here, min is the minimization operator, which aims to make the subsequent summation result as small as possible; The summation symbol is used for the first to the second image. The mean square errors of the images are accumulated; This is the total number of images of the surface of qualified workpieces; It is the first Images of qualified workpieces and their parameters , , Mean square error between calibrated predicted texture images; It is the tool equivalent radius compensation value, used to compensate for tool wear in actual machining, so that the predicted texture is closer to the actual machining effect of the tool; It is the feed rate correction coefficient, used to compensate for the error between the actual feed of the CNC system and the theoretical setting, and to adjust the texture period and other characteristics. It is the light reflection coefficient, used to match the difference between actual industrial environment lighting and simulated lighting, so that the brightness and reflection effect of the predicted texture are closer to the real scene;
[0057] Subsequently, these parameters are iteratively optimized using the Levenberg-Marquardt algorithm until the mean squared error decreases sufficiently or the number of iterations saturates, ensuring that the parameters are optimized to the optimal state.
[0058] The predicted texture is regenerated using the optimized parameters, and the MSE is calculated with all normal images to ensure that the average MSE is ≤5%, finally resulting in a calibrated predicted texture image.
[0059] Preferably, acquiring an image of the workpiece surface to be inspected, and comparing the image of the workpiece surface with a calibrated predicted texture image to determine potential defect areas includes:
[0060] Using the approved predicted texture image output in step S2 as a benchmark, a three-layer comparison is performed on the preprocessed real-time image:
[0061] The first layer involves pixel-level grayscale comparison, calculating the pixel-by-pixel grayscale difference between the real-time image and the approved texture:
[0062]
[0063] in, It is the real-time image and the calibrated texture image at the pixel position. The absolute value of the grayscale difference is used to quantify the degree of grayscale difference of a single pixel; It is a real-time acquired image of the workpiece at the pixel level. grayscale value at The predicted texture image after calibration in step S2 is in pixels The grayscale value at that location;
[0064] Based on the MSE statistical results of the normal images in step S2, a threshold is determined:
[0065]
[0066] in, It is the threshold for grayscale contrast, used to distinguish between normal grayscale differences and abnormal grayscale differences caused by defects; It is the standard deviation of the mean square error between the qualified workpiece image and the calibrated predicted texture image, representing the fluctuation range of normal differences; It is the mean square error between the qualified workpiece image and the calibrated predicted texture image, representing the typical level of difference in normal textures; all are marked. The pixels are grayscale outliers;
[0067] The second layer involves texture orientation consistency comparison. For both the real-time image and the approved texture, the calculation method used in step S1 is employed. The Gabor filter bank is used to obtain the dominant direction of each pixel. and Calculate the directional deviation:
[0068]
[0069] in, Pixels in real-time workpiece images The dominant direction of the texture; It is to calibrate the pixels in the predicted texture image The dominant direction of the texture; It is real-time image and calibrated texture at the pixel level Texture direction deviation at the location; based on the process stability of the texture direction in step S1, a threshold is taken. Mark all The pixels are points of orientation anomalies;
[0070] The third layer processes the comparison of periodic features, performing a two-dimensional lexical transform on local regions of the real-time image and the verified texture to extract the period corresponding to the main frequency. and Calculate the period deviation:
[0071]
[0072] in, In real-time workpiece images, in pixels The texture period corresponding to the main frequency after a 128×128 pixel block centered on it undergoes a two-dimensional Fourier transform. It is used to calibrate the predicted texture image in pixels. The 128×128 pixel block centered on the main frequency corresponds to the base texture period. Real-time image and calibrated texture at pixel The texture period at that location is relatively deviated;
[0073] Based on the allowable process error of the texture period in step S1, a threshold is taken. Mark all The pixels are periodic outliers;
[0074] For the abnormal points marked in the three sets of comparison, a logical AND operation is used to fuse them. Only when a pixel is marked as grayscale abnormal, orientation abnormal, and periodic abnormal at the same time is it determined as a defect candidate point.
[0075] The coordinates of the potential defect area are extracted as follows:
[0076] Perform connected component analysis on defect candidate points and filter connected components with an area ≥ 50 pixels;
[0077] Enclose each connected component in a bounding rectangle, and with the top-left corner of the image as the origin, output the top-left corner of the rectangle. and bottom right corner Pixel coordinates provide the coordinate range of potential defects.
[0078] Preferably, feature enhancement is first performed on the detected workpiece surface image of the potential defect region to obtain an enhanced potential defect region image, including:
[0079] Using the potential defect coordinates output in step S3 as input, perform targeted enhancements on each potential defect region:
[0080] Region cropping: Defect sub-blocks are cropped from the preprocessed real-time image based on the coordinates of the potential defect region. The size of the sub-blocks is dynamically adjusted according to the size of the potential defect region to ensure that there is sufficient pixel information for subsequent feature extraction.
[0081] The CLAHE enhancement parameters and operations are as follows:
[0082] The potential defect region is divided into 8×8 pixel non-overlapping sub-regions, the number of which is determined by the size of the potential defect region. The decision provides a fine foundation for enhancing local contrast;
[0083] Set contrast limit threshold For the grayscale histogram of each sub-region, if a certain grayscale level... number of pixels Exceed Then, according to the formula:
[0084]
[0085] in, It is a contrast limit threshold, used to constrain the upper limit of the number of pixels at a single gray level, to avoid excessive enhancement of local contrast; It is grayscale; It represents the number of pixels corresponding to gray level g in the original grayscale histogram. It is the number of pixels corresponding to gray level g after contrast limiting;
[0086] Gray-scale mapping after equalization of each sub-region Bilinear interpolation is used to calculate the pixel value within the potential defect region. Enhanced grayscale:
[0087]
[0088] in, It is a pixel The final grayscale value after interpolation enhancement It is the first The gray-level mapping function after equalization of each sub-region; These are the weights of bilinear interpolation, determined by the pixels. The distance from the boundaries of the four surrounding sub-regions determines the distance. It is the index of the subregion order.
[0089] Preferably, feature extraction is performed on the enhanced potential defect region image to obtain a defect feature vector, and the defect feature vector is standardized to obtain a standardized defect feature vector, including:
[0090] For feature concatenation, let the geometric feature vector be... The grayscale feature vector is The texture feature vector is Then the defect feature vector is: ;
[0091] Next, the defect feature vector f is standardized using Z-score, as shown in the formula:
[0092]
[0093] in, This is the mean vector of this feature in the training set, where each element is the mean of all samples in the training set along the corresponding feature dimension. The standard deviation vector for this feature in the training set is the standard deviation of all samples in the training set in the corresponding feature dimension, ensuring that the features in each dimension are of the same order of magnitude; the vector division in the formula is an independent arithmetic division of each corresponding element in the vector.
[0094] Preferably, a workpiece surface defect type identification model is constructed based on a support vector machine. The standardized feature vector of the defect is input into the workpiece surface defect type identification model, and the output surface defect types include:
[0095] An improved support vector machine is used as the classifier. Based on the complex distribution characteristics of the 311-dimensional defect-normalized feature vector output in step S4, which includes geometric, textural, and fingerprint features, an architecture with hybrid kernel functions and adaptive parameter optimization is generated.
[0096] The hybrid kernel function is generated as follows:
[0097] The formula for combining polynomial kernels and radial basis kernels is:
[0098]
[0099] in, , It is the 311-dimensional standardized feature vector output from step 4, which represents the features of the i-th and j-th defect samples respectively, and integrates three types of features: geometric, texture, and metric. It is the dot product of two feature vectors, used to measure the degree of linear correlation between features; This is the polynomial kernel function part, +2 is the constant term of the polynomial, and 3 is the degree of the polynomial, which is used to capture low-dimensional linear and high-dimensional polynomial correlations between features; It is the radial basis kernel function part. It is the squared Euclidean distance between the two eigenvectors. These are the coefficients of the radial basis kernel, used to fit the global nonlinear distribution of the features;
[0100] The parameter optimization method simulates the collective foraging behavior of bird flocks by supplementing Particle Swarm Optimization (PSO). It then uses swarm intelligence to search for the optimal parameter combination. The process is as follows:
[0101] Particle and parameter encoding: Each particle corresponds to a set of parameters to be optimized, including the mixed kernel weight α, polynomial kernel degree d, radial basis kernel coefficient γ, and SVM penalty coefficient C. These parameters are encoded into the particle's position vector.
[0102] For the position of each particle, the SVM model is trained using this parameter, and the classification accuracy is calculated on the validation set. This accuracy is the fitness of the particle.
[0103] The particle update rule is that particles adjust their velocity and position based on their individual optimal position and the global optimal position. The core formula is:
[0104] ;
[0105] ;
[0106] in, It is the particle's current velocity. It is the inertia weight, used to balance global and local search; , It is a learning factor used to guide particles to learn towards the optimal position; , It uses [0, 1] random numbers to increase the randomness of the search; It is the optimal position for an individual. It is the globally optimal position. It is the particle's current position;
[0107] The iteration termination condition is to stop when the maximum number of iterations is reached or the global fitness of the particle swarm no longer improves. At this point, the global optimal position is the optimal combination of parameters.
[0108] Input feature processing transforms the 311-dimensional normalized feature vector of the defect to be detected output from step S4. Input the trained improved SVM model;
[0109] The model output is:
[0110] The model outputs a predicted label y for the defect type through a decision function. Corresponding cracks, Corresponding scratches, Corresponding bubbles, Corresponding oxidation spots.
[0111] Preferably, binding the surface defect type with the coordinates of the potential defect region to generate surface defect coordinates and type includes:
[0112] The coordinate binding extracts the physical coordinates of the potential defect area output in step S3, namely the upper left corner (X1, Y1) and the lower right corner (X2, Y2), and binds them with the defect type y and confidence level Conf output by the model.
[0113] This invention provides a method for recognizing surface defects on workpieces, involving machine learning and deep learning technologies, which has the following beneficial effects:
[0114] (1) The workpiece surface defect image recognition method generates a predicted texture image by cutting surface morphology theory, which can accurately simulate the generation mechanism of workpiece surface texture during CNC machining, providing a high-precision theoretical benchmark for subsequent texture calibration and defect area comparison, effectively reducing the risk of defect misjudgment caused by the deviation between theoretical model and actual machining, and improving the theoretical reliability of defect recognition.
[0115] (2) The workpiece surface defect image recognition method uses the least squares method to calibrate the predicted texture image, which can quantify the pixel difference between the qualified workpiece image and the predicted texture, optimize the tool parameter compensation value, feed speed correction coefficient, etc., so that the calibrated predicted texture is closer to the actual machined surface, significantly weaken the interference of machining deviations such as tool wear and feed error on defect recognition, and improve the accuracy of defect positioning.
[0116] (3) Workpiece surface defect image recognition method: By using SVM support vector machine to build a defect category recognition model, with its excellent classification performance in small sample and high-dimensional feature scenarios, it can accurately distinguish different types of surface defects such as cracks and scratches, greatly improve the accuracy and robustness of defect type recognition, and meet the stringent requirements of precision fields such as aerospace and medical devices for defect classification accuracy.
[0117] (4) The method for identifying surface defects on workpieces optimizes the parameters of the SVM model through the particle swarm optimization algorithm. It can efficiently search for better combinations of parameters such as kernel function weights and penalty coefficients, which significantly improves the classification performance of the SVM model. This not only shortens the model training time but also improves the speed and accuracy of defect identification, ensuring the efficiency and reliability of the defect identification process. Attached Figure Description
[0118] Figure 1 This is a flowchart of a workpiece surface defect image recognition method proposed in this invention;
[0119] Figure 2 This invention provides a method for identifying surface defects on a workpiece to obtain a hierarchical map of the calibrated predicted texture image.
[0120] Figure 3 This is a hierarchical diagram of the surface defect coordinates obtained in a workpiece surface defect image recognition method proposed in this invention. Detailed Implementation
[0121] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0122] Please see Figures 1 to 3 This invention provides a technical solution: a method for recognizing surface defects on a workpiece. Specifically, the method for recognizing surface defects on a workpiece is provided below; please refer to [link / reference]. Figure 1 The method includes the following steps:
[0123] Step S1: Collect CNC machining parameters, calculate the CNC machining parameters using the cutting surface morphology theory, generate a contact area force field cloud map, and generate a predicted texture image based on the contact area force field cloud map by simulating the tool cutting process using computer graphics tools.
[0124] The CNC machining parameters are collected as follows:
[0125] The tool parameters include: tool radius (unit: mm, accuracy ±0.001 mm, measured by tool presetter); rake angle (unit: °, taken from tool design manual or tool marking); clearance angle (unit: °, obtained in the same way as rake angle); and tool type (turning tool / end mill / ball end mill, read from CNC system tool management module).
[0126] The machining motion parameters include: feed rate (unit: mm / min, actual output value read via FOCAS / OPCUA protocol, not set value); spindle speed (unit: rpm, read in the same way as feed rate to ensure consistency with actual machining); and depth of cut (unit: mm, parsed from the Z-axis coordinate difference of the NC code G01 instruction, such as Z10.0 to Z5.0 corresponding to a depth of 5.0 mm).
[0127] For path parameters including tool trajectory coordinate sequence (unit: mm, time interval 10ms), the reverse spiral or straight reciprocating path is extracted by parsing G code (G01 linear interpolation, G02 circular interpolation).
[0128] The reasonableness of the collected parameters and the feed rate are determined. Must meet System maximum feed rate (typically) 10000mm / min); spindle speed Must meet Device limit (e.g.) (15000rpm); Abnormal parameters trigger alarms and require manual confirmation and correction to ensure reliable input data.
[0129] Based on the core assumption of the Oxley model, a theory of cutting surface morphology, that cutting force is linearly related to depth of cut and feed rate, three types of cutting force components are calculated:
[0130] Among them, 0 main cutting force (Along the cutting speed direction) is:
[0131]
[0132] in The unit cutting force (unit: N / mm^2) is determined by material and tool compatibility tests, such as when machining titanium alloy TC4. , The cutting depth is (mm). The feed rate per revolution (mm / rev) is used. This linear relationship model is applicable to finishing conditions of low-carbon steel and aluminum alloys with cutting speeds of 50-200 m / min and workpiece material hardness HRC≤35. 50-200 m / min is the most commonly used and technically mature speed range for most modern CNC machine tools when finishing steel and aluminum alloys. Selecting this range indicates that the model targets the most extensive and typical industrial application scenarios, enhancing the practical value of the invention. Steels with hardness below HRC35 (such as 45# steel, AISI1045) and aluminum alloys belong to medium-low carbon steel and non-ferrous metals. During cutting, they mainly exhibit plastic deformation, and the material removal mechanism is relatively stable. The cutting force and cutting area (mm / rev) are relatively stable. It is easy to establish a stable linear proportional relationship between them (i.e., unit cutting force). (Relatively constant).
[0133] Feed resistance (Along the feed direction) is:
[0134]
[0135] in, The feed resistance coefficient (experimental fitted value, usually) );
[0136] Back force (Perpendicular to the feed direction) is:
[0137]
[0138] in, The back force coefficient (experimental fitted value, usually) ); Feed resistance coefficient and back force coefficient The calibration was obtained through orthogonal cutting tests.
[0139] The calculated , , The contact area between the tool and the workpiece is mapped to the spatial location. A force field cloud map of the contact area is generated using Python's Matplotlib library. This cloud map is used in the subsequent 3D rendering step to generate a predicted texture image to simulate the microscopic undulations in the texture caused by cutting force fluctuations (such as rougher texture in areas with high force).
[0140] The texture dominance direction is predicted as follows:
[0141] First, determine the texture direction based on the toolpath. If it is a turning process (the toolpath is a spiral), let the parametric equation of the toolpath be:
[0142]
[0143] in, For the workpiece radius, The rotation angle is... For feed rate, is the spindle speed, and z represents the position of the tool path in the spindle direction;
[0144] The slope of the tangent line to the spiral at a certain point is:
[0145]
[0146] in, The slope of the tangent line to the helix at a certain point reflects the degree of inclination of the helix; It is the feed rate; It is the circumference of the cylinder surface, representing the distance traveled in the circumferential direction for each revolution. The radius of the cylinder is in millimeters. It is the spindle speed;
[0147] This allows us to obtain the dominant texture direction. (tangent and workpiece axis) The included angle of the axis is:
[0148]
[0149] in, ( The arctangent function converts the slope of a tangent line into an angle value.
[0150] If it is a milling operation (the tool path is a linear reciprocating motion), assume the feed direction is along... When the axis is aligned, the texture dominates the direction. ;along When the axis is axial, .
[0151] Combined with spindle speed (Unit: rpm) and feed rate (Unit: mm / min), theoretical texture period calculated using formula. (Unit: mm):
[0152]
[0153] in The diameter of the workpiece surface to be machined (unit: mm). Main axis circumference (unit: mm).
[0154] The surf function in MATLAB, a computer graphics tool, is used to simulate the cutting process of a cutting tool. The details of the steps are as follows:
[0155] Tool scanning generation is based on the workpiece CAD model (STL format, containing the vertex coordinates and normal vectors of triangular facets), and is based on the spatial coordinate sequence of the tool center point. ,in Given the total number of tool path points, the tool scanning surface is generated using the path stretching method:
[0156] For turning, each tool position is stretched along the helical trajectory to form a continuous helical surface (the normal vector of the surface is determined by the helical tangent direction and the workpiece radial direction).
[0157] For milling, the tool position is stretched along the straight feed direction to form a parallel stripe surface (the stripe direction is consistent with the feed direction).
[0158] The contact area force field cloud map generated by micro-texturing is imported, and based on the positive correlation between cutting force and surface roughness (e.g., for every 100N increase in cutting force, the surface roughness Ra increases by 0.2μm), the vertex height of the scanning surface is perturbed:
[0159] Extract the cutting force at each location in the force field contour map. Calculate the roughness increment at that location:
[0160]
[0161] in, It is a rough increment. The coefficients determined by the experiment, ;
[0162] By adding random Perlin noise, and adding [something] to the vertices of the scanned face, [something] is added. Matching height fluctuations to simulate microscopic textures.
[0163] The lighting model and output are as follows:
[0164] Set the equipment lighting parameters, using a ring-shaped LED light source, with the light source positioned at 45° circumference of the workpiece (angle with the workpiece axis), a light intensity of 5000 lux, and a light source color of cool white (color temperature 5500K);
[0165] The brightness I of each pixel is calculated using the Phong lighting model, with the following formula:
[0166] I=
[0167] in, This represents the ambient light reflectance, with a value of 0.2. It is the diffuse reflectance coefficient, with a value of 0.7; represents the specular reflection coefficient, with a value of 0.3; N is the specular index, set to 20; It is the surface normal vector; The direction vector of the light source; The reflection direction vector; To observe the direction vector; For ambient light intensity, The intensity of diffuse reflected light. This represents the intensity of the specular reflected light, and its value is set according to the actual light source parameters.
[0168] The final output is an 8-bit texture prediction image:
[0169] The image has a resolution of 4096×3072 pixels, a pixel physical size of 3μm (ensuring that a single pixel corresponds to a 3μm×3μm area on the workpiece surface), and is in BMP format, ensuring the dominant texture direction. ,cycle The features are clearly discernible at the pixel level.
[0170] Step S2: Collect images of the surface of qualified workpieces, calculate the pixel mean square error between the surface images of qualified workpieces and the predicted texture image, and calibrate the predicted texture image using the least squares method based on the pixel mean square error to obtain a calibrated predicted texture image.
[0171] The process of collecting images of qualified workpiece surfaces is as follows:
[0172] The camera has a resolution of 4096x2160 pixels, global shutter, and motion blur of <1%; the light source is a high-uniformity LED ring light source with a color temperature of 5500K and illumination uniformity of >90%; the lens is a telecentric lens with a working distance of 100mm, a maximum magnification of 1x, and distortion of <0.1%.
[0173] For 3-5 defect-free workpieces that have been confirmed by quality inspection (with processing parameters completely consistent with those in step S1), collect 3 typical processing areas (head, middle, and tail) for each workpiece, and obtain a total of 9-15 qualified surface images, covering the texture changes throughout the entire processing.
[0174] Image preprocessing is as follows:
[0175] The process involves sequentially converting the RGB image to an 8-bit grayscale image to reduce computational load; performing median filtering (3x3 median filtering) to remove random noise and preserve texture edges; and scaling the image to match the resolution of the predicted texture image (4096x3072 pixels) generated in step S1 to ensure pixel-level contrast consistency.
[0176] For each preprocessed normal image, the MSE is calculated pixel-by-pixel with the predicted texture image generated in step S1, using the following formula:
[0177]
[0178] Where M and N are the image height and width (number of pixels). The predicted texture grayscale value in step S1, The grayscale values are those of normal images. The mean value is obtained by calculating the mean value of the mean grayscale values for all normal images. and standard deviation The formula uses i and j as the calibration reference; i and j are the coordinate indices of the pixel; i represents the row index of the pixel in the image, ranging from 1 to M; j represents the column index of the pixel in the image, ranging from 1 to N.
[0179] The calibration process for the predicted texture image using the least squares method is as follows:
[0180] Select the key parameters affecting texture in step S1: tool equivalent radius compensation value Δr, used to compensate for actual tool wear; feed rate correction coefficient kv, used to compensate for actual feed error of CNC system; and light reflection coefficient. It is used to match the difference between actual and simulated lighting.
[0181] Least squares optimization aims to minimize the sum of the MSE of all normal images and the calibrated predicted textures, and constructs an optimization function as follows:
[0182]
[0183] Here, min is the minimization operator, which aims to make the subsequent summation result as small as possible; The summation symbol is used for the first to the second image. The mean square error (MSE) of each image is accumulated. This is the total number of images of the qualified workpiece surface (9-15 normal images collected). That is, the quantity. It is the first Images of qualified workpieces and their parameters , , Mean square error between calibrated predicted texture images (a metric that measures the pixel-level difference between two images and reflects the degree of texture fit). It is the tool equivalent radius compensation value, used to compensate for tool wear in actual machining, so that the predicted texture is closer to the actual machining effect of the tool; It is the feed rate correction coefficient, used to compensate for the error between the actual feed of the CNC system and the theoretical setting, and to adjust the texture period and other characteristics. It is the light reflection coefficient, used to match the difference between actual industrial environment lighting and simulated lighting (and the Phong lighting model in step S1), so that the brightness and reflection effect of the predicted texture are closer to the real scene.
[0184] These parameters are then iteratively optimized using the Levenberg-Marquardt algorithm until the mean squared error decreases sufficiently. Alternatively, the number of iterations can be saturated (50 times) to ensure that the parameters are optimized to the optimal state.
[0185] The predicted texture is regenerated using the optimized parameters, and the MSE is calculated with all normal images to ensure that the average MSE is ≤5% (relative to the initial MSE in step S1), finally resulting in a calibrated predicted texture image.
[0186] This step involves acquiring and preprocessing images of qualified workpieces, and then comparing them with the predicted texture from step S1 at the pixel level using MSE. The least squares method is used to optimize parameters such as tool radius and feed rate to complete the predicted texture calibration, ensuring that the calibrated texture closely matches the actual normal machining texture. Step S3 requires comparing the real-time image with the calibrated texture in three layers: grayscale, direction, and period, to filter defect areas. Without calibration, the theoretical texture from step S1 will lead to subsequent defect identification errors due to actual deviations (such as tool wear).
[0187] Step S3: Acquire an image of the surface of the workpiece to be inspected, and compare the image of the surface of the workpiece to be inspected with the calibration prediction texture image to determine potential defect areas.
[0188] The data acquisition process uses the same hardware configuration as step S2 to acquire images of the workpiece to be inspected. The acquisition area covers all machined surfaces of the workpiece, corresponding to the acquisition area of the qualified workpiece in step S2 (head, middle, and tail). For the number of acquisitions, three images are acquired for each workpiece to be inspected (synchronizing with the area division in step S2) to ensure coverage of possible defects throughout the entire processing. The preprocessing operation follows the same preprocessing procedure as step S2 to ensure comparability with the calibration texture.
[0189] The real-time image is aligned pixel-level with the calibration texture using workpiece edge features (such as positioning holes) (deviation ≤ 1 pixel) to avoid positional offset affecting the results.
[0190] Using the approved predicted texture image output in step S2 as a benchmark, a three-layer comparison is performed on the preprocessed real-time image:
[0191] The first layer involves pixel-level grayscale comparison, calculating the pixel-by-pixel grayscale difference between the real-time image and the approved texture:
[0192]
[0193] in, It is the real-time image and the calibrated texture image at the pixel position. (No. line, number The absolute value of the grayscale difference of the column is used to quantify the degree of grayscale difference of a single pixel; It is a real-time acquired image of the workpiece at the pixel level. grayscale value (range) (8-bit grayscale image) The predicted texture image after calibration in step S2 is in pixels The gray value at that location (serving as the reference gray value for a normal, defect-free texture).
[0194] Based on the MSE statistical results of the normal images in step S2, a threshold is determined:
[0195]
[0196] in, It is the threshold for grayscale contrast, used to distinguish between normal grayscale differences and abnormal grayscale differences caused by defects. It is the standard deviation of the mean square error (MSE) between the qualified workpiece image and the calibrated predicted texture image, representing the fluctuation range of normal differences; It is the mean squared error (MSE) between the qualified workpiece image and the calibrated predicted texture image, representing the typical level of difference in normal texture.
[0197] Mark all The pixels in question are grayscale outliers.
[0198] The second layer involves texture orientation consistency comparison. For both the real-time image and the approved texture, the calculation method used in step S1 is employed. A Gabor filter bank (wavelength 8 pixels, orientation 0° / 45° / 90° / 135°) is used to obtain the dominant orientation of each pixel. and Calculate the directional deviation:
[0199]
[0200] in, Pixels in real-time workpiece images The dominant direction of the texture;
[0201] It is to calibrate the pixels in the predicted texture image The dominant direction of the texture; It is real-time image and calibrated texture at the pixel level Texture direction deviation at the location (unit: degrees).
[0202] Based on the process stability of the texture direction in step S1 (e.g., a deviation of ≤15° in the turning texture direction is considered normal), a threshold is taken. Mark all The pixels are points of orientation anomalies.
[0203] The third layer processes the periodic feature comparison, performing a two-dimensional derivation transform on local regions (128×128 pixel blocks) of the real-time image and the verified texture to extract the period corresponding to the main frequency. and Calculate the period deviation:
[0204]
[0205] in, In real-time workpiece images, in pixels The 128×128 pixel block centered on the center, after two-dimensional Fourier transform, corresponds to the texture period (which reflects the spacing of texture repetition and is one of the core features of texture). It is used to calibrate the predicted texture image in pixels. The 128×128 pixel block centered on the main frequency corresponds to the base texture period. Real-time image and calibrated texture at pixel The relative deviation of the texture period at a given location (measured as a percentage of the degree of period difference).
[0206] Based on the allowable process error (≤10%) of the texture period in step S1, a threshold is taken. Mark all The pixels are periodic outliers.
[0207] For the abnormal points marked in the three sets of comparison, a logical AND operation is used to fuse them. Only when a pixel is marked as grayscale abnormal, orientation abnormal, and periodic abnormal at the same time is it determined as a defect candidate point.
[0208] It should be noted that the three-layer comparison filters anomalies from three dimensions: pixel grayscale (difference between light and dark), texture direction (process-driven direction), and texture period (repetition of processing patterns). Anomalies in a single dimension are likely to be non-defect interference (e.g., grayscale anomalies: uneven light reflection, camera noise). Only when a pixel violates the normal process characteristics in all three dimensions is it judged as a defect candidate point, which can effectively filter out false anomalies and avoid misjudging normal processing as defects.
[0209] The coordinates of the potential defect area are extracted as follows:
[0210] Perform connected component analysis (8-neighbor connectivity) on defect candidate points and filter connected components with an area ≥ 50 pixels (excluding isolated points caused by noise).
[0211] Enclose each connected component in a bounding rectangle, and with the top-left corner of the image as the origin, output the top-left corner of the rectangle. and bottom right corner Pixel coordinates provide the coordinate range of potential defects.
[0212] The coordinate transformation is as follows:
[0213] Convert image pixel coordinates to physical coordinates (unit: mm) in the workpiece coordinate system. Conversion formula: , (s is the pixel size, defined as 3µm, i.e.) If the aforementioned potential defects are converted into physical coordinates (X1, Y1) and (X2, Y2) in the workpiece coordinate system, the physical meaning of subsequent defect location will be clear.
[0214] This step acquires and preprocesses real-time images of the test workpiece, and compares them with the calibration prediction texture output in step S2 at the pixel level in terms of grayscale, direction, and period. By setting thresholds associated with the process features in step S1 (such as direction deviation <15°, period deviation <10%), and after fusing outliers, potential defect areas with qualified area and clear physical location are selected, thus completing the preliminary location of the defect areas.
[0215] Step S4: First, perform feature enhancement on the detected workpiece surface image of the potential defect area to obtain an enhanced potential defect area image; perform feature extraction on the enhanced potential defect area image to obtain a defect feature vector; and perform standardization processing on the defect feature vector to obtain a standardized defect feature vector.
[0216] The coordinates of the potential defects output in step S3 (the top left corner of the image sub-block corresponding to each potential defect region). and bottom right corner Using pixel coordinates as input, perform targeted enhancements on each potential defect area:
[0217] Region cropping involves cropping defect sub-blocks from the preprocessed real-time image based on the coordinates of the potential defect region. The size of the sub-blocks is dynamically adjusted according to the size of the potential defect region (minimum not less than 32×32 pixels) to ensure sufficient pixel information for subsequent feature extraction.
[0218] The CLAHE enhancement parameters and operations are as follows:
[0219] The potential defect region is divided into 8×8 pixel non-overlapping sub-regions, the number of which is determined by the size of the potential defect region. (high ,width The unit (pixels) determines the fine foundation for local contrast enhancement.
[0220] Set contrast limit threshold Contrast Limit Threshold This is based on multiple experiments, achieving a balance between avoiding excessive noise enhancement and effectively improving defect contrast. It can also be set as a function of the image's average grayscale value to achieve adaptive behavior; for the grayscale histogram of each sub-region, if a certain grayscale level... ( Number of pixels (grayscale levels from 0 to 255) Exceed Then, according to the formula:
[0221]
[0222] in, This is the contrast limit threshold (set to 40 here), used to constrain the upper limit of the number of pixels at a single gray level, preventing excessive enhancement of local contrast. It is the gray level (ranging from 0 to 255, corresponding to the 256 gray levels of an 8-bit grayscale image). It is the number of pixels corresponding to gray level g in the original gray-level histogram (i.e., the total number of pixels contained in that gray level). It is the number of pixels corresponding to gray level g after contrast limiting (cropping).
[0223] Gray-scale mapping after equalization of each sub-region ( (For sub-region indexing), bilinear interpolation is used to calculate any pixel within the potential defect region. Enhanced grayscale:
[0224]
[0225] in, Pixels within the ROL (Region of Interest) The final grayscale value after interpolation enhancement (used for subsequent defect feature extraction). It is the first The grayscale mapping function after equalization of each sub-region (obtained by dividing the potential defect region into blocks) describes the transformation system of pixel grayscale within that sub-region; These are the weights of bilinear interpolation, determined by the pixels. The distance to the boundaries of the four surrounding sub-regions determines the order of the sub-regions, and m is the index of the sub-region order.
[0226] Based on the enhanced image of potential defect areas, multi-dimensional feature extraction is performed to extract three core features: contour, grayscale, and texture.
[0227] The contour extraction process is as follows:
[0228] The complete contour of the enhanced potential defect region image is obtained through 8-neighbor connected component analysis. If the contour contains 1 pixel ( The total number of pixels within the area outline is then... :
[0229]
[0230] in, This is an indicator function; a pixel is 1 if it is within the outline, and 0 otherwise.
[0231] The longer side of the minimum bounding rectangle of the defect With the shorter side The ratio of length to diameter, aspect ratio :
[0232]
[0233] in, It is the longer side of the smallest bounding rectangle. It is the shorter side of the smallest bounding rectangle.
[0234] For roundness First, calculate the perimeter of the outline:
[0235]
[0236] in, is the perimeter of the contour, and m is the total number of points that make up the contour. and These are the x and y coordinates of the j-th contour point (i.e., the pixel coordinates of discrete points on the contour); and These are the x and y coordinates of the (j+1)th contour point, respectively;
[0237] Then through the formula C (range of values) (The closer it is to 1, the closer it is to a circle):
[0238]
[0239] in, It is the area enclosed by the contour, and its value ranges from 1 to 2. The closer to 1, the closer the outline shape is to a circle; the farther away from 1, the more irregular the shape.
[0240] Grayscale features are extracted as follows:
[0241] Enhance pixel grayscale values within potential defect areas ( , To enhance the overall brightness of the defective area (total number of pixels), a statistical grayscale mean μ is calculated, reflecting the overall brightness of the defective area. The formula is:
[0242]
[0243] in, It enhances the first region within the potential defect region (region of interest, i.e., the potential defect region). grayscale value of each pixel. , It is the total number of pixels within the potentially defective area, that is, the total number of pixels in the area. It is the grayscale mean, used to describe the overall brightness and darkness of the area with potential defects.
[0244] Gray-level variance reflects the degree of dispersion of gray-level distribution, and its formula is:
[0245]
[0246] in, It is the gray-level variance, used to describe the degree of dispersion (non-uniformity) of gray-level values within a region of potential defects.
[0247] Gradient histogram, calculated by Sobel gradients in the horizontal and vertical directions. , (through convolution) , (Implement), to obtain gradient magnitude Statistically determine the frequency distribution of G in the range [0, 255]. (g is the step level), quantifying the steepness of the defect edge to form a 10-dimensional gradient histogram feature.
[0248] Texture features are extracted as follows:
[0249] Local binary pattern (LBP) is used to enhance pixels within potential defect areas. With it as the center and radius The circular neighborhood contains 8 sampling points ( ), where p is the sampling point sequence index, and the LBP value is:
[0250]
[0251] in, For symbolic functions, The value is 1 if the LBP is active and 0 otherwise. A 256-dimensional histogram is obtained by statistically analyzing the LBP values of all pixels. It reflects the microscopic texture pattern of the defect surface (e.g., the surface of a bubble is smooth and the LBP value is concentrated; the edge of a crack is rough and the LBP value is dispersed).
[0252] Gabor texture energy is achieved using a Gabor filter bank with 5 scales (wavelengths of 2-10 pixels) and 8 directions. Convolution of images to enhance potential defect regions, the energy value output by each filter. for:
[0253]
[0254] in, To increase the size of potential defect areas, For scale indexing, Using directional indices, a 40-dimensional energy feature is formed. Distinguish between the directional differences between defects and processing textures.
[0255] Feature fusion and standardization are as follows:
[0256] For feature concatenation, let the geometric feature vector be... (3D), grayscale feature vector is (12-dimensional, including mean, variance, and 10-dimensional gradient histogram statistics), the texture feature vector is... (256 + 40 = 296 dimensions), then the defect feature vector (multi-dimensional) is:
[0257]
[0258] Then, Z-score standardization is applied to the defect feature vector f to obtain the standardized feature vector. The formula is:
[0259]
[0260] in, This is the mean vector of this feature in the training set, where each element is the mean of all samples in the training set along the corresponding feature dimension. The standard deviation vector for this feature in the training set is the standard deviation of all samples in the training set in the corresponding feature dimension, ensuring that the features in each dimension are of the same order of magnitude; the vector division in the formula is an independent arithmetic division of each corresponding element in the vector.
[0261] This step, based on the potential defect region output in step S3, enhances the contrast between the defect and the background using the CLAHE algorithm. Then, it extracts the geometric (area, aspect ratio, circularity), grayscale (grayscale value, variance, gradient histogram), and texture (LBP histogram, Gabor energy) features of the defect using methods such as Canny edge detection, statistical analysis, LBP and Gabor filtering. Finally, these features are fused into a standardized 311-dimensional defect standardized feature vector, providing a quantitative basis for defect type identification.
[0262] Step S5: Based on support vector machine, construct a workpiece surface defect type identification model, input the standardized feature vector of the defect into the workpiece surface defect type identification model, output the surface defect type, bind the surface defect type with the coordinates of the potential defect area, and generate surface defect coordinates and type.
[0263] Construct a workpiece surface defect type identification model:
[0264] An improved support vector machine (SVM) is used as the classifier, and the 311-dimensional defect-normalized feature vector output in step S4 is analyzed. This involves considering the complex distribution characteristics of geometric, textural, and fingerprint features, and generating an architecture with hybrid kernel functions and adaptive parameter optimization.
[0265] Hybrid kernel function The following was generated:
[0266] The formula for combining polynomial kernels and radial basis kernels is:
[0267]
[0268] in, , It is the 311-dimensional standardized feature vector output from step 4 (representing the features of the i-th and j-th defect samples, respectively, integrating geometric, texture, and metric features). It is the dot product of two feature vectors, used to measure the degree of linear correlation between features (such as the linear correlation between aspect ratio and crack type). This is the polynomial kernel function part, +2 is the constant term of the polynomial, and 3 is the degree of the polynomial, which is used to capture low-dimensional linear and high-dimensional polynomial correlations between features; It is the radial basis function (RBF) kernel part. It is the squared Euclidean distance between the two eigenvectors. These are the coefficients of the radial basis kernel (initial value -0.8), used to fit the global nonlinear distribution of the features;
[0269] Parameter optimization methods (Particle Swarm Optimization, PSO) supplement Particle Swarm Optimization (PSO) simulates the collective foraging behavior of bird flocks, searching for the optimal combination of parameters through swarm intelligence. The process is as follows:
[0270] Particle and parameter encoding: Each particle corresponds to a set of parameters to be optimized (mixed kernel weight α, polynomial kernel degree d, radial basis kernel coefficient γ, SVM penalty coefficient C), and these parameters are encoded into the particle's position vector.
[0271] For each particle's position (i.e. a set of parameters), an SVM model is trained using these parameters, and then the classification accuracy is calculated on the validation set (240 samples). This accuracy is the particle's fitness (the higher the fitness, the better the parameter combination).
[0272] The particle update rule is that particles adjust their velocity and position based on their individual optimal position (the parameters corresponding to their highest historical fitness) and the global optimal position (the parameters corresponding to the highest historical fitness of the entire particle swarm). It is the velocity of the particle at the next moment, and the core formula is:
[0273] ;
[0274] ;
[0275] in, It is the particle's current velocity. (Inertia weight, set to 0.7) Balances global and local search; , (Learning factor, set to 2) guides the particle to learn towards the optimal position; , It uses [0, 1] random numbers to increase the randomness of the search; It is the optimal position for an individual. It is the globally optimal position. It is the particle's current position.
[0276] The iteration terminates when the maximum number of iterations (50 times) is reached or the global fitness (validation set accuracy) of the particle swarm no longer improves. At this point, the global optimal position is the optimal parameter combination.
[0277] The model training process is as follows:
[0278] Dataset preparation: The historical defect samples (200 samples per class, 4 classes in total) are divided into a training set (560 samples) and a validation set (240 samples) in a 7:3 ratio. Each sample contains the 311-dimensional feature vector from step S4 and manually labeled defect type (e.g., crack=1, scratch=2, etc.).
[0279] Initialize the parameter range and set the PSO search range: α∈[0,1] (mixed weights sum to 1), d∈[2,5] (polynomial degree, to avoid overfitting), γ∈[0,1,2] (radial basis function, to control the width of the kernel function), C∈[1,100] (SVM penalty coefficient, to balance classification accuracy and model complexity).
[0280] During the continuous training phase, in each iteration (50 rounds in total), PSO generates 30 sets of parameters (corresponding to the positions of 30 particles); for each set of parameters, an SVM model (based on a hybrid kernel function K) is trained using the training set; the trained model is used to predict on the validation set, and the classification accuracy is calculated as the fitness of that set of parameters; the individual optimal position of each particle and the global optimal position of the particle swarm are updated based on the fitness.
[0281] Termination and Saving Phase: After the iteration ends, extract the parameter combination corresponding to the global optimal position; retrain the SVM model on the complete training set using this parameter combination to ensure an accuracy of ≥92% on the validation set (meeting the accuracy requirements for industrial defect detection); save the trained SVM model (including optimal parameters and support vectors) for subsequent defect type prediction.
[0282] The input feature processing takes the 311-dimensional standardized feature vector f' of the defect to be detected output in step S4 and inputs it into the trained improved SVM model.
[0283] The model output is:
[0284] The model outputs a predicted label y for the defect type through a decision function, for example: Corresponding cracks, Corresponding scratches, Corresponding bubbles, Corresponding oxidation spots.
[0285] Based on the distance from the sample to the classification hyperplane (the decision function value f(F'test)), convert it into a confidence score:
[0286] Conf=
[0287] Where Conf is the confidence level of the defect type prediction. It is the output value of the decision function of the Support Vector Machine (SVM). It is the standardized multi-dimensional feature vector of the defect to be detected in step 4 (a set of 311-dimensional features after Z-score standardization); It is the decision function of the SVM model, and its output reflects the distance of the sample to be detected to the classification hyperplane (the greater the distance, the further the sample is from the class boundary, and the higher the confidence of the classification). Natural exponential function (in Euler's number) (with base), used to map the output of the decision function to the interval (0, 1).
[0288] The coordinates and types of the generated surface defects are as follows:
[0289] The coordinate binding extracts the physical coordinates of the potential defect area output in step S3, namely the upper left corner (X1, Y1) and the lower right corner (X2, Y2), and binds them with the defect type y and confidence level Conf output by the model.
[0290] This invention proposes a method for recognizing surface defects on workpieces. First, a predicted texture image is generated from CNC machining parameters based on the theory of cutting surface morphology. Then, the texture is calibrated using the least squares method combined with an image of a qualified workpiece. Next, potential defect areas are located and features are enhanced, and geometric, grayscale, and texture triple feature vectors are extracted. Finally, a support vector machine (SVM) optimized by particle swarm optimization algorithm is used to accurately identify the defect type and bind it to the coordinates of the defect area. This forms a closed loop of theoretical texture generation, calibration, defect localization, feature processing, classification, and localization, achieving high-precision, strong anti-interference, and high-efficiency recognition of surface defects on workpieces, providing accurate basis for subsequent defect repair and process optimization.
[0291] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the statement "including a..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0292] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their likenesses.
Claims
1. A method for identifying a surface defect of a workpiece, characterized by, The method comprises the following steps: Step S1: Collecting numerical control machining parameters, calculating the numerical control machining parameters through cutting surface topography theory, generating a contact area force field cloud chart, and simulating the tool cutting process based on the contact area force field cloud chart through computer graphics tools to generate a predicted texture image; Step S2: Collecting a qualified workpiece surface image, calculating the pixel mean square error of the qualified workpiece surface image and the predicted texture image, calibrating the predicted texture image through the least square method based on the pixel mean square error, and obtaining a calibrated predicted texture image; Step S3: Collecting a workpiece surface image to be detected, comparing the workpiece surface image to be detected with the calibrated predicted texture image, and determining a potential defect area; Step S4: First, performing feature enhancement on the detected workpiece surface image of the potential defect area to obtain an enhanced potential defect area image; performing feature extraction on the enhanced potential defect area image to obtain a defect feature vector, performing standardization processing on the defect feature vector, and obtaining a defect standardized feature vector; Step S5: Based on a support vector machine, a workpiece surface defect type recognition model is constructed, the defect standardized feature vector is input into the workpiece surface defect type recognition model, and a surface defect type is output to obtain a surface defect coordinate and type by binding the surface defect type with the coordinates of the potential defect area.
2. The method of claim 1, wherein The numerical control machining parameters are collected, the numerical control machining parameters are calculated through the cutting surface topography theory, and a contact area force field cloud chart is generated, comprising: The numerical control machining parameters are collected as follows: For tool parameters, the tool radius, rake angle, and tool type are included; For machining motion parameters, the feed speed, spindle speed, and cutting depth are included; For path parameters, the tool trajectory coordinate sequence is included, which is extracted by analyzing G code, and reverse helical lines or straight line reciprocating paths are included; Based on the core hypothesis that the cutting force is linearly related to the cutting depth and feed speed in the Oxley model of cutting surface topography theory, three types of cutting force components are calculated respectively: Main cutting force Is: ; wherein is the unit cutting force, unit is , determined by material and tool matching experiment; is the cutting depth, unit is , is the feed per revolution, unit is mm / rev; the linear relationship model is applicable to the fine machining working condition of low carbon steel and aluminum alloy with cutting speed of 50-200 m / min and workpiece material hardness HRC≤35; Further feed resistance Is: ; wherein, is the feed resistance coefficient; Back force Is: ; wherein, Cp is the drag coefficient; and The calculated , , The contact area of the tool and the workpiece is mapped according to the spatial position, and the force field cloud diagram of the contact area is generated through the Matplotlib library of Python.
3. The workpiece surface defect image recognition method of claim 2, wherein Based on the contact area force field cloud chart, the tool cutting process is simulated through computer graphics tools to generate a predicted texture image, comprising: The surf function of the computer graphics tool MATLAB is used to simulate the tool cutting process, and the details are as follows: The tool scanning is generated based on a workpiece CAD model according to a sequence of spatial coordinates of a tool center point wherein is the total number of tool path points, and a tool scanning surface is generated by using a path stretching method; For turning machining, the tool position at each time point is stretched along the helical line trajectory to form a continuous spiral surface, and the normal vector of the surface is determined by the helical line tangent direction and the workpiece radial direction; For milling machining, the tool position is stretched along the straight line feed direction to form a parallel stripe surface; The generated contact area force field cloud chart is disturbed according to the rule that the cutting force is positively correlated with the surface roughness: extracting a cutting force at each position in the force field cloud , calculating a roughness increment at the position: ; wherein, is a coarse increment, is an experimentally determined coefficient; by adding random Perlin noise, add a height fluctuation matching the microtexture at the vertices of the scan face; The light model and output are as follows: The device lighting parameters are set, a ring-shaped LED light source is adopted, the light source position is 45° in the circumferential direction of the workpiece, the light intensity is 5000 lux, and the light source color is cold white; The brightness I of each pixel is calculated using the Phong light model, and the formula is: I= ; wherein represents the coefficient of reflection of ambient light; its value is 0.2; is the coefficient of diffuse reflection, having a value of 0.7; is the value of the specular reflection coefficient, which is 0.3; is the high light index, which is set to 20; is the surface normal vector; is the light source direction vector; is the reflection direction vector; is the observation direction vector; is the ambient light intensity, is the diffuse reflection light intensity, is the specular reflection light intensity, the value of which is set according to the actual light source parameters; The final output is an 8-bit texture prediction image: Resolution 4096x3072 pixels, pixel physical size 3 μm, image format BMP, ensure the texture dominant direction , period The features are clearly distinguishable in the pixels.
4. The workpiece surface defect image recognition method of claim 3, wherein The qualified workpiece surface image is collected, and the pixel mean square error of the qualified workpiece surface image and the predicted texture image is calculated, comprising: The collection of workpiece surface image process is as follows: The camera is 4096x2160 pixels, global shutter, motion blur <1%; the light source is a high uniformity LED ring light source, 5500K color temperature, illumination uniformity >90%; the lens is a telecentric lens, working distance 100mm, maximum magnification 1x, distortion <0.1%; For 3-5 pieces of workpieces confirmed to be defect-free by quality inspection, 3 typical machining areas are collected for each workpiece, and 9-15 frames of qualified surface images are obtained, covering the texture changes in the whole machining process; For each preprocessed normal image, the mean square error (MSE) is calculated with the predicted texture image generated in step S1 pixel by pixel, and the formula is: ; where M, N are the height and width of the image, is the predicted texture gray value of step S1, is the normal image gray value; the MSE of all normal images is calculated to obtain the mean and standard deviation as the calibration reference; i and j in the formula are the coordinate indexes of the pixel points; i represents the row index of the pixel in the image, ranging from 1 to M; j represents the column index of the pixel in the image, ranging from 1 to N.
5. The workpiece surface defect image recognition method of claim 4, wherein Based on the pixel mean square error, the predicted texture image is calibrated by least squares method to obtain the calibrated predicted texture image, including: The calibration process of the predicted texture image by least squares method is as follows: The key parameters affecting the texture in step S1 are selected, a tool equivalent radius compensation value Δr is used to compensate the actual tool wear, a feed speed correction coefficient kv is used to compensate the actual feed error of the numerical control system, and a light reflection coefficient is used to match the actual and simulated light differences. The least squares optimization takes the sum of the MSE of all normal images and the calibrated predicted texture as the target to construct the optimization function: ; Here, min is the minimization operator, which aims to make the subsequent summation result as small as possible; The summation symbol is used for the first to the second image. The mean square errors of the images are accumulated; This is the total number of images of the surface of qualified workpieces; It is the first Images of qualified workpieces and their parameters , , Mean square error between calibrated predicted texture images; It is the tool equivalent radius compensation value, used to compensate for tool wear in actual machining, so that the predicted texture is closer to the actual machining effect of the tool; It is the feed rate correction coefficient, used to compensate for the error between the actual feed of the CNC system and the theoretical setting, and to adjust the texture period and other characteristics. It is the light reflection coefficient, used to match the difference between actual industrial environment lighting and simulated lighting, so that the brightness and reflection effect of the predicted texture are closer to the real scene; Subsequently, the Levenberg-Marquardt algorithm is used to iteratively optimize these parameters until the decline of the mean square error is small enough or the iteration times are saturated, ensuring that the parameters are optimized to the optimal state; The optimized parameters are used to regenerate the predicted texture, and the MSE is calculated with all normal images to ensure that the average MSE is ≤5%, and finally the calibrated predicted texture image is obtained.
6. The workpiece surface defect image recognition method of claim 5, wherein Collect the surface image of the workpiece to be detected, and compare the surface image of the workpiece to be detected with the calibrated predicted texture image to determine the potential defect area, including: Take the calibrated predicted texture image output in step S2 as the reference, and perform three-layer comparison on the preprocessed real-time image: The first layer is a gray pixel level comparison, which calculates the pixel-by-pixel gray difference between the real-time image and the calibrated texture: ; wherein, is the absolute value of the gray scale difference value of the real-time image and the calibration texture image at the pixel position , used to quantify the degree of gray scale difference of a single pixel; is the gray scale value of the real-time collected workpiece image at the pixel ; is the gray scale value of the calibrated prediction texture image at the pixel ; Based on the MSE statistical result of the normal image in step S2, a threshold is taken: ; wherein, is a decision threshold of the gray contrast, used to distinguish the normal gray difference from the abnormal gray difference caused by defects; is the standard deviation of the mean square error of the qualified workpiece image and the calibration predicted texture image, representing the fluctuation range of the normal difference; is the mean value of the mean square error of the qualified workpiece image and the calibration predicted texture image, representing the typical difference level of the normal texture; mark all pixels as gray abnormal points; The second layer, texture direction consistency contrast, uses the Gabor filter bank used in step S1 for calculating the dominant direction of each pixel for both the real-time image and the approved texture and the direction deviation: ; wherein, is the dominant direction of texture at pixel in the real-time workpiece image; is the dominant direction of texture at pixel in the calibration predicted texture image; is the texture direction deviation of the real-time image and the calibration texture at pixel ; based on the process stability of the texture direction in step S1, a threshold is taken, and all pixels of are marked as direction abnormal points; Third layer, processing period feature contrast, two-dimensional Fourier transform is done to local area of real-time image and approved texture, and the period corresponding to the main frequency is extracted and , the period deviation is calculated ; wherein, is the texture period of the 128x128 pixel block centered at pixel in the real-time workpiece image, after two-dimensional Fourier transform, the main frequency corresponds to the texture period; is the reference texture period of the 128x128 pixel block centered at pixel in the calibration predicted texture image, the main frequency corresponds to the reference texture period; is the relative deviation of the texture periods of the real-time image and the calibration texture at pixel ; Taking a threshold value based on the process allowance of the texture period in step S1 , marking all pixels of the period anomaly points; For the three groups of abnormal points marked by comparison, logical AND operation is used to fuse, and only when the pixel is marked as gray abnormal, direction abnormal and periodic abnormal at the same time, it is determined as a defect candidate point; The potential defect area coordinates are extracted as follows: Perform connected component analysis on the defect candidate points and select connected components with an area of ≥50 pixels; Enclose each connected component in a bounding rectangle, and with the top-left corner of the image as the origin, output the top-left corner of the rectangle. and bottom right corner Pixel coordinates provide the coordinate range of potential defects.
7. The workpiece surface defect image recognition method of claim 6, wherein First, the feature of the potential defect area is enhanced to obtain an enhanced potential defect area image, including: Take the potential defect coordinates output in step S3 as input, and perform targeted enhancement on each potential defect area: Region cropping, according to the potential defect area coordinates, crop the defect sub-block from the preprocessed real-time image, and dynamically adjust the sub-block size according to the potential defect area size to ensure that there is enough pixel information for subsequent feature extraction; The CLAHE enhancement parameters and operations are as follows: The potential defective area sub-block is divided into 8x8 pixel non-overlapping sub-areas, and the number of sub-areas is determined by the size of the potential defective area Decide to provide a fine basis for local contrast enhancement; Setting a contrast limit threshold For each sub-region, if the number of pixels of a certain gray level exceeds a certain percentage of the total number of pixels in the sub-region, then the gray level is set as the contrast limit threshold of the sub-region. ; wherein, is a contrast limit threshold, used to constrain the upper limit of the number of pixels of a single gray level, to avoid excessive enhancement of local contrast; is a gray level; is the number of pixels corresponding to the gray level g in the original gray histogram; is the number of pixels corresponding to the gray level g after contrast limiting; Gray-scale mapping after equalization of each sub-region Bilinear interpolation is used to calculate the pixel value within the potential defect region. Enhanced grayscale: ; wherein, is a pixel is the final gray value after interpolation enhancement is the gray mapping function after the sub-region equalization; is determined by the distance to the surrounding four sub-region boundaries, is the index of the sub-region order.
8. The method of claim 7, wherein Perform feature extraction on the enhanced potential defect area image to obtain a defect feature vector, and perform standardization processing on the defect feature vector to obtain a defect standardized feature vector, including: For feature concatenation, let the geometric feature vector be , the gray level feature vector be , and the texture feature vector be , then the defect feature vector is: wherein, is the total number of pixels within the area contour; C is ; is the length-diameter ratio; is the mean gray level; is the gray level variance; is the LBP texture feature vector; is the Gabor texture feature vector; and T is the transpose symbol. Then, the defect feature vector f is subjected to Z-score standardization, and the formula is: ; wherein, is the mean vector of the feature in the training set, each element of which is the average of all samples in the training set in the corresponding feature dimension; is the standard deviation vector of the feature in the training set, which is the standard deviation of all samples in the training set in the corresponding feature dimension, ensuring that the features in each dimension are in the same order of magnitude; the division of the vectors appearing in the formula is an independent arithmetic division of the elements in each corresponding position in the vectors.
9. The method of claim 8, wherein Based on the support vector machine, a workpiece surface defect type recognition model is constructed, the defect standardized feature vector is input into the workpiece surface defect type recognition model, and the surface defect type is output, including: An improved support vector machine is used as a classifier. For the 311-dimensional defect standardization feature vector output in step S4, a complex distribution characteristic including geometric, texture, and fingerprint features is generated, and a mixed kernel function and parameter adaptive optimization architecture is generated. The mixed kernel function is generated as follows: A polynomial kernel and a radial basis kernel are fused, and the formula is as follows: ; in, , It is the 311-dimensional standardized feature vector output from step 4, which represents the features of the i-th and j-th defect samples respectively, and integrates three types of features: geometric, texture, and metric. It is the dot product of two feature vectors, used to measure the degree of linear correlation between features; This is the polynomial kernel function part, +2 is the constant term of the polynomial, and 3 is the degree of the polynomial, which is used to capture low-dimensional linear and high-dimensional polynomial correlations between features; It is the radial basis kernel function part. It is the squared Euclidean distance between the two eigenvectors. These are the coefficients of the radial basis kernel, used to fit the global nonlinear distribution of the features; A parameter optimization method is used. A particle swarm optimization (PSO) is used to simulate the foraging behavior of a bird swarm, and a swarm intelligence is used to search for an optimal parameter combination. The process is as follows: Particle and parameter coding. Each particle corresponds to a set of parameters to be optimized, including a mixed kernel weight α, a polynomial kernel degree d, a radial basis kernel coefficient γ, and an SVM penalty coefficient C. These parameters are coded as a position vector of the particle. For the position of each particle, an SVM model is trained using the parameters, and the classification accuracy is calculated on the validation set. The accuracy is the fitness of the particle. The particle update rule is that the particle adjusts the speed and position through the individual optimal position and the global optimal position. The core formula is as follows: ; ; where, is the current velocity of the particle, is the inertia weight, used to balance the global and local search; , is the learning factor, used to guide the particle to learn the optimal position; , is a [0, 1] random number, increasing the search randomness; is the individual optimal position, is the global optimal position, is the current position of the particle; The iteration termination condition is that the maximum iteration number is reached or the global fitness of the particle swarm is no longer improved, and the iteration is stopped. At this time, the global optimal position is the optimal parameter combination. The input feature processing processes the 311-dimensional normalized feature vector of the defect to be detected outputted by step S4 The input trained improved SVM model; The model output is as follows: The model outputs a predicted label y of the defect type by a decision function, corresponding to a crack, corresponding to a scratch, corresponding to a bubble, corresponding to an oxidation spot.
10. The method of claim 9, wherein, The surface defect type and the coordinates of the potential defect area are bound to generate surface defect coordinates and types, including: The coordinates are bound to extract the potential defect area physical coordinates of the left upper corner (X1, Y1) and the right lower corner (X2, Y2) output in step S3, and the defect type y and the confidence Conf output by the model are bound.
Citation Information
Patent Citations
Automobile leather defect detection method and system based on visual detection
CN120655628A
Cutting workpiece defect detection method and system based on image feature feedback
CN120747040A