A machine vision-based tool detection method for CNC equipment

Through adaptive threshold selection algorithm and machine vision technology, the detection inaccurate problem caused by improper threshold selection in tool detection in CNC equipment is solved, real-time online detection and diagnosis of tool defects is realized, and the accuracy and stability of detection are improved.

CN118967687BActive Publication Date: 2024-12-31ZHEJIANG ADVANCED CNC MASCH TOOL TECH INNOVATION CENT CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411448096.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-17
Publication Date
2024-12-31
Estimated Expiration
2044-10-17

AI Technical Summary

Technical Problem

In the tool detection of CNC equipment in machine vision, the selection of thresholds too high or too low will lead to inaccurate image segmentation results, affect tool parameter measurement and defect identification, and lead to missed or missed detection of detection.

Method used

Adaptive threshold selection algorithm is used to capture tool images of CNC equipment, extract texture and edge features, and construct image feature vectors. Combined with prior knowledge, the minimum cross entropy method is used to optimize the initial threshold, and the adaptive segmentation threshold is obtained and binary is performed. Segmentation and contour extraction, input pre-trained detection models for defect identification and classification.

Benefits of technology

Real-time online detection and diagnosis of tool defects is realized, the accuracy and stability of detection is improved, and the reliability and product quality of CNC processing is ensured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118967687B_ABST
    Figure CN118967687B_ABST
Patent Text Reader

Abstract

The present invention provides a machine vision CNC equipment tool detection method, comprising: S1, photographing a CNC equipment tool image and preprocessing it to obtain a preprocessed image; S2, extracting the texture and edge features of the preprocessed image, and constructing a tool image feature vector based on the texture and edge features; S3, determining an initial threshold for image segmentation based on the tool image feature vector and prior knowledge, optimizing the initial threshold through an optimization algorithm, and obtaining an adaptive segmentation threshold; S4, performing binary segmentation on the preprocessed image based on the adaptive segmentation threshold and extracting the tool contour to obtain a tool binary image; S5, performing contour extraction and parameter measurement on the tool binary image to obtain tool geometric parameters, and constructing a tool parameter feature vector based on the geometric parameters; S6, inputting the tool parameter feature vector into a pre-trained detection model to perform tool defect recognition and classification to obtain a detection result. The tool defect online detection and diagnosis are realized, and the recognition accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of numerical control equipment detection, and in particular to a method for detecting a tool of a numerical control equipment using machine vision. Background Art

[0002] In the tool detection of CNC equipment in machine vision, threshold technology is often used for image segmentation and defect detection. However, selecting too high or too low a threshold may lead to missed or false detection of tool defects. The cracking of the threshold will make the image segmentation result inaccurate, affecting the subsequent tool parameter measurement and defect identification. Therefore, it is necessary to study the adaptive threshold selection algorithm, dynamically adjust the threshold according to the characteristics of the tool image, and improve the stability and accuracy of tool detection. Summary of the invention

[0003] Technical issues to be solved

[0004] In view of this, the embodiments of this specification provide a tool detection method for CNC equipment using machine vision with high accuracy and strong stability.

[0005] Technical Solution

[0006] To solve the technical problem, the present invention provides the following technical solutions: a machine vision CNC equipment tool detection method, comprising the following steps: S1, photographing a CNC equipment tool image and preprocessing it to obtain a preprocessed image; S2, extracting texture and edge features of the preprocessed image, and constructing a tool image feature vector based on the texture and edge features; S3, determining an initial threshold for image segmentation based on the tool image feature vector and prior knowledge, optimizing the initial threshold through an optimization algorithm, and obtaining an adaptive segmentation threshold; S4, binarizing and segmenting the preprocessed image based on the adaptive segmentation threshold and extracting the tool contour to obtain a tool binary image; S5, performing contour extraction and parameter measurement on the tool binary image to obtain tool geometric parameters, and constructing a tool parameter feature vector based on the tool geometric parameters; S6, inputting the tool parameter feature vector into a pre-trained detection model to perform tool defect recognition and classification to obtain a detection result; in step S3, using the minimum cross entropy method, constructing a foreground and background probability model based on the tool image feature vector and prior knowledge, and obtaining the optimal segmentation threshold as the initial threshold by minimizing the cross entropy iterative optimization.

