Research on online detection System of lathe tool wear based on Machine Vision


 Machine tools are important factor to determine the surface quality of the workpiece, and the online detection of tool wear is of great significance to the production and processing. In this paper, turning tools are taken as the research object, the tool wear evaluation index is defined, and the online detection system of lathe tool wear based on machine vision is designed. The workpiece processing, tool wear image acquisition, transmission, storage, and processing are completed in this system. Aiming at the problem of tool wear state detection, an adaptive hybrid filtering method is proposed in order to remove noise in the image acquisition process, nonlinear transformation and unsharp masking methods are used to enhance tool wear image quality. The GrabCut improved algorithm is used to segment the tool wear image. The Canny edge detection operator with adaptive double thresholds is used to detect the edge of the tool wear area. Finally, the upper and lower boundaries of the tool wear area are detected by using the Hough transform method, and the wear value of the tool flank is calculated, which is compared with the blunt standard VB=06mm to determine whether the tool needs to be replaced. The accuracy of the detection method is verified by experimental measurement of the surface roughness of the workpiece after machining.

keywords：Introduction The traditional tool wear state detection needs to be judged by experience, or by shutdown measurement. This method is subjective, easy to misjudge, and requires high ability of workers, which is difficult to meet the requirements of intelligent manufacturing.
Tool wear detection methods are divided into two types: direct measurement method and indirect measurement method. The indirect measurement method determines the wear state of machine tools by measuring the cutting force during the machining process, the cutting temperature generated by cutting, machine tool vibration and noise and other processing information. They are studied by various researchers [1][2][3][4] . Although it allows to monitor the tool condition in real time, it is connected with cutting parameters and complicated to deal with.
The common method for tool wear detection is to detect the tool wear state of machine tools by measuring the cutting force, cutting temperature generated by cutting, machine vibration, and noise in the machining process. Since this information cannot strictly correspond to the tool wear, and the installation of sensors is inconvenient, it is easy to be affected by the machining conditions and environment, so there are certain limitations.
The tool wear detection method based on machine vision is a direct measurement method. It uses image processing algorithm to process and analyze the collected tool wear image, and extracts the wear value of the tool wear image, and compare it with the tool blunt standard to determine the tool wear state. This method has the advantages of high detection accuracy and fast speed. Tool wear detection methods based on machine vision include tool wear detection of workpiece surface texture features, tool wear detection of workpiece chip images, and tool wear detection methods of tool knife face images. Wen-Yuh Jyw et al. [5] used machine vision to obtain the texture image of the workpiece surface, and carried out weighting calculation according to the surface texture. The experiment showed that the standard deviation of the workpiece surface texture data result can be used as an indicator of tool replacement. Zhang Peipei et al. [6] established the relationship between the width and bending radius of the workpiece chip and the tool wear value. The experiment shows that as the degree of tool wear increases, the width and bending radius of the chip gradually decrease.
In this paper, the tool wear state is measured by analyzing tool surface image. The image processing technology is used to measure the flank wear width of the tool directly, the depth of the front tooth depression, the length of the cutting edge, and the fillet radius of the tool tip. The tool wear state is judged by comparing with the tool blunt standard.
Guan Shengqi [7] used Gaussian filtering and Gaussian difference filtering to process the tool wear image. Through the center-peripheral operation between the Gaussian filter map and the Gaussian difference filter map, a significant image of tool wear was formed to achieve wear image enhancement. Peng Ruitao [8] used the CCD camera to collect the tool wear images, established wear boundaries through image preprocessing, threshold segmentation, edge detection based on Canny operator and sub-pixels, and extracted milling machine tool wear. Qing Guohua [9] used Otsu and spline curve fitting method to enhance the contrast of wear area and background area, and realized the segmentation and calculation of tool wear area by adaptive variance threshold method and morphological description method. Liao Yusong and Han Jiang [10] used a Canny operator to detect the edge of tool wear area and used pixel distribution continuity judgment method to remove the false edge points in the edge of tool wear image, and realized the edge extraction of tool wear area. Guan Shengqi [11] carried out gray transform and wavelet single layer transform on the tool wear image to eliminate the influence of uneven illumination. The filtered tool wear image was standardized and fused. The interclass variance method was used to segment the tool wear image, and the tool wear detection was realized.
JinLin Zhang [12] proposed a machine vision-based end mill wear detection system, which extracts the edge of the tool wear area through column scanning, finds the correct edge position in each wear column, uses sub-pixel edge detection technology for edge extraction, and reconstructs the wear area Obtain the wear value of the upper and lower edges. Qiulin Hou [13] used the adaptive connection domain marking method for edge separation, and used the threshold method to extract the cutting edge and calculate the tool wear. The experiment shows that this method can quickly and effectively detect tool wear with high detection accuracy. Jamie Loizou [14] proposed a broach wear measurement method, which quantifies the wear of the broaching tool according to the total wear area, making the measurement of broach wear more accurate.
Extensive research has been conducted for the tool wear measurement method.
Although they have done extensive researches about the tool wear detection based on machine vision and made great process, there is a long way to go. Few researches have been done in lathe tool field. In this paper, a lathe tool wear detection system based on machine vision is proposed.
The rest of the paper is organized as follows. Sec. 2 introduces the high-quality acquisition method of lathe tool wear images, including the selection of the camera and the key technology of the acquisition system. Tool wear image processing includes image noise reduction, image enhancement, area segmentation, edge detection, determination of tool wear boundaries, and the calculation method of tool wear value are introduced in Sec. 3. Sec.4 establishes a lathe tool wear detection system, and conducts experiments to verify the detection results by measuring the surface roughness of the workpiece. Finally, Sec. 5 summarizes the research results done in this article.

