Disclosure of Invention
The invention discloses a bearing roller chamfer surface defect detection method based on machine vision.
The technical scheme adopted by the invention for realizing the purpose is as follows:
a bearing roller chamfer surface defect detection method based on machine vision comprises the following steps:
1) establishing a machine vision acquisition system, acquiring a bearing roller image sample containing the chamfer surface defect, calibrating the defect position, and establishing a bearing roller chamfer surface defect database;
2) establishing a deep learning algorithm target detection model based on a deep convolutional neural network, and training the detection model according to image samples in a bearing roller chamfer surface defect database to obtain a network model suitable for bearing roller chamfer surface defect detection;
3) acquiring a roller image to be detected by using a visual acquisition system, extracting a roller chamfer surface outline by using an edge detection algorithm based on a metering model, judging whether a defect exists or not by using a trained defect detection network model, if the defect exists, positioning a defect area, and screening an area within a chamfer surface outline or intersected with the outline as a chamfer surface defect area;
4) and rechecking the defect area, extracting the area and gray value characteristics of the defect area by using a Blob analysis algorithm, judging whether the defect area is a false detection area, if not, feeding back the type and the position of the defect to a detection system database, and if the defect area is the false detection area, feeding back a defect-free result.
The machine vision acquisition system includes: the device comprises an area array camera, an outer-ring lens, a ball integral light source and a moving shaft, wherein the area array camera is connected with the outer-ring lens and is arranged vertically above a bearing roller, the ball integral light source is connected with the moving shaft, the central axes of the area array camera, the outer-ring lens and the ball integral light source are coincident with the central axis of the bearing roller, the moving shaft is controlled to drive the ball integral light source, the bearing roller chamfering surface is positioned in the irradiation area of the ball integral light source, and the image of the bearing roller chamfering surface is acquired through the area array camera.
The bearing roller chamfer surface defect database is established by the following steps:
1) acquiring bearing roller chamfer surface images including a defect-free image and a defective image by a machine vision acquisition system;
2) graying the image, adopting a threshold segmentation algorithm to segment and extract a to-be-detected region from the image, zooming the segmented to-be-detected region image, and storing the zoomed to-be-detected region image as an image sample;
3) selecting a zoom chamfer image sample containing a defect, marking the defect area by using a rectangular frame, and obtaining coordinate values a of four corners of the defect areaij,bij,cij,dijAnd i is 1,2,3 …, j is 1,2,3 …, i represents the serial number of the image sample, j represents the serial number of the labeling frame in the same image sample, coordinate value data of the four corners of all the labeling frames are stored, each group of coordinate values corresponds to one defect area sample, and a bearing roller chamfer surface defect sample database is established.
The step 2) is as follows:
the network model adopts a CNN model and consists of an input layer, a convolution layer, a pooling layer, a full-link layer and an output layer, and the process of training the network model is as follows:
1) scaling the marked defect image sample, and inputting the scaled defect image sample into the network model through the input layer;
2) performing convolution operation on the convolution layer to extract a characteristic diagram of a defect image sample, realizing nonlinear operation through an activation function to enhance the image characteristic fitting capability of the network, and obtaining the characteristic diagram of the defect image sample through calculation:
a characteristic diagram representing the output of the jth neural node in the ith layer of convolutional network, f is an activation function, M
jFor the jth node feature map set,
is the ith characteristic diagram of the l-1 st layer,
the values of the convolution kernel weights are used as the values of the convolution kernel weights,
is a bias term;
3) inputting a sample characteristic diagram extracted from the convolutional layer into a pooling layer, establishing a sliding window, sliding on the sample characteristic diagram for average pooling, calculating a characteristic mean value of each window, inputting the sample characteristic diagram into a full-connection layer, refitting the sample characteristic diagram into a global characteristic diagram, and obtaining the global characteristic diagramGet the characteristic yj:yj=f(∑iWij*xi+bj) F is an activation function, WijRepresenting respective neuron node weight values, xiAs input features, bjIs a bias value;
4) the network model inputs m defect samples, and the network total loss function can be expressed as:
w represents the weight of the network model, b represents the bias value of the network model, J (W, b; x)
(i),y
(i)) Representing the i-th defect sample loss function, with sample λ representing the network weight decay term, n
lRepresenting the number of layers of the network, S
lNumber of ganglion points, x, representing the l-th neural network
(i)Predicted defect characteristics for the ith defect sample, y
(i)The real defect characteristics of the ith defect sample. Through iterative training learning, the weight parameters of the network are corrected, the loss function is reduced, the network model is updated until the training is finished, and the defect detection model based on the deep convolutional neural network is obtained.
The step 3) is as follows:
the method comprises the steps of obtaining a roller chamfer surface and a partial outer diameter surface image in an image sample of a region to be detected, seeking a segmentation threshold value of the chamfer surface and the outer diameter surface by adopting an Otsu algorithm, segmenting a chamfer surface image region, then carrying out closed operation on the image region, taking a minimum inscribed circle to obtain a crude extraction contour of the chamfer surface, adding the crude extraction contour into a template, creating a metering model template, creating a plurality of adjacent quasi-rectangular regions with the height of h at intervals of l according to the initial contour position of the template, enabling the centers of the quasi-rectangular regions to be located on the initial contour and perpendicular to the initial contour, then determining edge boundary positions in the quasi-rectangular detection regions by using an RANSAC algorithm in each quasi-rectangular region, and finally connecting and fitting boundary points in all detected detection regions to obtain the accurate contour of the chamfer surface.
The step 4) is as follows:
taking a plurality of detection areas in the defect area in a fixed-scale sliding window mode, and dividing each detection area into a plurality of detection areasInputting the area image into the network model convolution layer to extract a characteristic diagram, inputting the characteristic diagram into the full-connection layer to obtain an output value y-f (sigma)
kW*x
k+ b), calculating the output value of the whole full-connection layer by adopting a Softmax function, wherein each defect classification corresponds to one node, and outputting the probability of the defect classification
y
kRepresenting the probability, x, of a network model determining each defect class k corresponding to a certain detection area
kInput value, x, representing the node corresponding to the k-th defect
jThe input value of the corresponding node of the jth defect is n, the number of categories of defect classification is n, the weight value of the network model is W, the bias item of the network model is b, and the category with the highest probability and the probability exceeding the set threshold is the judged defect classification.
The invention has the following beneficial effects and advantages:
1. the invention replaces the traditional manual mode to detect the defects of the chamfer surface of the bearing roller, has high detection efficiency and strong stability, and effectively removes the conditions of defect omission and false detection caused by factors such as working environment, experience deviation of detection personnel, fatigue state and the like.
2. The invention improves the original vision acquisition system, adopts the lens outside the ring and the spherical integral light source, can effectively improve the acquisition integrity and the presentation effect of the bearing roller chamfer surface image, and improves the chamfer surface defect detection effect.
3. According to the invention, the intelligent prediction judgment is carried out on whether the roller chamfer surface has defects or not by adopting the deep convolution network model, so that the problems of insufficient defect rule description, difficult feature extraction, poor robustness and the like of the traditional algorithm are effectively solved, and the accuracy of defect detection is improved.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples.
As shown in fig. 1, a method for detecting defects of a bearing roller chamfer surface based on machine learning includes the following steps:
1) establishing a machine vision acquisition system, acquiring a large number of bearing roller image samples containing the chamfer surface defects, manually calibrating the positions of the defects, and establishing a chamfer surface defect database;
2) establishing a deep learning algorithm target detection model based on a deep convolutional neural network, and training and optimizing the detection model by using defect samples in a defect database to obtain a network model suitable for detecting the defects of the bearing roller chamfer surface;
3) and (3) acquiring an image of the roller to be detected by using a visual acquisition system, and extracting the outline of the roller chamfer surface by using an edge detection algorithm based on a metering model. Judging whether a defect exists or not by using the trained and optimized defect detection network model, positioning a defect area, and screening an area within or intersected with the contour line of the chamfer surface as the chamfer surface defect area;
4) and rechecking the defect area, extracting the characteristics of the area, the gray value and the like of the defect by using a Blob analysis algorithm, judging whether the defect area is a false detection area or not, and storing the confirmed defect detection information.
As shown in fig. 2, is a machine vision acquisition system. The visual acquisition system consists of an area-array camera, a 360-degree lens outside a ring, a spherical integral light source and a motion shaft. The camera is connected with the lens outside the ring and is arranged above the roller vertically, and the spherical integral light source is connected with the moving shaft, so that the central axes of the camera, the lens and the light source are coincided with the central axis of the roller. And controlling the motion shaft to drive the ball integral light source, so that the bearing roller chamfer surface is positioned in a light source irradiation area, and acquiring a chamfer surface image through a camera.
Fig. 3 is a flowchart of a bearing roller defect detection method based on machine vision according to the present invention.
Establishing a bearing roller chamfer surface defect database, wherein the specific implementation process comprises the following steps:
1) acquiring a large number of roller chamfer surface images by a vision acquisition system, wherein the images need to comprise a defect-free image sample and a defect-carrying image sample;
2) graying the image sample, selecting a proper grayscale threshold by adopting a threshold segmentation algorithm, and segmenting and extracting the region to be detected from the image background. And scaling the segmented to-be-detected region image into 256 × 256, and storing as an image sample.
3) Selecting a zoom chamfer image sample containing a defect, manually marking the defect area by using a rectangular frame, and obtaining coordinate values a of four corners of the defect areaij,bij,cij,dijI is 1,2,3 … n, j is 1,2,3 … n, i indicates the number of the image sample, and j indicates the number of the label box in the same image sample. And storing coordinate value data of four corners of all the marking frames, wherein each group of coordinate values corresponds to one defect area sample, and establishing a bearing roller chamfer surface defect sample database.
And training a defect detection network model by using a defect sample database. The network model adopts a CNN model and consists of an input layer, a convolution layer, a pooling layer, a full-link layer and an output layer, and the specific process of training the network model comprises the following steps:
1) uniformly scaling the defect samples into 32 × 32 sizes, and inputting the defect samples into a network through an input layer;
2) convolution operation is carried out through the convolutional layer to extract the characteristics of the sample, nonlinear operation is realized through an activation function to enhance the image characteristic fitting capacity of the network, and a sample characteristic diagram is obtained through calculation:
representing the l-th convolutional network inputThe j th feature graph is shown, f is an activation function, M
jFor the set of feature maps, W is the convolution kernel value,
is the ith feature map of layer l-1, and b is the bias term.
3) Inputting the characteristic graph extracted from the convolutional layer into a pooling layer, establishing a sliding window in a scale of 2 x 2, sliding on the characteristic graph for average pooling, solving a characteristic mean value of each window, and reducing the calculated amount of characteristic values. Then inputting the feature graph into a full-connection layer, refitting the feature graph into a global feature graph, and obtaining features: y isj=f(∑iWij*xi+bj) F is an activation function, WijRepresenting respective neuron node weight values, xiAs input features, bjIs an offset value.
4) The network model inputs m defect samples, and the network total loss function can be expressed as:
w represents the weight of the network model, b represents the bias value of the network model, J (W, b; x)
(i),y
(i)) Representing the i-th defect sample loss function, with sample λ representing the network weight decay term, n
lRepresenting the number of layers of the network, S
lRepresenting the number of ganglion points of the l-th neural network. And continuously correcting the weight parameters of the network through continuous iterative training and learning to ensure that the loss function is smaller and smaller, and updating the optimized network model until the training is finished. And finally obtaining a defect detection model based on the deep convolutional neural network.
And extracting the outline of the chamfer surface by adopting an edge detection algorithm based on a metering model. The image sample of the region to be detected comprises a roller chamfer surface image and a partial outer diameter surface image, the segmentation threshold values of the chamfer surface and the outer diameter surface are searched by adopting an Otsu algorithm, a chamfer surface image region is segmented, then the image region is subjected to closed operation, the minimum inscribed circle is taken, and the crude extraction contour of the chamfer surface is obtained. And adding the crude extraction contour into the template, creating a metering model template, and modifying the control measurement parameters of the metering model template according to requirements. And creating a plurality of adjacent rectangle-like areas with the height h at intervals of l according to the initial contour position of the template, wherein the centers of the rectangle-like areas are positioned on the initial contour and are perpendicular to the initial contour line. Then, in each small rectangular area, the RANSAC algorithm is used to determine the edge boundary position in the small rectangular detection area. And finally, connecting and fitting the detected boundary points in all the detection areas to obtain the accurate profile of the chamfer surface.
And detecting the defects by using the defect detection network model after training optimization. Taking a plurality of small detection areas in an image area to be detected in a fixed-scale sliding window mode, inputting each area image into a network model convolution layer to extract a characteristic diagram, and then inputting the characteristic diagram into a full-connection layer to obtain an output value y-f (sigma)
iW*x
i+ b), calculating the probability of outputting the defect category by adopting a Softmax function to the output value of the whole full-connection layer
y
iRepresenting the probability, x, that the network model determines each small image area for each defect class i
kAnd (4) representing the input value of the node corresponding to the kth defect, wherein the class with the highest probability and the probability exceeding a set threshold is the judged defect type.