[0007] In some embodiments, in step S1, a median filtering algorithm is used to perform denoising on a CNC equipment tool image to obtain a denoised image; and a histogram equalization algorithm is used to perform enhancement on the denoised image to obtain an enhanced image.

[0008] In some embodiments, in step S2, a gray-level co-occurrence matrix algorithm is used to obtain statistics reflecting the texture features of the preprocessed image, the statistics including contrast, correlation and entropy, and a texture feature vector is formed based on the statistics; edge detection is performed on the preprocessed image using the Canny operator to obtain the tool contour edge, and the directional gradient histogram of the tool contour edge is calculated to obtain the directional gradient histogram vector of the tool edge feature; the texture feature vector and the directional gradient histogram vector are fused to obtain the tool image feature vector.

[0009] In some embodiments, the method for fusing texture feature vectors and directional gradient histogram vectors includes: adopting a feature-level fusion strategy to fuse the texture feature vectors and directional gradient histogram vectors by weighted averaging to obtain a comprehensive tool image feature vector, and the weight coefficient of the weighted average is adaptively adjusted according to the contribution of each feature to tool defect recognition.

[0010] In some embodiments, the method for obtaining a tool image feature vector includes: using principal component analysis to reduce the dimension of the comprehensive tool image feature vector, extracting the top N principal components that contribute most to tool defect identification, and forming a reduced-dimensional tool image feature vector as the required tool image feature vector.

[0011] In some embodiments, in step S3, the method of optimizing the initial threshold through the optimization algorithm includes: using a genetic algorithm to generate new candidate thresholds through crossover and mutation operations, and calculating the objective function value corresponding to each candidate threshold; according to a preset fitness function, selecting a threshold with high fitness from the candidate thresholds as an excellent individual, and eliminating the candidate thresholds with low fitness to obtain a new generation of candidate thresholds; when the convergence condition is reached, the candidate threshold with the best objective function value among the current candidate thresholds is used as the segmentation threshold optimized by the genetic algorithm; the segmentation threshold optimized by the genetic algorithm is used as the initial particle position of the particle swarm optimization algorithm, and the objective function value is used as the fitness function, and the segmentation threshold is further optimized and searched by updating the particle's speed and position; and the particle position with the best fitness function value is obtained as the final adaptive segmentation threshold.

[0012] In some embodiments, in step S6, the method for obtaining a pre-trained detection model includes: training a support vector machine based on a pre-labeled tool defect sample data set to obtain a pre-trained detection model.

[0013] Beneficial Effects

[0014] Compared with the prior art, the present invention has the following advantages and technical effects: the present invention obtains the original image of the tool and performs preprocessing, extracts texture and edge features to construct a feature vector, combines prior knowledge of the tool, uses the maximum inter-class variance method to determine the initial threshold, and then searches for the optimal threshold through an optimization algorithm for adaptive segmentation, extracts contours and geometric parameters from the segmented binary image, and inputs a pre-trained machine learning model for defect recognition and classification, thereby realizing real-time online detection and diagnosis of tool defects, and continuously improving recognition accuracy through continuous data accumulation and model optimization, effectively ensuring the reliability and product quality of CNC machining, and improving the stability of CNC machining. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0016] Figure 1 A flow chart of a method for detecting a tool of a numerical control device according to an embodiment of the present invention;

[0017] Figure 2 is a method flow chart of step S2 of an embodiment of the present invention;

[0018] Figure 3 This is a flow chart of a tool detection method for numerical control equipment according to another embodiment of the present invention. DETAILED DESCRIPTION

[0019] The present application is described in detail below with reference to the accompanying drawings and specific embodiments.

[0020] The following describes the implementation methods of the present application through specific examples, and those skilled in the art can easily understand other advantages and effects of the present application from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The present application can also be implemented or applied through other different specific implementation methods, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, in the absence of conflict, the following embodiments and the features in the embodiments can be combined with each other. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work belong to the scope of protection of the present application.

[0021] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein can be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present application, it should be understood by those skilled in the art that an aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number and aspect described herein can be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein can be used to implement this device and / or practice this method.

[0022] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present application. The illustrations only show the components related to the present application rather than being drawn according to the number, shape and size of the components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed at will, and the component layout may also be more complicated.

[0023] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the examples can be practiced without these specific details.

[0024] The technical solutions provided by various embodiments of the present application are described below in conjunction with the accompanying drawings.