Tool wear evaluation index
When tool is worn to a certain limit, it cannot continue to be used, this wear limit is the tool blunt standard. According to ISO, on the tool flank face, the wear band width VB of 1 / 2 depth of cut is used as the blunt standard of tool. General tool grinding blunt standard [15] is shown in table 2-1. Table 2-2 is tool bluntness standards recommended by ISO [16] .

High quality image acquisition technology for tool wear
The process of image acquisition generally uses the optical imaging module to image the object under the auxiliary illumination of an appropriate external light source.
The position and angle of the object or the focal length of the imaging equipment are adjusted to be clear, and the image of the object is converted to digital image information, which is transmitted to the computer for image processing. information is widely used. The commonly used gradient evaluation function is to extract the edge and contour information of the image and construct the evaluation function after differential operation. The commonly used gradient evaluation functions include Sobel operator, Laplacian operator, and variance evaluation function [17] .
Four different resolution tool images are given in      The sharpness evaluation function is that the larger the data index, the clearer the image is. The statistics of sharpness evaluation are shown in Table 2-3. Therefore, in the actual shooting of the tool image, the focus of the camera is adjusted manually to shoot the tool wear image, and the sharpness evaluation function is used to calculate the sharpness index of the image. The camera focal length is adjusted to make the sharpness index of the tool image maximum, and the camera focal length is selected to collect the tool wear image.

Measurement error analysis of tool wear image
There is a certain deviation between actual imaging and theoretical imaging, which is called lens distortion. Lens distortion is generally divided into three kinds, radial distortion, eccentric distortion, and thin prism distortion.

