Turning surface roughness GS-BP visual detection method
Through the GS-BP neural network combined with grid search algorithm, industrial cameras and mathematical morphology are used to process turning workpiece images and extract straight line features, solving the accuracy and cost problems of existing detection methods, and achieving efficient and accurate surface roughness detection of turning workpieces.
Patent Information
- Application Number
- CN202510434530.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-07-22
AI Technical Summary
The existing surface roughness detection methods for turning workpieces have problems such as inaccurate detection accuracy, high cost, complex operation and sensitive to the surface of the workpiece. Especially when traditional contact measurement methods damage the workpiece, the non-contact measurement methods are costly and have high environmental requirements.
The GS-BP neural network is combined with the grid search algorithm, and the workpiece surface images are collected through industrial cameras, grayscale, binarization and filtering are performed. The target area is optimized using mathematical morphology, linear features are extracted, and BP neural network model is constructed for detection.
It realizes efficient and accurate surface roughness detection of turning workpieces, with accurate identification, simple operation, low cost and strong robustness, with an accuracy of prediction results reaching 97.6%, and a single prediction time is only 0.006 seconds.
Smart Images

Figure CN120355676A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a method for detecting the surface roughness of turning, and particularly to a method for detecting the surface roughness of turning workpieces based on a GS-BP neural network. Background Art
[0002] As an important indicator for measuring the quality of machined surfaces, surface roughness has a significant impact on the performance of mechanical parts such as fit, wear resistance, fatigue strength, and contact stiffness, and is also closely related to the service performance and life of products. Therefore, for precision engineering and manufacturing, accurate measurement techniques for surface roughness have an extremely important position.
[0003] Currently, the existing methods for detecting the surface roughness of workpieces are mainly divided into two categories: contact measurement methods and non-contact measurement methods. Contact measurement methods include impression methods and stylus methods, which are also relatively traditional surface roughness detection methods. Among them, the detection accuracy of the impression method is extremely limited and it cannot capture the minute details of the surface. The stylus method has disadvantages such as high equipment cost, complex operation, wear of the stylus tip, sensitivity to the workpiece surface, and damage to the workpiece surface, resulting in inaccurate and inefficient detection accuracy. Another non-contact measurement method mainly includes speckle contrast method, real-time holography method, optical sectioning method, etc. However, the speckle contrast method, real-time holography method, and optical sectioning method all use lasers as light sources, which will cause disadvantages such as high cost and difficult installation. Therefore, it is extremely important to study the method of using machine vision to detect the roughness of workpieces.
[0004] TSAI et al. conducted in-depth research on surface roughness based on a vision system using a neural network. LEE and TARANG combined an abductive network to extract three features, namely the square of the main frequency amplitude, the standard deviation of grayscale, and the main peak frequency, to construct a model for evaluating the surface roughness value. LIU et al. proposed a method of gray-level co-occurrence matrix support vector machine (GLCM-SVM) using the gray-level co-occurrence matrix to measure the surface roughness of deep holes. The experimental results prove that the GLCM-SVM method has high measurement accuracy and strong generalization ability.
[0005] The usage methods of the above-mentioned literatures will result in a significant decrease in the accuracy for detecting the surface roughness of turning workpieces. For example, when using the gray-level co-occurrence matrix to extract the features of the workpiece surface image, some of the features are not closely related to the roughness of the turning workpiece. Summary of the Invention
[0006] For the detection of the surface roughness of turning workpieces, the present invention provides a GS-BP vision detection method for the surface roughness of turning in order to improve the detection efficiency and accuracy.
[0007] The object of the present invention is achieved by the following technical solutions:
[0008] A vision detection method for the turning surface roughness GS - BP, comprising the following steps:
[0009] Step 1, data acquisition:
[0010] Use an industrial camera to collect the surface image of the workpiece. The specific steps are as follows:
[0011] Step 11, select a suitable industrial camera. According to the surface texture characteristics and dimensions of the turning workpiece, determine the resolution, frame rate, and pixel size of the industrial camera; match the corresponding lens to obtain clear and undistorted images. At the same time, set a suitable light source. By adjusting the angle, intensity, and color of the light source, highlight the features of the workpiece surface and reduce shadows and reflections;
[0012] Step 12, fix the industrial camera on a stable bracket to ensure that the shooting angle of the camera can completely cover the surface of the turning workpiece, and determine the best shooting position and angle according to the shape of the workpiece and the detection requirements;
[0013] Step 2, image pre - processing:
[0014] Perform image pre - processing on the dataset images, including grayscale conversion, binarization, and filtering. The specific steps are as follows:
[0015] Step 21, grayscale conversion: Use the weighted average method to convert the RGB image into a grayscale image. The grayscale conversion formula is as follows:
[0016] Gary(x,y) = 0.299R(x,y)+0.587G(x,y)+0.114B(x,y)
[0017] Step 22, binarization: Assign pixels with grayscale values less than or equal to the threshold to 0 (black), and pixels greater than the threshold to 255 (white);
[0018] Step 23, filtering: Use a filtering algorithm to filter the image;
[0019] Step 3, target area optimization:
[0020] Use mathematical morphology to optimize the target. The specific steps are as follows:
[0021] Dilation operation: Move the center point of the structural element kernel from left to right and from top to bottom in the image to traverse all pixel points in the image. Each time it moves, extract the maximum value of the pixel points within the structural element area and assign the maximum value to the remaining pixel points of the structural element;
[0022] Erosion operation: Move the center point of the structural element kernel from left to right and from top to bottom in the image to traverse all pixel points in the image. Each time it moves, extract the minimum value of the pixel points within the structural element area, and assign the minimum value to the remaining pixel points of the structural element;
[0023] Opening operation: First, remove isolated and small noise points through the erosion operation, and then restore the main features of the workpiece surface through the dilation operation, so as to effectively improve the signal-to-noise ratio of the image and highlight the macroscopic texture and roughness features of the workpiece surface without affecting the true roughness information of the workpiece surface;
[0024] Closing operation: First perform multiple dilation operations on the image and then perform multiple erosion operations, which are used to fill small holes and gaps and connect adjacent images to eliminate scratch defects;
[0025] Step 4. Target differentiation and feature extraction:
[0026] Step 4.1. Target differentiation:
[0027] Combined with the characteristics of mathematical morphology operations, design a linearized image processing operation. The specific steps are as follows:
[0028] According to the surface texture of the workpiece image, use a rectangular structural element. Determine the size of the rectangular structural element according to the image size. After determining the structural element, traverse the original image from left to right with the structural element. Each time it moves, extract the number of pixel values of 0 within the structural element, and at the same time compare the number with the total number of pixel points within the structural element area. If it exceeds a certain threshold, assign all pixel values within the structural element to 0;
[0029] Step 4.2. Feature extraction:
[0030] Extract the number of lines and the distance between lines as features. The specific steps are as follows:
[0031] Use the cv2.boundingRect function to obtain the bounding rectangle of each contour and return the coordinates of the upper left corner of the rectangle (x,y) , by judging whether the height H of the rectangle is greater than 1 to ensure that what is detected is a line rather than a single pixel point. Finally, calculate the number of lines, the average value of the distances between lines, and the median value of the line distances as the extracted features;
[0032] Step 5. Build a neural network prediction model:
[0033] Step 51. Determine the basic structure of the BP neural network:
[0034] The basic structure of the BP neural network includes an input layer, a hidden layer, and an output layer. The number of units in the input layer is 3, the number of units in the hidden layer is 4 - 13, and the number of units in the output layer is 1;
[0035] Step 52: Use grid search to adjust the learning rate, activation function, and number of hidden layer nodes in the model, and determine that the optimal parameters of the neural network prediction model are as follows: the optimal number of nodes in the hidden layer is 5, the learning rate is 0.1, and the activation function is Tanh;
[0036] Step 6: Use the BP neural network optimized by grid search to identify the roughness of the turned workpiece, with the number of characteristic wave peaks, the average value and the median value of the distance from the wave peaks to the wave valleys as the inputs.
[0037] Compared with the prior art, the present invention has the following advantages:
[0038] 1. The present invention solves the problem of damage to workpieces caused by contact measurement, as well as the problems of high environmental requirements and high costs of other non-contact measurements, and can achieve the advantages of simple operation, rapid detection, and low cost.
[0039] 2. Compared with the convolutional neural network, the method of the present invention is more simple and the recognition is more accurate.
[0040] 3. The linearized image processing and GS-BP network model mentioned in the present invention provide a reference for solving engineering practical problems.
[0041] 4. The present invention proposes a brand-new feature extraction method, which has good robustness and is not affected by surface defects and impurities of workpieces. At the same time, the grid search algorithm and the BP neural network algorithm are combined as a model for training, and the accuracy of the prediction result reaches 97.6%, and the single prediction time is only 0.006 seconds, showing good results in the detection of turned workpieces. Description of the Drawings
[0042] Figure 1 It is a flow chart of the GS-BP visual detection method for turning surface roughness;
[0043] Figure 2 It is an image of the surface of a turned workpiece;
[0044] Figure 3 It is the effect of grayscale conversion and binarization, (a) grayscale image, (b) binarized image;
[0045] Figure 4 It is a schematic diagram of dilation and erosion operations;
[0046] Figure 5 It is a GUI for adjusting linearization parameters;
[0047] Figure 6 It is the image processing result after adjusting the linearization parameters, (a) original image, (b) processed image;
[0048] Figure 7is the schematic diagram of turning;
[0049] Figure 8 is the schematic diagram of linearization operation;
[0050] Figure 9 is the structure diagram of BP neural network;
[0051] Figure 10 is the convergence curve of training loss;
[0052] Figure 11 is the comparison chart of predicted value and actual value. Specific implementation manners
[0053] The technical solution of the present invention will be further described below in conjunction with the accompanying drawings, but it is not limited thereto. Any modification or equivalent replacement of the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention shall be covered by the protection scope of the present invention.
[0054] The present invention provides a visual inspection method for turning surface roughness GS-BP. First, analyze and identify the regular texture on the workpiece surface, use an industrial camera to collect the workpiece surface image to make a data set, and then perform image processing operations on the data set. For the bright and dark differences shown by the texture under the illumination of the light, perform depth binary processing, extract the workpiece surface texture based on the number of straight black pixels, and finally analyze through the GS-BP neural network to obtain the surface roughness of the workpiece. As Figure 1 shown, the specific steps are as follows:
[0055] Step 1. Data collection:
[0056] Analyze and identify the regular texture on the workpiece surface, and use an industrial camera to collect the workpiece surface image. The specific steps are as follows:
[0057] Step 11. Select a suitable industrial camera, and determine parameters such as the resolution, frame rate, and pixel size of the industrial camera according to the texture characteristics and dimensions of the turning workpiece surface; match corresponding lenses, such as fixed-focus lenses, zoom lenses, or telecentric lenses, to obtain clear and undistorted images. At the same time, set a suitable light source, such as a ring light source, a backlight source, or a bar light source, and by adjusting the angle, intensity, and color of the light source, highlight the features of the workpiece surface and reduce shadows and reflections.
[0058] Step 12. Fix the industrial camera on a stable bracket to ensure that the shooting angle of the camera can completely cover the surface of the turning workpiece. You can choose to shoot from the front, side, or inclined angle, and determine the best shooting position and angle according to the shape of the workpiece and the detection requirements.
[0059] Step 2. Image preprocessing:
[0060] Industrial cameras are prone to interference from factors such as the environment when acquiring images, resulting in noise on the surface of the workpiece. And during the turning process, due to factors such as the errors of the lathe, there are defects such as scratches and holes on the workpiece, as Figure 2 shown. To address the above problems, eliminate the interference factors in the workpiece image, and perform image preprocessing on the image.
[0061] To simplify the image information, the images in the dataset are grayscaled. In the field of image processing, an image can be regarded as a two-dimensional array, and each point in the image corresponds to an amplitude value, which is the gray value of the image. The images in the dataset used in the experiment are all RGB images, which are composed of three components: R (red), G (green), and B (blue). The weighted average method is used to convert the image into a grayscale image. The weights used are based on the different sensitivities of the human visual system to the R, G, and B components. The red, green, and blue channel values are multiplied by the corresponding weights of 0.30, 0.59, and 0.11 respectively, and then summed to obtain the gray value. Through this, the color image is converted into a black-and-white image. The grayscaling formula is as follows:
[0062] Gary(x,y) = 0.299R(x,y) + 0.587G(x,y) + 0.114B(x,y)
[0063] There are scratches and holes generated during the manufacturing process in the workpiece image. Therefore, the binarization method is adopted. The optimal binarization threshold is determined through multiple experiments. The pixels with gray values less than or equal to the threshold are assigned a value of 0 (black), and the pixels greater than the threshold are assigned a value of 255 (white). Through a reasonable binarization threshold, the data volume of the image can be greatly reduced, reducing the complexity of subsequent processing, facilitating computer storage, analysis, and processing. It can clearly separate the target object in the image from the background, thereby highlighting the target features and facilitating feature extraction. The grayscaling and binarization effects are as Figure 3 shown.
[0064] Filtering process: Images are affected by various noises during the processes of acquisition, transmission, and storage, such as salt-and-pepper noise, Gaussian noise, etc. Filtering can reduce these noises by smoothing the image, improve the quality and visual effect of the image, make the image clearer, and facilitate subsequent analysis and processing. By selecting an appropriate filter, specific frequency components in the image can also be enhanced, thereby highlighting certain features of the image. For example, a high-pass filter can highlight the edge and detail information in the image, which is helpful for target recognition and contour extraction; a low-pass filter can smooth the image and highlight the low-frequency information in the image, which is used to remove noise and retain the general image structure. Common filtering algorithms include Gaussian filtering, median filtering, mean filtering methods, etc.
[0065] The image after filtering processing can be evaluated by Peak Signal-to-Noise Ratio (PSNR). Peak Signal-to-Noise Ratio is an objective evaluation index used to measure the image quality, and is often used to evaluate the difference between the image after compression, filtering or other processing and the original image. The specific formula is as follows.
[0066]
[0067] In the formula, MSE is the mean square error; I is the original image; K is the processed image; M×N is the image size (M is the number of rows of the image, N is the number of columns of the image); MAX I represents the maximum value of the pixel points in image I.
[0068] Step 3. Target area optimization:
[0069] There are still errors such as small-area holes and noise points in the dataset after grayscale and binarization processing. Therefore, mathematical morphology is used to optimize the target.
[0070] Mathematical morphology is a discipline based on set theory, which analyzes and describes the geometric shapes in images based on structural elements. The application of mathematical morphology can optimize the shape features of images and remove irrelevant structures. Its basic operations are 4 types, namely dilation operation, erosion operation, opening operation and closing operation. Commonly used structural elements include rectangle, L shape, cross shape. The dilation operation is to move the center point of the structural element kernel from left to right and from top to bottom in the image to traverse all pixel points in the image. Each time it moves, it extracts the maximum value of the pixel points within the structural element area and assigns the maximum value to the remaining pixel points of the structural element. The erosion operation is the opposite, which is to extract the minimum value for assignment operation. The schematic diagrams of the dilation operation and the erosion operation are as Figure 4 shown.
[0071] The opening operation and the closing operation are composed of different combinations of the erosion and dilation operations. The opening operation is to erode first and then dilate, which is used to remove unimportant small areas in the image; the closing operation is to dilate first and then erode, which is used to fill and connect small holes or discontinuities. There are some tiny protrusions or impurities on the surface of the turning workpiece, which are regarded as noise in visual inspection, and there are also irregularities. The opening operation can first remove isolated and smaller noise points through the erosion operation, and then restore the main features of the workpiece surface through the dilation operation, so as to effectively improve the signal-to-noise ratio of the image and highlight the macroscopic texture and roughness features of the workpiece surface without affecting the true roughness information of the workpiece surface, making the subsequent roughness analysis more accurate.
[0072] After the above image processing, defects such as holes, scratches, and impurities still exist in the image. To eliminate interference information and only retain the surface texture of the turned workpiece, the image is binarized and subjected to mathematical morphology operations, and a simple image processing platform GUI is built. The interface is as shown in Figure 5 as follows.
[0073] First, the image is dilated and then eroded. The main function is to fill small holes and gaps and connect adjacent images to eliminate scratch defects. Initially, the image was processed using the default closing operation based on experience. However, the closing operation only performs one dilation and then one erosion, and the single closing operation has a relatively light effect. Repeating it multiple times will cause the loss of surface texture features of the turned workpiece. Therefore, multiple repeated dilation operations are performed followed by multiple erosion operations. The structuring element traverses the image from left to right using a 5000×10 rectangle according to the image size, and the straightening threshold is 0.5.
[0074] When processing multiple images, using the same parameters for turned workpieces with different roughnesses will result in misidentification of features in the obtained images. For example, the image obtained by processing a roughness of Ra0.8 using the above parameters is as shown in Figure 6 as follows.
[0075] The unreasonable parameters lead to the miselimination of features in the image. An overly high binarization threshold will strengthen the presence of the wave troughs (black areas), resulting in a completely black image; too many dilation times will cause the wave peaks (white areas) to expand outward, resulting in a completely white image; too many erosion times will cause the loss of details, resulting in the disappearance of finer lines in the image; an overly wide width of the structuring element will cause the black areas in the image to stick together; and the straightening threshold determines whether the area covered by the structuring element is a wave trough. Therefore, after processing the images with multiple different parameter combinations for different roughnesses, reasonable parameter combinations are obtained for images with different roughness values, as shown in Table 1.
[0076] Table 1 Image processing parameters
[0077]
[0078] After processing the image in the above manner, only the surface texture features of the turned workpiece are retained in the image, and there are no defects or interference factors.
[0079] Step 4. Target differentiation and feature extraction:
[0080] Step 4.1. Target differentiation:
[0081] The surface roughness of the turned workpiece is mainly determined by the turning parameters (tool nose radius, cutting speed, feed rate, depth of cut). The residual height of the machined surface is the best obtainable surface roughness and can best characterize the surface quality of the workpiece. The residual height of the machined surface in turning can be obtained throughFigure 7 and characterized by the following formula:
[0082]
[0083] In the formula, R max is the height of the residual area; r ε is the nose radius; f is the turning feed. When R max << r ε , can be ignored, and the formula is deformed to:
[0084]
[0085] It can be seen from the formula that the turning surface roughness is mainly affected by the nose radius and the turning feed. When the nose radius is determined, the turning feed determines the size of the turning workpiece surface roughness. For the characteristic of regular strip texture on the turning workpiece surface, the wave peaks and valleys with strong correlation with roughness are used as extraction features. Combining the operation characteristics of mathematical morphology, a linearization operation is designed.
[0086] First, according to the surface texture characteristics of the workpiece image, a suitable structural element is selected. It is found by observation that the surface texture of the turning workpiece is strip texture with a certain directionality. It is decided to use a rectangular structural element, which can better match the direction of the turning texture and is helpful for subsequent extraction and analysis of image features. The size of the rectangular structural element is determined by the image size. When the image size is large, a larger-sized structural element is correspondingly selected, so that more image information can be processed in one operation and the operation efficiency can be improved; when the image size is small, a smaller-sized structural element is used to capture the local features of the image more carefully. After determining the structural element, the structural element is traversed from left to right on the original image. Each time it moves, the system will extract the number of all pixel values of 0 in the structural element, and at the same time compare the number with the total number of pixel points in the structural element area. If it exceeds a certain threshold, all pixel values in the structural element will be assigned 0. The schematic diagram of the linearization operation is shown in Figure 8 . After linearization, the image only retains the wave peaks and valleys of the turning workpiece, and completely eliminates the defects such as holes and scratches in the turning workpiece image.
[0087] Step 4.2: Feature extraction:
[0088] In the research scope of image science, image feature extraction is a very challenging and significant topic. From a theoretical level, it aims to reveal the internal structure and semantic information of the image through a rigorous mathematical model and algorithm system.
[0089] After the above image processing, the number of straight lines and the distances between the straight lines contained in the images of workpieces with different roughnesses are different. Therefore, the number of straight lines and the distances between the straight lines are extracted as features. The cv2.boundingRect function is used to obtain the bounding rectangle of each contour and return the coordinates (x, y) of the upper left corner of the rectangle. This function mainly uses the Suzuki85 algorithm to find the boundaries composed of continuous white pixel points, and these boundaries can outline the shapes of the objects in the image. By judging whether the height H of the rectangle is greater than 1, it is ensured that the detected object is a straight line rather than a single pixel point. Finally, the number of the upper left corner coordinates and the distances between them are calculated as the extracted features. During the processing of the workpiece, some wave peaks may have narrow or long widths due to the vibration of the machine tool or unstable feeding. To eliminate the influence of abnormal values on the training model, when calculating the width of the wave peaks, the values of all wave peak widths are first sorted, and then the median value is taken as the wave peak width feature of the image.
[0090] Step 5: Construct a neural network prediction model:
[0091] The BP neural network (Back-Propagation Neural Network) is a network model with error backpropagation in a forward neural network. Its basic structure includes an input layer, a hidden layer, and an output layer. Its main characteristics are forward signal propagation and error backpropagation. In the present invention, the distances between the characteristic wave peaks and wave valleys extracted after image processing are used as inputs, so the structure includes two input nodes. Designing the number of hidden layer nodes is a complex problem. Due to different network structures and personalized requirements, the empirical formulas for determining the number of hidden layer nodes are also diverse. According to the empirical formulas, the design range of the hidden layer is roughly determined, and finally optimized through grid search. The following are the empirical formulas for determining the number of hidden layer nodes of the BP neural network:
[0092] N H = 2N I + 1 (3)
[0093]
[0094] N H = log2N I (6)
[0095] Among them, N I is the number of units in the input layer; N H is the number of units in the hidden layer; N O is the number of units in the output layer; a takes values from 1 to 10. Let N I be 2, N OSubstituting 1 into the above formula, the approximate range of the number of hidden layer nodes is 4 to 13. Since the experiment requires detecting the surface roughness value of the turned workpiece, the number of output layer units is 1. The BP neural network structure is as Figure 9 shown.
[0096] Grid Search is an algorithm used to adjust the parameters of machine learning models. Grid Search traverses different parameter combinations within the specified parameter range through an exhaustive search method to find the parameter combination that makes the model perform best. For the BP neural network, different hyperparameters such as the learning rate and activation function will greatly affect the accuracy of the model training and prediction results. The present invention uses Grid Search to adjust the learning rate, activation function, number of hidden layer nodes, etc. in the model. Through experience, the optional values of the learning rate are 0.01, 0.05, 0.1, 0.5; the activation functions are Relu and Tanh.
[0097] Create a grid search object. Use GridSearchCV to create a grid search object for finding the best parameter combination on the training set. After training the GS-BP neural network, the best parameters of the model are determined to be that the best number of nodes in the hidden layer is 5, the learning rate is 0.1, and the activation function is Tanh.
[0098] Step 6: Use the number of characteristic wave peaks and the distance between wave valleys as inputs, and use the BP neural network optimized by grid search to identify the roughness of the turned workpiece.
[0099] Embodiment:
[0100] 1. Establish a data set:
[0101] For relevant experiments, use the WST-4KCH measurement industrial camera to collect the surface images of the surface roughness comparison samples as the data set. The experimental conditions for obtaining this data set are shown in Table 2.
[0102] Table 2 Equipment parameters
[0103]
[0104] Under the same environment, collect images of turned workpieces with roughnesses of 0.8, 1.6, 3.2, and 6.3 respectively, and finally obtain 400 images.
[0105] 2. Identification test:
[0106] In the experiment, the number of straight lines and the distance between straight lines were used as input parameters to extract features from the image. In the straightening process, parameters such as the binarization threshold, the number of erosion and dilation operations, and the pixel value ratio need to be determined. To determine the parameters, a parameter adjustment GUI was built to intuitively understand the impact of different parameters on the recognition accuracy and determine the accurate parameters. After multiple parameter adjustments, the binarization threshold was finally determined to be 48, the dilation times were 2, the erosion times were 13, the size of the straightening rectangular structural element was 5000×10, and the straightening threshold was 0.6.
[0107] 3. Model Training
[0108] The training environment was Windows 10, Python 3.8 was used, the graphics card was AMD RX6650XT, and the GS-BP network model was used for training. During the training process, the Adam optimizer was used to improve the calculation efficiency, enabling the model to converge quickly to the optimal solution. After training, the model reached the best convergence after about 100 times, as Figure 10 shown.
[0109] After training with the GS-BP neural network, the best parameters of the model were determined to be that the best number of nodes in the hidden layer was 5, the learning rate was 0.1, the activation function was Tanh, and Alpha was 0.01. Finally, the roughness error curve graph of the turning workpiece was obtained, Figure 11 showing that the recognition accuracy reached 97.35% when the tolerance was 0.5.
[0110] In the experiment, images of four turning workpieces with different roughnesses were collected. At the same time, the roughness values of different regions on the surface of the same workpiece should be different. Therefore, the average value of the numerical values should be taken as the accurate roughness of the workpiece for the results obtained from predicting the workpiece. After the above experiments, from the perspective of the accuracy of detecting the sample set, this method is feasible for turning detection.
Claims
1. A visual inspection method for the turning surface roughness GS-BP, characterized in that The method includes the following steps: Step 1, data acquisition: Use an industrial camera to collect images of the workpiece surface; Step 2, image preprocessing: Perform image preprocessing on the dataset images, including grayscale conversion, binarization, and filtering; Step 3, target area optimization: Use mathematical morphology to optimize the target; Step 4, target differentiation and feature extraction: Step 4.1, target differentiation: Design a linearized image processing operation in combination with the characteristics of mathematical morphology operations; Step 4.2, feature extraction: Extract the number of lines and the distance between lines as features; Step 5, construct a neural network prediction model: Step 51, determine the basic structure of the BP neural network: The basic structure of the BP neural network includes an input layer, a hidden layer, and an output layer. The number of units in the input layer is 3, and the number of units in the hidden layer is 4~13 , and the number of units in the output layer is 1; Step 52, use grid search to adjust the learning rate, activation function, and number of hidden layer nodes in the model, and determine that the optimal parameters of the neural network prediction model are: the optimal number of nodes in the hidden layer is 5, the learning rate is 0.1, and the activation function is Tanh; Step 6, use the number of characteristic wave peaks, the average value and the median value of the distance between wave valleys as inputs, and use the BP neural network optimized by grid search to identify the roughness of the turned workpiece.
2. The visual inspection method for turning surface roughness GS-BP according to claim 1, wherein The specific steps of Step 1 are as follows: Step 11, select a suitable industrial camera, and determine the resolution, frame rate, and pixel size of the industrial camera according to the surface texture characteristics and dimensions of the turned workpiece; match the corresponding lens to obtain clear and undistorted images. At the same time, set a suitable light source to highlight the characteristics of the workpiece surface by adjusting the angle, intensity, and color of the light source, and reduce shadows and reflections; Step 12, fix the industrial camera on a stable bracket to ensure that the shooting angle of the camera can completely cover the surface of the turned workpiece, and determine the best shooting position and angle according to the shape of the workpiece and the detection requirements.
3. The visual inspection method for turning surface roughness GS-BP according to claim 1, characterized in that The specific steps of Step 2 are as follows: Step 21, grayscale conversion: Use the weighted average method to convert the RGB image into a grayscale image. The grayscale conversion formula is as follows: Gary(x,y) = 0.299R(x,y) + 0.587G(x,y) + 0.114B(x,y) Step 22, binarization: Assign pixels with a grayscale value less than or equal to the threshold to 0, and pixels greater than the threshold to 255; Step 23, filtering: Use a filtering algorithm to filter the image.
4. The visual inspection method for turning surface roughness GS-BP according to claim 1, wherein The specific steps of Step 3 are as follows: Dilation operation: Move the center point of the structural element kernel from left to right and from top to bottom in the image to traverse all pixel points in the image. Each time it moves, extract the maximum value of the pixel points within the structural element area, and assign the maximum value to the remaining pixel points of the structural element; Erosion operation: Move the center point of the structural element kernel from left to right and from top to bottom in the image to traverse all pixel points in the image. Each time it moves, extract the minimum value of the pixel points within the structural element area, and assign the minimum value to the remaining pixel points of the structural element; Opening operation: First, remove isolated and small noise points through the erosion operation, and then restore the main features of the workpiece surface through the dilation operation, so as to effectively improve the signal-to-noise ratio of the image and highlight the macroscopic texture and roughness features of the workpiece surface without affecting the true roughness information of the workpiece surface; Closing operation: First, perform multiple dilation operations on the image and then perform multiple erosion operations, which are used to fill small holes and gaps, and connect adjacent images to eliminate scratch defects.
5. The visual inspection method for turning surface roughness GS-BP according to claim 1, characterized in that The specific steps of step 4.1 are as follows: According to the surface texture of the workpiece image, use a rectangular structuring element. Determine the size of the rectangular structuring element based on the size of the image. After determining the structuring element, traverse the original image from left to right with the structuring element. Each time it moves, extract the number of all pixel values of 0 within the structuring element, and at the same time compare the number with the total number of pixel points within the area of the structuring element. If it exceeds a certain threshold, assign all pixel values within the structuring element to 0.
6. The visual inspection method for turning surface roughness GS-BP according to claim 1, wherein The specific steps of step 4.2 are as follows: Use the cv2.boundingRect function to obtain the bounding rectangle of each contour and return the coordinates of the upper left corner of the rectangle (x,y) , by judging whether the height H of the rectangle is greater than 1 to ensure that what is detected is a straight line rather than a single pixel point. Finally, the number of straight lines, the average value of the distances between the straight lines, and the median value of the straight line distances are calculated as the extracted features.
Citation Information
Patent Citations
Surface roughness detection method based on imaging simulation and computing equipment
CN110057325A
Rod-pumped well pump inspection period prediction method based on BP neural network
CN113987933A
Fuel cell modeling method based on BP neural network
CN113988296A
Workpiece surface roughness detection optimization method based on improved histogram homogenization algorithm
CN114972330A
Electric vehicle charging station medium-term load prediction method based on machine learning
CN118336678A