[0025] See also Figure 1-2 In this embodiment: a machine vision CNC equipment tool detection method includes the following steps: S1, shooting the CNC equipment tool image and preprocessing it to obtain a preprocessed image; S2, extracting the texture and edge features of the preprocessed image, and constructing a tool image feature vector based on the texture and edge features; S3, determining the initial threshold of image segmentation based on the tool image feature vector and prior knowledge, and optimizing the initial threshold through an optimization algorithm to obtain an adaptive segmentation threshold; S4, binarizing the preprocessed image based on the adaptive segmentation threshold and extracting the tool contour to obtain a tool binary image; S5, extracting the contour and measuring the parameters of the tool binary image to obtain the geometric parameters of the tool, and constructing a tool parameter feature vector based on the geometric parameters; S6, inputting the tool parameter feature vector into a pre-trained detection model to perform tool defect recognition and classification to obtain a detection result.

[0026] Step S1, obtaining an original image of a tool for numerical control equipment, preprocessing the original image, including image denoising and enhancement, to obtain a preprocessed image; obtaining an original image of a tool for numerical control equipment; determining whether the original image has noise, and if so, performing denoising on the original image using a median filtering algorithm to obtain a denoised image; based on the denoised image, performing enhancement on the denoised image using a histogram equalization algorithm to obtain an enhanced image; and determining the enhanced image as the preprocessed image.

[0027] For example, firstly, the original image of the tool is obtained through the high-definition camera on the CNC equipment, and the image resolution is 1920×1080; then the original image is subjected to noise detection, and the standard deviation of the image is calculated. If the standard deviation is greater than the threshold value of 20, it is judged that the image has noise; for the noisy image, a 5×5 median filter algorithm is used for denoising to remove salt and pepper noise and Gaussian noise to obtain a smooth denoised image; then, the denoised image is enhanced using the histogram equalization algorithm to expand the grayscale dynamic range of the image to 0-255, improve the image contrast, and make the tool contour clearer; the enhanced image is used as the preprocessing result.

[0028] Step S2, extracting texture and edge features from the preprocessed image, and constructing a tool image feature vector for subsequent threshold adaptive selection and defect recognition.

[0029] The preprocessed tool image is obtained, and texture features are extracted for the tool image. The gray-level co-occurrence matrix algorithm is used to obtain statistics reflecting the texture features of the tool image. The statistics include contrast, correlation and entropy to form a texture feature vector. On the basis of extracting texture features, the edge features of the tool image are further extracted. The edge detection of the tool image is performed by the Canny operator to obtain the tool contour edge, and the directional gradient histogram of the contour edge is calculated to obtain the directional gradient histogram vector that characterizes the tool edge features. The texture feature vector and the directional gradient histogram vector are fused to construct a comprehensive tool image feature vector. The feature-level fusion strategy is adopted to fuse the texture feature vector and the directional gradient histogram vector by weighted averaging. The weight coefficient of the weighted average is adaptively adjusted according to the contribution of each feature to tool defect recognition. According to the comprehensive tool image feature vector, the feature is reduced in dimension. The principal component analysis method is used to reduce the dimension of the high-dimensional feature vector, and the top N principal components that contribute the most to tool defect recognition are extracted to form a tool image feature vector after dimensionality reduction.

[0030] For example, the preprocessed tool image is first grayed out to convert the RGB color image into a grayscale image; then the grayscale co-occurrence matrix algorithm is used to extract the texture features of the image, the grayscale level is set to 256, four directions of 0°, 45°, 90° and 135° are selected, the step size is 1, a grayscale co-occurrence matrix of size 256×256 is generated, and the three statistics of the matrix contrast, correlation and entropy are calculated to obtain a 12-dimensional texture feature vector; on this basis, the Canny operator is used to detect the edge of the grayscale image, the standard deviation of the Gaussian filter is 2, the double threshold selects a high threshold of 150 and a low threshold of 50, and the contour edge of the tool is extracted; the contour edge is divided into 360 directions, The gradient amplitude in each direction is calculated to generate a 360-dimensional directional gradient histogram vector to characterize the edge features of the tool. The texture features and edge features are integrated, and a feature-level weighted fusion strategy is adopted. Through grid search and cross-validation, the weight of the texture feature is determined to be 6, and the weight of the edge feature is determined to be 4. The two types of feature vectors are weighted averaged to obtain a 372-dimensional comprehensive feature vector of the tool image. In order to reduce the feature dimension, the principal component analysis method is used to reduce the dimensionality of the 372-dimensional feature vector. By calculating the eigenvalues ​​and eigenvectors of the covariance matrix, the eigenvectors corresponding to the first 10 largest eigenvalues ​​are selected as the principal components. The original feature vector is mapped to these 10 principal components to obtain a 10-dimensional tool image feature vector after dimensionality reduction.