Noise reduction of tool wear image using adaptive hybrid filtering
Due to the complexity of the workshop working environment, the collected tool image is often interfered by noise from the external environment and the internal structure of the imaging equipment. These noises can usually be divided into two categories, one is salt and pepper noise, and the other is Gaussian noise [18] . Therefore, it is necessary to denoise tool image. Median filtering is a nonlinear filtering algorithm [19] . It has an excellent filtering effect on noise interference and can protect image details.
At the same time, Gaussian noise is often accompanied in the process of image acquisition and transmission, so it is necessary to use Gaussian filtering for tool image denoise.
In this paper, adaptive mixed filtering is used. Adaptive mixed filtering includes Gaussian filtering and adaptive median filtering. Adaptive median filtering can adaptively change the size of the template, which can not only ensure an excellent smoothing effect, but also ensure the edge of the image. The adaptive median filter has a window of xy S , and the size of this window will change in the filtering process. The output of the filter is a pixel value, and an intermediate value ( , ) xy is used to replace the value of the window center.
The adaptive hybrid filtering process is shown in Fig 3-2. The median filter has an outstanding effect on salt-pepper noise suppression, but the median filter with a smaller kernel has an insufficient suppression effect. The median filter with a larger kernel will cause image blur and cannot suppress Gaussian noise well. Gaussian filtering combined with median filtering still has the above problems.
Adaptive mixed filtering can suppress Gaussian noise and salt-pepper noise, and adaptive median filtering can adjust the size of the template, almost no image blur, so the filtering effect is the best.

Tool wear image enhancement based on nonlinear transformation and anti-sharpening mask
After noise reduction, the tool wear image will change the gray value of the image, resulting in changes in the contrast and edge information of the image, and the image becomes blurred. To improve the overall visual effect of the image, it is necessary to enhance the tool wear image. The Gamma correction method is used.

Image enhancement based on Gamma and nonlinear transform
The transformation formula for Gamma correction is: Where A is a constant and  is a correction coefficient.
Gamma correction adjusts the contrast of the image by selecting the appropriate correction coefficient, which can be used to improve the image details and make the visual effect of the image better. In order to suppress some high-brightness regions, strengthen the low-brightness part, and enhance the image balance, the nonlinear transformation is adopted for the image. The definition of nonlinear transformation is: Among them, ( , ) v x y is the gray value of ( , ) xy point in the image, a is the adjustment coefficient,

Tool wear region segmentation based on GrabCut improved algorithm
After the image is denoised and enhanced, the tool wear area needs to be segmented for tool wear edge detection. Traditional image segmentation methods include a threshold-based segmentation method, an edge-based segmentation method, a region-based segmentation method, and a graph-based segmentation method [20] .
GrabCut algorithm is based on the graph theory combination optimization method, and the segmentation effect is better. The process of the GrabCut algorithm segmentation image is shown in Fig 3-8. The traditional GrabCut algorithm is sensitive to the initial value, and it is difficult to meet the needs of engineering. If the framed part of the image is a non-convex polygon, the algorithm will select additional information. Although redundant background can be eliminated by multiple iterations, the segmentation efficiency is reduced. The Improved K-means clustering algorithm is proposed to deal with the presegmentation of image [21] in order to improve the segmentation efficiency of GrabCut.
2.3.1 Improved K-means clustering algorithm K-means clustering algorithm is used to divide samples into different classes according to the similarity of sample data, and its basic process is shown in Fig 3-9.
The selection of the K value of the traditional K-means clustering algorithm depends on experience or is determined by the successive incremental method, which is too subjective or inefficient to meet the requirements. The improved K-means clustering algorithm can obtain a better clustering effect and better image pre-segmentation effect. The algorithm uses the inflection point method to determine the value [22] , and the outlier factor to determine the clustering center [23] .

Optimal K value selection
By selecting different K values, the SSE (within-cluster sum of squared errors) corresponding to different K values is calculated, and the relationship curve between SSE and K is drawn, and the K value corresponding to the curve ' inflection point ' is found. The inflection point is determined by the slope of the curve. As the number of data points in the cluster center increases, similarity sample data gather together, and the variance of the data in the same cluster is getting smaller and smaller. According to the relationship curve between SSE and K value, when the K value increases to a certain extent, the slope of the sample changes sharply. This sharp change point is called the inflection point.