[0031] Step S301, obtain the tool image feature vector according to the grayscale histogram distribution of the preprocessed image, combine the prior knowledge of tool material, shape, processing technology, etc., use the maximum inter-class variance method or the minimum cross entropy method to determine the initial threshold of image segmentation.

[0032] Obtain the preprocessed tool image and extract the grayscale histogram distribution feature vector of the image; construct a tool image feature knowledge base based on the preset tool material, shape, and processing technology prior knowledge; for the current tool image to be segmented, retrieve the prior knowledge most similar to its material, shape, and processing technology from the knowledge base; if the maximum inter-class variance method is used, then according to the grayscale histogram distribution, traverse all possible thresholds, calculate the inter-class variance, and select the grayscale value corresponding to the maximum variance as the optimal segmentation threshold; if the minimum cross entropy method is used, then according to the grayscale histogram distribution and prior knowledge, construct a foreground and background probability model, and minimize the cross entropy and iteratively optimize to obtain the optimal segmentation threshold; the adaptive segmentation threshold determined according to the above steps.

[0033] For example, the preprocessed tool image is first grayed out, the 256-level grayscale histogram distribution features are extracted, and a 256-dimensional grayscale histogram vector is generated; based on the prior knowledge that the tool material is high-speed steel, the shape is a standard end mill, and the processing technology is CNC milling, a tool image feature knowledge base containing 1000 samples is constructed, and each sample includes attributes such as grayscale histogram, material, shape, and process; for the current tool image to be segmented, the K nearest neighbor algorithm is used to retrieve the 10 prior samples that are most similar to its material, shape, and process from the knowledge base; considering the grayscale distribution characteristics of the tool image, the maximum inter-class variance method is selected to adaptively determine the segmentation threshold; traverse all grayscale values ​​0-255, calculate the inter-class variance of the background and foreground, and obtain the optimal threshold of 87 by solving the variance maximization problem; the grayscale Figure 2 The pixels less than 87 are set to 0, and the pixels greater than or equal to 87 are set to 255 to obtain the segmented tool foreground area. The binary image is morphologically processed. First, a 3×3 structure element is used for corrosion to remove small noise in the binary image. Then a 5×5 structure element is used for dilation to fill small holes in the tool foreground area. Finally, a 7×7 structure element is used for opening and closing operations to smooth the edges of the tool foreground area to obtain the final accurately segmented tool image. The segmentation result is compared with the manually labeled groundtruth. The pixel-level segmentation accuracy reaches 95%, indicating that this method can accurately extract the foreground area of ​​the tool and provide a reliable segmentation basis for subsequent defect detection.

[0034] Step S302, based on the initial threshold, the optimal threshold is searched by genetic algorithm or particle swarm optimization algorithm to optimize the objective function of image segmentation and obtain an adaptive segmentation threshold; the objective function is defined as the ratio of the between-class variance to the within-class variance.

[0035] The image to be segmented is obtained, and the initial segmentation threshold is determined for the image to be segmented; according to the preset objective function, the ratio of the between-class variance to the within-class variance is obtained as the optimization target; for the initial segmentation threshold, a genetic algorithm is used to generate a new candidate threshold through crossover mutation operation, and the objective function value corresponding to each candidate threshold is calculated; according to the preset fitness function, a threshold with high fitness is selected from the candidate thresholds as a good individual, and a threshold with low fitness is eliminated as an inferior individual to obtain a new generation of candidate thresholds; it is determined whether the preset number of iterations or the convergence condition of the objective function value is reached, if not, the candidate threshold generation step is returned to continue iterative optimization; if the convergence condition is reached, the threshold with the best objective function value in the current candidate threshold is used as the segmentation threshold obtained by genetic algorithm optimization; the segmentation threshold obtained by genetic algorithm optimization is used as the initial particle position of the particle swarm optimization algorithm, and the objective function is used as the fitness function, and the segmentation threshold is further optimized and searched by updating the speed and position of the particles; the particle position with the best fitness function value is obtained, and it is used as the final adaptive segmentation threshold; the image to be segmented is segmented using the adaptive segmentation threshold to obtain the segmented image.

[0036] For example, first obtain a tool image to be segmented, and according to the grayscale histogram distribution characteristics of the image, use the maximum inter-class variance method to determine the initial segmentation threshold of 120; then use the ratio of inter-class variance to intra-class variance as the optimization objective function of the genetic algorithm, set the population size to 50, the crossover probability to 8, the mutation probability to 1, and the number of iterations to 100; in each iteration, generate new candidate thresholds through crossover and mutation operations, and calculate the objective function value corresponding to each threshold; according to the roulette wheel selection strategy, select the top 30% of the thresholds with the objective function value from the candidate thresholds as excellent individuals, eliminate the bottom 40% of the thresholds as inferior individuals, and retain the middle 30% of the thresholds unchanged, forming a new generation of candidate thresholds; after 100 iterations, the genetic algorithm converges, and the candidate threshold with the largest objective function value is 135, which is used as the segmentation threshold optimized by the genetic algorithm; then 135 is used as the initial particle position of the particle swarm algorithm, and the number of particles is set to 20, the learning factor is 2, the inertia weight is 8, and the maximum number of iterations is 50; in each iteration, the position and speed of each particle are updated according to the particle speed update formula and position update formula, and the fitness function value corresponding to each particle position is calculated; after 50 iterations, the particle swarm algorithm converges, and the particle position with the best fitness function value is 138, which is used as the final adaptive segmentation threshold.

[0037] Step S4, using an adaptive threshold to perform binary segmentation on the preprocessed image, extract the tool contour, perform morphological processing, eliminate noise and interference areas, and obtain a binary image of the tool; obtain the image of the tool to be detected, preprocess the image, and eliminate noise and distortion in the image; use an adaptive threshold method to perform binary segmentation processing on the preprocessed image, automatically determine the segmentation threshold according to the grayscale distribution of different areas of the image, and obtain a binary image.

[0038] For example, firstly, an image of a tool to be detected is obtained, and the image is subjected to median filtering and histogram equalization processing to eliminate Gaussian noise and distortion caused by uneven illumination in the image; then, according to the bimodal distribution characteristics of the image grayscale histogram, the maximum inter-class variance method is used to adaptively determine the segmentation threshold as 135, and the image is binarized; then, the binary image is subjected to morphological opening and closing operations, with a 3×3 rectangular structure element used in the opening operation and a 5×5 circular structure element used in the closing operation, to eliminate interference areas such as holes and burrs in the binary image.

[0039] As an optional implementation method, the Suzuki85 contour extraction algorithm is used to extract the tool contour based on the processed binary image, and the extracted contour is subjected to morphological filtering. The contour is expanded and eroded using an 11×11 diamond structure element to eliminate jagged edges and breakpoints on the contour. The Douglas-Peucker contour approximation algorithm is then used to approximate the filtered contour, and the approximation threshold is set to 2 to reduce the number of contour points to 1 / 4 of the original. Seven geometric features and five shape features are extracted from the approximated contour, including contour area, perimeter, circularity, rectangularity, etc. Finally, based on the extracted contour feature vector, the support vector machine algorithm is used for defect detection and classification. The radial basis kernel function is used, and the penalty factor is set to 100. The optimal model parameters are determined through 5-fold cross validation. The defect detection accuracy on 200 test samples reaches 95%, and the accuracy of discriminating the tool defect type reaches 95%, realizing automatic detection and intelligent classification of tool defects.

[0040] Step S5, perform contour extraction and parameter measurement on the binary image of the tool, calculate the geometric parameters of the tool, such as length, width, circumference, and area, and construct a tool parameter feature vector; calculate the geometric parameters of the tool according to the tool contour image to obtain the tool geometric parameters; wherein the tool geometric parameters include length, width, circumference and area; construct the tool geometric parameters into a feature vector to obtain a tool feature vector.

[0041] For example, the high and low thresholds of the Canny algorithm are set to 50 and 150 respectively to extract the precise contour of the tool. Then, the geometric parameters of the extracted contour image are calculated. The length of the tool is calculated to be 120 pixels and the width is 35 pixels through the minimum circumscribed rectangle of the contour. The perimeter of the contour is calculated to be 325 pixels and the area is 3720 square pixels through the Green formula. The calculated four geometric parameters are constructed into a 4-dimensional feature vector.