Determination of cluster centers by outlier factor optimization algorithm
Clustering algorithm divides the same class or similar objects into the same cluster.
The data in the same cluster are as similar as possible, and the difference between different clusters is as large as possible. In the same cluster, the cluster center with more data points and the outlier with less data points. For outliers, try to avoid such data as the initial cluster center. Fig 3-10. Data points with similar characteristics will gather in a certain area and form clusters, such as 1 C and 2 C , and data points without similar characteristics will be far away and form isolated points, such as 1 D and 2 D .

Fig 3-10 Clusters and isolated points
The goal of the outlier factor algorithm is to calculate the outlier factor of each data point, arrange the data according to the outlier factor, and select the data with the furthest distance as the initial clustering center.
By Comparing with the traditional K-means clustering algorithm, the improved K-means clustering algorithm has a better clustering effect. It lays the foundation for the image segmentation method which integrates K-means clustering algorithm and GrabCut algorithm.

Tool wear region segmentation based on GrabCut improved algorithm
The image processed by the improved K-means clustering method is used as the input of the GrabCut segmentation algorithm [24] . The clustering method is used to mark the wear area, and then the GrabCut algorithm is used for segmentation. It can reduce manual interaction and improve the efficiency and accuracy of tool wear image segmentation.

Image segmentation process based on GrabCut improved algorithm
The flow chart of image segmentation based on the improved GrabCut algorithm is shown in Fig 3-11. between SSE and K value can be obtained. It is shown in Fig 3-12. According to the inflection point inflexion method, the slope of the K value decreases sharply from 1 to 2, and then the slope tends to be stable. Therefore, the point with the K = 2 is called the inflection point, and then the K = 2.  The accuracy and recall rate of the traditional GrabCut segmentation algorithm are low, and some non-wear areas are divided into wear areas, which cannot segment the tool wear area completely and accurately. It also requires manual interaction and has low efficiency. The improved GrabCut algorithm uses a clustering algorithm to classify foreground and background, and takes the classification results as the input of the GrabCut algorithm without manual interaction. When K = 2, the accuracy and recall of our algorithm has high accuracy and recall, and has a perfect segmentation accuracy.

Edge detection of tool image based on adaptive dualthreshold Canny operator
After the image is segmented, the gray level of pixels in the tool wear area and image background area has a step change, and the wear boundaries is obtained by the image edge detection method. Edge is a extremely important feature of the image, and it is one of the most important information to distinguish the target area and the background area. In the process of tool wear detection, it is greatly important to obtain complete edge information, which is the prerequisite for accurate calculation of tool wear value.
The detection process of Canny edge detection operator is shown in Fig 3-16. The double thresholds 1 T and 2 T in the traditional Canny edge detection operator needs to be set manually, which has strong subjectivity and poor adaptability [25] . An adaptive threshold Canny edge detection algorithm is proposed, which can automatically select the appropriate double thresholds to achieve the purpose of automatic image edge detection.
The Otsu algorithm (Otsu) is adaptive threshold selection method. The algorithm makes the image have the best separation by selecting the optimal threshold. However, in the Otsu method, it is easy to filter out some small edges in the process of calculating the mean value. An improved method is used which can use the gradient variance to reflect these details. The implementation process is: (1)Calculation of gray level probability ( , ) f x y denotes as the gray value of point ( , ) xy on the image. The gray level of the point on the image is distributed between 0 and L. The image size is MN  , and the number of pixels S with gray level Then the probability () pi of the appearance of a pixel with a gray level of i in pixels is: (2)Calculation of inter class variances By selecting a reasonable threshold k, the pixels in the image is divided into two part, the target region O and the background region B, then these values can be calculated: The formula of Otsu algorithm to find the optimal threshold of an image is: (3)Calculation of optimal threshold k Since the between-class variance is a function of threshold value K, the maximum between-class variance can be determined according to the threshold value K. In the Otsu method, it is easy to filter out some small edges in the process of averaging. The gradient variance can be used to reflect these details. The optimal threshold can be expressed as the gradient variance: The highest threshold value 2 K can be obtained by the above formula, and the lowest threshold value 12 0.4 KK = can be obtained by the estimation formula of Canny operator. After two high and low thresholds 1 K and 2 K are determined, the image is divided into three regions 0 A , 1 A and 2 A , which are expressed as: In the formula, region 2 A is identified as the edge of the image, region 0 A is identified as the non-edge region of the image, which will be discarded, and region 1 A is those points to be determined. If these points can be connected to the edge, they can be retained, otherwise they will be discarded.