[0042] As an optional implementation method, the support vector machine algorithm is used to train and classify the tool feature vectors. The radial basis kernel function is used, and the penalty factor C is set to 10. The optimal model parameters are obtained through grid search and 5-fold cross validation. On 200 test samples, the algorithm has an identification accuracy of 98% for 6 common tools. Finally, the category information of the tool is output according to the classification results, realizing automatic identification and classification of the tool.

[0043] Step S601, input the tool parameter feature vector into the pre-trained support vector machine or decision tree model to identify and classify tool defects; the model is trained with a large number of labeled tool image samples to learn the characteristics of different defect types; determine whether the tool has defects, give the defect type (such as chipping, wear, cracks) and severity (mild, moderate, severe), and output the detection results.

[0044] According to the pre-labeled tool defect sample data set, the support vector machine (SVM) algorithm is used to train the defect feature vector to obtain the tool defect classifier; the defect feature vector of the tool to be detected is input into the tool defect classifier, and the model reasoning is used to determine whether the tool to be detected has defects. If there are defects, the type of defect is determined; for the tool to be detected that is detected to have defects, the similarity between its defect feature vector and the standard defect sample feature is calculated, and the defects are divided into three levels: slight, moderate and severe according to the similarity, and the defect detection result of the tool to be detected is output.

[0045] For example, the SVM algorithm is used to train the feature vector on 500 labeled tool defect samples, using the RBF kernel function and the penalty factor C=10. The optimal classification model is obtained through 5-fold cross validation to determine whether the tool has defects, and the defect detection rate reaches more than 95%; the defect features of the tool to be detected are input into the trained SVM classifier to determine whether it has three defects: chipping, wear, and cracks; for the defective tools detected, the Euclidean distance between its feature vector and the standard defect sample feature is further calculated. When the distance is less than or equal to 10, it is judged as a minor defect; when the distance is between 10 and 20, it is judged as a moderate defect; when the distance is greater than 20, it is judged as a serious defect; finally, the tool defect detection results and defect level assessment results are output to realize online intelligent monitoring of the tool health status.

[0046] Step S602: If a defect is detected in the tool, the defect area is marked and displayed in the original tool image, and the defect information is fed back to the CNC equipment control system to trigger an alarm or shutdown processing; at the same time, the defect information is stored in the database for reference and model update in subsequent detection processes.

[0047] If a defect is detected in the tool, an edge detection algorithm is used to extract the outline of the defect area, and the defect outline is marked with a preset color in the original tool image; the location coordinates, defect type and severity of the defect area are packaged into a defect information data packet.

[0048] The defect information data packet is transmitted to the CNC equipment control system via industrial Ethernet; the CNC equipment control system receives the defect information data packet, extracts the defect type and severity, and determines whether the severity exceeds a preset threshold; if so, an alarm signal is triggered, and the CNC equipment is controlled to stop processing, and the defect type and recommended processing measures are displayed on the human-machine interface.

[0049] The defect information data packet is stored in the defect information table of the relational database, and the defect information table includes the defect occurrence time, batch number, tool number, defect type and severity fields; in the subsequent tool defect detection process, the historical defect data is read from the relational database, and the defect occurrence rules and influencing factors in the historical defect data are analyzed by the data mining algorithm to obtain the association rules of defect occurrence; according to the association rules, the optimization parameters of the defect detection model are determined, the parameters of the defect detection model are optimized, and the detection accuracy of the defect detection model is improved.

[0050] For example, the Canny edge detection algorithm is first used to preprocess the original tool image and extract the tool contour; then the extracted tool contour is matched one by one with the 10 pre-established standard tool templates, the Hu invariant moment feature vector of the contour is calculated, and the Euclidean distance is used to measure the contour similarity; when the similarity is less than 85, it is determined that the tool has a defect and the minimum circumscribed rectangle of the defect area is extracted; then the defect area is morphologically processed, and the defect edge is detected using the Sobel operator and marked with red pixels on the original image; the defect location, type, area and other information are packaged into JSON format and sent to the CNC system through the MQTT protocol with a service quality level of QoS1; the CNC system subscribes to the defect topic, receives the JSON data packet, and extracts the defect area; when the defect area When the defect area exceeds 5% of the tool area, an alarm is triggered, processing is stopped, and a prompt "Tool chipping, please replace the tool" is displayed on the HMI; the defect information is stored in the MySQL database with a 64-bit timestamp, 20-bit batch number, 10-bit tool ID, 1-bit defect type and 10-bit defect area; the Apriori association rule mining algorithm is used in the background to analyze the correlation between defects and processing parameters, usage time, and material type, and generate association rules with a confidence level greater than 80%; the processing parameters in the association rules are used as input features of the SVM defect detection model, and the penalty factor C of the model and the gamma parameter of the RBF kernel function are optimized using grid search to improve the generalization performance of the model, predict the probability of defect occurrence in new tool defect detection tasks, and guide tool preventive maintenance.

[0051] Step S603, continuously acquire the tool image of the CNC equipment, and repeat the above steps to realize real-time online detection and defect diagnosis of the tool; dynamically adjust the detection parameters and thresholds according to the historical defect information in the database to improve the detection accuracy; through continuous data accumulation and model optimization, continuously improve the tool defect recognition capability to ensure the reliability of the CNC machining process and product quality.

[0052] The tool image of the CNC equipment is acquired, and the tool image is preprocessed to obtain the preprocessed tool image; the features of the tool are extracted from the preprocessed tool image to obtain the tool feature vector; the tool feature vector is classified by the support vector machine algorithm according to the pre-built tool defect sample library to determine whether the tool has defects; if the tool is determined to be defective, the convolutional neural network algorithm is used to diagnose the defect type to determine the category and severity of the defect; the detected tool defect information is stored in the historical defect database, and the model parameters of the support vector machine algorithm and the convolutional neural network algorithm are dynamically adjusted according to the defect data accumulated in the historical defect database; the tool image of the CNC equipment is continuously acquired, the historical defect database is continuously updated, and the models of the support vector machine algorithm and the convolutional neural network algorithm are regularly retrained and optimized; the optimized tool defect detection and diagnosis model is applied to the real-time monitoring of CNC equipment to timely discover and alarm tool defects.

[0053] In other embodiments, see Figure 3The results show that, firstly, an industrial camera is used to collect images of tools installed on the spindle of a CNC machine tool, and the image resolution is 1280×960 pixels. Then, the collected original images are preprocessed, including grayscale, histogram equalization, median filtering denoising and other operations, to enhance the tool contour and texture features. Then, the shape, size, texture and other features of the tool are extracted to construct a 128-dimensional tool feature vector. According to 500 normal tool samples and 500 defective tool samples collected in advance, the tool feature vector is classified into two categories using the SVM algorithm. The optimal kernel function is determined to be RBF through 5-fold cross validation, the penalty factor C is 10, and the classification accuracy reaches more than 95%. When defects are detected in the tool, the pre-trained ResNet-50 convolutional neural network model is further used to classify the defective image. The classification error rate of this model on the ImageNet dataset is 25%, and it can identify eight common defects such as chipping, cracks, wear, and deformation. The defect type is classified into three levels: mild, moderate and severe according to the defect area ratio; the tool defect information detected each time is stored in the MySQL database in JSON format, including fields such as defect type, severity, occurrence time, tool number, etc.; when the amount of historical defect data accumulates to more than 1,000, the adaptive boosting algorithm AdaBoost is used to dynamically adjust the weight coefficients of the SVM and CNN models to improve the generalization performance of the model; at the same time, the model is retrained every month, newly collected defect samples are introduced, and the model parameters are iteratively optimized; the trained tool defect detection and diagnosis model is deployed to the embedded vision system of the CNC equipment, and the detection is automatically triggered every 10 minutes. Once a defect is found, an alarm signal is immediately sent to the CNC system, and the defect type and severity are displayed on the human-machine interface, prompting the operator to replace the tool or adjust the cutting parameters in time to avoid workpiece scrapping and equipment failure due to tool damage.

[0054] The same and similar parts between the various embodiments in this specification can be referenced to each other, and each embodiment focuses on the differences from other embodiments.

[0055] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.

Claims