Determination of tool wear boundaries by Hough transform curve fitting
After detecting the complete edge of the tool wear area, it is necessary to accurately locate the upper and lower boundaries of the tool wear area. Using the boundary distance, the tool wear value can be calculated according to the pixel value of the upper and lower boundaries of the wear area based on the camera calibration results. Hough transform is one of the commonly used methods for processing geometric shapes of planar images, which is widely used in machine vision and image processing [26] .
The Hough transform is ultimately to detect the number of intersecting curves corresponding to each point in the image. If the number exceeds the set threshold, it can be considered that the intersection corresponds to a straight line on the image. The linear detection steps of the transform are as follows: (1)In the parameter space ( , ) H  ,  represents the distance from the pole to the straight line, and is the angle between the straight line and the polar coordinate.
Divide the parameter space into * mn units, where  is divided into m equal parts,  is divided into n equal parts, and set the accumulator ( , ) mn Q  for each unit and set it to 0; (2)For each point ( , ) xy on the image boundaries,  corresponding to each  is calculated according to the linear polar coordinate equation, and the corresponding unit of ( , )  is found out, and the corresponding accumulator

Establishment of experimental environment
The hardware of the lathe tool wear detection system includes a CNC lathe, image acquisition system, and computer, which mainly completes the machining process of the tool, the acquisition, transmission, and storage of the tool wear image. Software functions include tool wear image acquisition, processing and tool wear state detection.
In the actual machining process, the workpiece is fixed on the three-claw chuck and rotates with the spindle at high speed. The tool is fed horizontally on the tool holder.
The axis of the camera is perpendicular to the surface of the tool to be photographed.
After each tool feed is completed, the tool returns to the specified position to collect the tool image. The experimental process of tool wear detection is as follows: (1)After each machining , the tool is retreated to the designated location. The image acquisition system is used to collect the wear image of the tool flank, and the surface roughness of the workpiece is measured after four times cutting.
(2)After each acquisition of tool wear image, the image is transmitted and saved to the computer, and the software is used for subsequent image processing; ( 3 ) After processing the tool wear image, the detection algorithm decides whether to change tool according to the result of tool wear detection and gives the tool change information.
The tool wear detection system for lathes is shown in Fig 4-1.

Analysis of Tool Wear Test Results
The corresponding wear value is calculated by using the camera calibration results.
According to the detection results of the upper and lower wear boundaries of the tool with different machining times, each pixel represents, For example, (a) in Fig 3-21. The detection value of the upper and lower wear boundaries of the tool is 12, and the tool wear value is 12*0.0114 0.14 VB mm mm = . The roughness tester is used to measure the surface roughness of the workpiece after the corresponding cutting times. The obtained tool wear image detection results are shown in Table 4-2. , the detection value of tool wear is not more than 0.6mm . Therefore, when the tool is used to process 240 times, the tool wear value exceeds the blunt standard. At this time, although the surface roughness of the workpiece meets the surface quality requirements of 1.6 m  , the tool state is in the later stage of wear. The tool wear is relatively fast. Continue processing, the surface roughness of the workpiece may exceed 1.6 m  , which will lead to the scrap of the workpiece and not meet the processing requirements. Therefore, the tool is replaced in time before 240 times processing.

Summary
Tool wear on-line detection is a key technology to realize intelligent The experimental results show that when the tool is processed 240 times, it exceeds the blunt standard, and the tool needs to be replaced in time.