1. A machine vision CNC equipment tool detection method, characterized in that: The following steps are involved: S1, photographing and preprocessing the image of the tool of the CNC equipment to obtain a preprocessed image; In the step S1, the original image is subjected to noise detection, and the standard deviation of the image is calculated. If the standard deviation is greater than a threshold, it is determined that the image has noise; the image of the CNC tool is subjected to denoising by using a median filtering algorithm to obtain a denoised image; the denoised image is enhanced by using a histogram equalization algorithm to obtain an enhanced image; S2, extracting texture and edge features of the preprocessed image, and constructing a tool image feature vector based on the texture and edge features; S3, determining an initial threshold for image segmentation based on the tool image feature vector and prior knowledge, and optimizing the initial threshold by an optimization algorithm to obtain an adaptive segmentation threshold; S4, based on the adaptive segmentation threshold, the pre-processed image is binarized and segmented, and the tool contour is extracted to obtain a tool binary image, and an opening operation and a closing operation are performed on the tool binary image, wherein the opening operation uses a 3×3 rectangular structure element, and the closing operation uses a 5×5 circular structure element to obtain a processed binary image; S5, performing contour extraction and parameter measurement on the binary image to obtain tool geometric parameters, and constructing a tool parameter feature vector based on the tool geometric parameters; S6, inputting the tool parameter feature vector into a pre-trained detection model to perform tool defect recognition and classification to obtain a detection result; If a defect is detected in the tool, the defect area is marked and displayed in the original tool image, and the defect information is fed back to the CNC equipment control system to trigger an alarm or shut down the machine; At the same time, the defect information data packet is stored in the defect information table of the relational database, which includes the defect occurrence time, batch number, tool number, defect type and severity fields; in the subsequent tool defect detection process, the historical defect data is read from the relational database, and the defect occurrence law and influencing factors in the historical defect data are analyzed by data mining algorithm to obtain the association rules of defect occurrence; the optimization parameters of the defect detection model are determined according to the association rules, and the parameters of the defect detection model are optimized to improve the detection accuracy of the defect detection model; In the step S2, a gray level co-occurrence matrix algorithm is used to obtain statistics reflecting the texture features of the pre-processed image, the statistics including contrast, correlation and entropy, and a texture feature vector is formed based on the statistics; edge detection is performed on the pre-processed image by using a Canny operator to obtain a tool contour edge, and a directional gradient histogram of the tool contour edge is calculated to obtain a directional gradient histogram vector of a tool edge feature; the texture feature vector and the directional gradient histogram vector are fused to obtain the tool image feature vector; The method for fusing the texture feature vector and the directional gradient histogram vector comprises: adopting a feature-level fusion strategy to fuse the texture feature vector and the directional gradient histogram vector by weighted averaging to obtain a comprehensive tool image feature vector, wherein the weight coefficient of the weighted averaging is adaptively adjusted according to the contribution of each feature to tool defect recognition; In the step S3, a minimum cross entropy method is used to construct a foreground-background probability model according to the tool image feature vector and prior knowledge, and an optimal segmentation threshold is obtained by iterative optimization through minimizing the cross entropy, which is used as the initial threshold; In step S3, the method for optimizing the initial threshold by an optimization algorithm includes: using a genetic algorithm to generate a new candidate threshold through a crossover mutation operation, and calculating the objective function value corresponding to each candidate threshold; according to a preset fitness function, selecting a threshold with a high fitness from the candidate thresholds as an excellent individual, eliminating the candidate thresholds with a low fitness to obtain a new generation of the candidate thresholds; when the convergence condition is reached, the candidate threshold with the best objective function value among the current candidate thresholds is used as the segmentation threshold optimized by the genetic algorithm; the segmentation threshold optimized by the genetic algorithm is used as the initial particle position of the particle swarm optimization algorithm, and the objective function value is used as the fitness function, and the further optimization search of the segmentation threshold is realized by updating the speed and position of the particles; and the particle position with the best fitness function value is obtained as the final adaptive segmentation threshold.

2. A machine vision CNC equipment tool detection method according to claim 1, characterized in that: The method for obtaining the tool image feature vector includes: using principal component analysis to reduce the dimension of the comprehensive tool image feature vector, extracting the top N principal components that contribute most to tool defect identification, and forming the reduced-dimensional tool image feature vector as the required tool image feature vector.

3. The method for detecting tool of numerical control equipment by machine vision according to claim 1, characterized in that: In the step S6, the method for obtaining the pre-trained detection model includes: training a support vector machine based on a pre-labeled tool defect sample data set to obtain a pre-trained detection model.