Disclosure of Invention
In order to solve one or more of the above technical problems, the present invention provides an intelligent metal forging quality detection method, which includes the following steps:
Collecting a transmission gear image;
Acquiring the gradient direction of each pixel point in the transmission gear image according to the transmission gear image; acquiring adjacent points of each pixel point in the transmission gear image according to the gradient direction of each pixel point in the transmission gear image; acquiring a sequence of adjacent points of each pixel point in the transmission gear image according to the adjacent points of each pixel point in the transmission gear image; acquiring the gray level mutation degree of each pixel point in the transmission gear image according to the gray level value of each adjacent point in the adjacent point sequence of each pixel point in the transmission gear image; acquiring a plurality of pixel points to be filtered of a transmission gear image according to the gray level mutation degree of each pixel point in the transmission gear image;
Dividing a plurality of pixel points to be filtered of a transmission gear image into a plurality of texture sets; performing straight line fitting on all pixel points to be filtered in each texture set to obtain a fitting straight line of each texture set; acquiring adjacent texture sets of each texture set according to the fitted straight line of each texture set; obtaining the distance between each texture set and the adjacent texture set of each texture set according to the fitting straight line of each texture set and the fitting straight line of the adjacent texture set of each texture set; acquiring the possibility that each texture set is the texture of the gear according to the distance between each texture set and the adjacent texture set of each texture set;
Acquiring an initial forgetting factor of each pixel point to be filtered in each texture set according to the possibility that each texture set is the texture of the gear and the gray level mutation degree of each pixel point to be filtered in each texture set; acquiring the forgetting factor of each pixel point to be filtered in each texture set according to the initial forgetting factor of each pixel point to be filtered in each texture set and the possibility that each texture set is the texture of the gear; carrying out filtering treatment on the transmission gear image according to forgetting factors of each pixel point to be filtered in each texture set to obtain a transmission gear image after the filtering treatment;
and carrying out crack defect detection according to the transmission gear image after the filtering treatment.
Preferably, the gradient direction of each pixel point in the transmission gear image is obtained according to the transmission gear image; acquiring adjacent points of each pixel point in the transmission gear image according to the gradient direction of each pixel point in the transmission gear image; according to the adjacent point of each pixel point in the transmission gear image, acquiring an adjacent point sequence of each pixel point in the transmission gear image comprises the following steps:
Presetting the number M of unidirectional adjacent points, acquiring the gradient direction of an ith pixel point in a transmission gear image by using a sobel algorithm, acquiring M pixel points continuously adjacent to the ith pixel point in the gradient direction of the ith pixel point, and marking the M pixel points as the adjacent points of the ith pixel point; acquiring the opposite direction of the gradient direction of an ith pixel point in the transmission gear image, and acquiring M pixel points continuously adjacent to the ith pixel point in the opposite direction of the gradient direction of the ith pixel point, and marking the M pixel points as the adjacent points of the ith pixel point;
And sequencing the adjacent points of the ith pixel point according to the gradient direction of the ith pixel point to obtain an adjacent point sequence of the ith pixel point.
Preferably, the gray level mutation degree of each pixel point in the transmission gear image is obtained according to the gray level value of each adjacent point in the adjacent point sequence of each pixel point in the transmission gear image, and the calculation formula is as follows:
;
In the method, in the process of the invention,Representing the gray level mutation degree of the ith pixel point in the transmission gear image; m represents the number of unidirectional adjacent points; /(I)Representing the gray value of the q-th adjacent point in the adjacent point sequence of the i-th pixel point in the transmission gear image; /(I)Representing the gray value of the (q+1) th adjacent point in the adjacent point sequence of the (i) th pixel point in the transmission gear image; the absolute value symbol is represented by the absolute value; norm () represents a normalization function.
Preferably, the obtaining a plurality of pixel points to be filtered of the transmission gear image according to the gray level mutation degree of each pixel point in the transmission gear image includes:
And presetting a gray level mutation degree threshold T, and when the gray level mutation degree of the ith pixel point in the transmission gear image is larger than the gray level mutation degree threshold T, marking the ith pixel point as a pixel point to be filtered, so as to obtain a plurality of pixel points to be filtered of the transmission gear image.
Preferably, the pixel points to be filtered of the transmission gear image are divided into a plurality of texture sets; performing straight line fitting on all pixel points to be filtered in each texture set to obtain a fitting straight line of each texture set, wherein the straight line fitting includes:
Marking any one of the to-be-filtered pixel points in the transmission gear image as a first to-be-filtered pixel point, obtaining the vertical direction of the gradient direction of the first to-be-filtered pixel point, marking other to-be-filtered pixel points in the vertical direction of the gradient direction of the first to-be-filtered pixel point as a first texture set, marking any one of the unlabeled to-be-filtered pixel points in the transmission gear image as a second to-be-filtered pixel point, obtaining the vertical direction of the gradient direction of the second to-be-filtered pixel point, marking the second to-be-filtered pixel point and other unlabeled to-be-filtered pixel points in the vertical direction of the gradient direction of the current to-be-filtered pixel point as a second texture set, and so on until all to-be-filtered pixel points in the transmission gear image are marked, and stopping to obtain a plurality of texture sets;
Constructing a Cartesian coordinate system by taking an L-th pixel point to be filtered in an L-th texture set as an origin, taking the horizontal direction of the L-th pixel point to be filtered in the L-th texture set as an X axis and taking the vertical direction as a Y axis, acquiring the position coordinate of each pixel point to be filtered in the L-th texture set, and performing straight line fitting on all the pixel points to be filtered in the L-th texture set by adopting a least square method according to the position coordinate of each pixel point to be filtered in the L-th texture set to obtain a fitting straight line of the L-th texture set; and obtaining a fitting straight line of each texture set.
Preferably, the adjacent texture set of each texture set is obtained according to the fitted straight line of each texture set; obtaining the distance between each texture set and the adjacent texture set of each texture set according to the fitting straight line of each texture set and the fitting straight line of the adjacent texture set of each texture set, comprising:
acquiring a perpendicular bisector of a fitting straight line of the L-th texture set, marking a texture set which is on the left side of the fitting straight line of the L-th texture set and corresponds to a nearest fitting straight line intersected with the perpendicular bisector of the fitting straight line of the L-th texture set as one adjacent texture set of the L-th texture set, and marking a texture set which is on the right side of the fitting straight line of the L-th texture set and corresponds to a nearest fitting straight line intersected with the perpendicular bisector of the fitting straight line of the L-th texture set as the other adjacent texture set of the L-th texture set;
According to the method for acquiring the distance between two non-parallel line segments, the distance between the fitting straight line of the L-th texture set and the fitting straight line of each adjacent texture set of the L-th texture set is acquired and is recorded as the distance between the L-th texture set and each adjacent texture set of the L-th texture set.
Preferably, the obtaining the probability that each texture set is the texture of the gear according to the distance between each texture set and the adjacent texture set of each texture set, and the calculation formula is as follows:
;
In the method, in the process of the invention,Representing the possibility that the L-th texture set is the texture of the gear itself; /(I)Representing a distance between the L-th texture set and one of the adjacent texture sets of the L-th texture set; /(I)Representing the distance between the L-th texture set and another adjacent texture set of the L-th texture set; the absolute value symbol is represented by the absolute value.
Preferably, the obtaining an initial forgetting factor of each pixel to be filtered in each texture set according to the possibility that each texture set is the texture of the gear and the gray level mutation degree of each pixel to be filtered in each texture set, and the calculating formula is as follows:
;
In the method, in the process of the invention,Representing an initial forgetting factor of an s-th pixel point to be filtered in the L-th texture set; /(I)Representing the vertical distance from the s-th pixel point to be filtered in the L-th texture set to the fitting straight line of the L-th texture set; /(I)Representing the likelihood that the L < th > texture set is the texture of the gear itself,/>Representing the gray level mutation degree of the s-th pixel point to be filtered in the L-th texture set; exp () represents an exponential function based on a natural constant.
Preferably, the obtaining the forgetting factor of each pixel to be filtered in each texture set according to the initial forgetting factor of each pixel to be filtered in each texture set and the possibility that each texture set is the texture of the gear itself includes:
presetting a possibility threshold T, and when the possibility that the L-th texture set is the gear texture is greater than or equal to the possibility threshold T, the L-th texture set is the gear texture, and the forgetting factor of the s-th pixel point to be filtered in the L-th texture set is; When the possibility that the L-th texture set is the gear texture is smaller than the possibility threshold T, the L-th texture set is a crack edge, and the forgetting factor of the s-th pixel point to be filtered in the L-th texture set is/>,/>Representing the initial forgetting factor of the s-th pixel to be filtered in the L-th texture set.
Preferably, the filtering processing is performed on the transmission gear image according to the forgetting factor of each pixel point to be filtered in each texture set, so as to obtain a transmission gear image after the filtering processing, including:
And according to forgetting factors of each pixel point to be filtered in each texture set, performing filtering processing on each pixel point to be filtered in the transmission gear image by using an RLS filtering algorithm to obtain a transmission gear image after the filtering processing.
The invention has the following beneficial effects: according to the method, firstly, gray level mutation degree of each pixel point in a transmission gear image is obtained according to gray level difference between adjacent pixel points in the gradient direction of each pixel point in the transmission gear image, a plurality of pixel points to be filtered of the transmission gear image are obtained, the filtered pixel points are textures and crack defect pixel points of the gear, so that only the pixel points to be filtered can be analyzed conveniently, and then the pixel points to be filtered of the transmission gear image are divided into a plurality of texture sets; according to the periodicity of the texture distribution, the possibility that each texture set is the texture of the gear is obtained; according to the possibility that each texture set is the texture of the gear and the gray level mutation degree of each pixel point to be filtered in each texture set, the forgetting factor of each pixel point to be filtered in each texture set is adaptively obtained to carry out filtering treatment on the transmission gear image, the texture of the gear can be smoothed, crack defects are highlighted, and the accuracy of crack defect detection is improved.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
Referring to fig. 1, a flowchart of steps of an intelligent metal forging quality detection method according to an embodiment of the present invention is shown, and the method includes the following steps:
S001, collecting a transmission gear image.
In the embodiment of the invention, the produced gears are horizontally placed on a transmission belt, and an industrial camera is arranged above the transmission belt to collect RGB images of the transmission gears, so that the RGB images of the transmission gears are subjected to gray processing for facilitating subsequent processing and recorded as transmission gear images.
S002, according to the gray level difference between adjacent pixel points in the gradient direction of each pixel point in the transmission gear image, acquiring the gray level mutation degree of each pixel point in the transmission gear image, obtaining a plurality of pixel points to be filtered of the transmission gear image, and dividing the plurality of pixel points to be filtered of the transmission gear image into a plurality of texture sets; according to the distribution periodicity among the texture sets, the possibility that each texture set is the texture of the gear is obtained.
When the transmission gear image is subjected to crack detection, the textures of the gear and the cracks have certain similarity, the textures of the gear are required to be smoothed before the crack detection is carried out, so that the appearance of crack areas is improved, the subsequent detection of the cracks in the transmission gear image is facilitated, the transmission gear image is smoothed, meanwhile, the appearance of the cracks is reduced to a certain extent, therefore, the filtering treatment is required to be carried out by screening out pixel points to be filtered in the transmission gear image, and the closer the screened pixel points to be filtered are to the textures of the gear, the better the smoothing effect of the transmission gear image is finally, and the recognition of the crack areas is facilitated.
It should be further noted that the purpose of the present invention is to smooth the texture of the gear in the transmission gear image, so that the pixel points on the edge of the texture of the gear need to be screened as the pixel points to be filtered, and the pixel points on the edge are mostly gray abrupt points, so that the present invention is used for reflecting the gray abrupt degree of each pixel point by obtaining the cumulative sum of the gray differences between the adjacent pixel points in the gradient direction of each pixel point, thereby screening the pixel points to be filtered.
In the embodiment of the invention, a sobel algorithm is used for acquiring the gradient direction of an ith pixel point in a transmission gear image, M pixel points which are continuously adjacent to the ith pixel point are acquired in the gradient direction of the ith pixel point and are marked as the adjacent points of the ith pixel point; in the embodiment of the invention, the number M=3 of unidirectional adjacent points is preset, and in other embodiments, the number of unidirectional adjacent points can be preset by an implementer according to specific implementation conditions.
According to the gradient direction of the ith pixel point, the adjacent points of the ith pixel point are ordered to obtain an adjacent point sequence of the ith pixel point, and the method for ordering the adjacent points of the ith pixel point according to the gradient direction of the ith pixel point is described, referring to fig. 2.
The gray level mutation degree of each pixel point in the transmission gear image is obtained:
;
In the method, in the process of the invention,Representing the gray level mutation degree of the ith pixel point in the transmission gear image; m represents the number of unidirectional adjacent points; /(I)Representing the gray value of the q-th adjacent point in the adjacent point sequence of the i-th pixel point in the transmission gear image; /(I)Representing the gray value of the (q+1) th adjacent point in the adjacent point sequence of the (i) th pixel point in the transmission gear image; the absolute value symbol is represented by the absolute value; norm () represents a normalization function, and the normalization object is the/> of all the pixel points in the transmission gear image by adopting a linear normalization functionIs a value of (2).
In the embodiment of the invention, a gray level mutation degree threshold value T is preset, when the gray level mutation degree of an ith pixel point in a transmission gear image is larger than the gray level mutation degree threshold value T, the ith pixel point is marked as a pixel point to be filtered, and a plurality of pixel points to be filtered of the transmission gear image are obtained.
It should be noted that, when the RLS algorithm is adopted to filter the pixel point to be filtered, the filtering effect of the method mainly depends on the selection of the forgetting factor. The forgetting factor determines the memory degree of the RLS algorithm on the historical data, can balance memory and forgetting, improve model stability, inhibit noise and abnormal values and control memory length, reasonably select and adjust the forgetting factor, can enable the RLS algorithm to be better suitable for different data environments, and improve the performance and robustness of the algorithm, so that when the acquired pixel points to be filtered are filtered for further improving the smoothing effect, the forgetting factor when each pixel point to be filtered is required to be acquired according to the characteristic expression of the pixel points to be filtered, and the filtering of different scales of the pixel points to be filtered is realized.
It should be further explained that, the pixel points to be filtered in the transmission gear image are obtained, but when there is a crack in the transmission gear image, the crack edge and the texture edge of the gear belong to edge pixel points, and have a certain degree of gray mutation, so that the obtained transmission gear contains the pixel points of the texture edge of the gear, and possibly also contains the pixel points of the crack edge, but the pixel points of the texture edge of the gear and the pixel points of the crack edge have a certain difference in distribution, the pixel points of the texture edge of the gear have the characteristics of linear arrangement and have a periodic distribution rule, and the pixel points of the crack edge have no characteristics due to the irregularity of the crack, therefore, the forgetting factor of each pixel point to be filtered can be obtained according to the coincidence degree of the periodicity and the linear characteristics of each pixel point to be filtered, further the adjustment of the filtering scale of each pixel point to be realized, when the coincidence degree of the pixel point to be filtered is higher, the pixel points to be filtered are more likely to be the pixel points of the texture edge of the gear, and the pixel points to be filtered are more than the pixel points to be filtered, and the pixel points to be filtered are better in the filter line to be filtered, and the pixel to be filtered are collected at intervals.
In the embodiment of the invention, any one of the to-be-filtered pixel points in the transmission gear image is marked as a first to-be-filtered pixel point, the vertical direction of the gradient direction of the first to-be-filtered pixel point is obtained, other to-be-filtered pixel points in the vertical direction of the gradient direction of the first to-be-filtered pixel point and the gradient direction of the first to-be-filtered pixel point are marked as a first texture set, marking is carried out, any one of the unlabeled to-be-filtered pixel points in the transmission gear image is marked as a second to-be-filtered pixel point, the vertical direction of the gradient direction of the second to-be-filtered pixel point is obtained, other unlabeled to-be-filtered pixel points in the vertical direction of the gradient direction of the second to-be-filtered pixel point and the gradient direction of the current to-be-filtered pixel point are marked as a second texture set, and so on until all to-be-filtered pixel points in the transmission gear image are marked and can be stopped, and a plurality of texture sets are obtained.
Constructing a Cartesian coordinate system by taking an L-th pixel point to be filtered in an L-th texture set as an origin, taking the horizontal direction of the L-th pixel point to be filtered in the L-th texture set as an X axis and taking the vertical direction as a Y axis, acquiring the position coordinate of each pixel point to be filtered in the L-th texture set, and performing straight line fitting on all the pixel points to be filtered in the L-th texture set by adopting a least square method according to the position coordinate of each pixel point to be filtered in the L-th texture set to obtain a fitting straight line of the L-th texture set;
The perpendicular bisector of the fitting straight line of the L-th texture set is obtained, the texture set which is on the left side of the fitting straight line of the L-th texture set and corresponds to the nearest fitting straight line intersecting with the perpendicular bisector of the fitting straight line of the L-th texture set is marked as one adjacent texture set of the L-th texture set, and the texture set which is on the right side of the fitting straight line of the L-th texture set and corresponds to the nearest fitting straight line intersecting with the perpendicular bisector of the fitting straight line of the L-th texture set is marked as the other adjacent texture set of the L-th texture set.
According to the method for acquiring the distance between two non-parallel line segments, the distance between the fitting straight line of the L-th texture set and the fitting straight line of each adjacent texture set of the L-th texture set is acquired and is recorded as the distance between the L-th texture set and each adjacent texture set of the L-th texture set.
The possibility that the L-th texture set is the texture of the gear is obtained:
;
In the method, in the process of the invention,Representing the possibility that the L-th texture set is the texture of the gear itself; /(I)Representing a distance between the L-th texture set and one of the adjacent texture sets of the L-th texture set; /(I)Representing the distance between the L-th texture set and another adjacent texture set of the L-th texture set; the absolute value symbol is represented by the absolute value.
S003, acquiring an initial forgetting factor of each pixel point to be filtered in each texture set according to the possibility that each texture set is the texture of the gear and the gray level mutation degree of each pixel point to be filtered in each texture set; according to the initial forgetting factor of each pixel point to be filtered in each texture set and the possibility that each texture set is the texture of the gear, the forgetting factor of each pixel point to be filtered in each texture set is obtained to carry out filtering processing on the transmission gear image, and the transmission gear image after the filtering processing is obtained.
It should be noted that, it is known that, when the vertical distance between any pixel point to be filtered in any texture set and the fitted line of the texture set is smaller, the degree of importance of the pixel point to be filtered in the texture set to the texture set can be reflected, and when the vertical distance is smaller, the degree of deviation of the pixel point to be filtered in the texture set relative to the fitted line of the texture set is smaller, the degree of importance of the pixel point to be filtered in the texture set is higher, the initial forgetting factor of the pixel point to be filtered in the texture set is larger, and when the possibility that the texture set is a gear self texture is higher, the gray scale mutation degree of the pixel point to be filtered in the texture set is larger, the initial forgetting factor of the pixel point to be filtered in the texture set is larger, so that the initial forgetting factor of each pixel point to be filtered in each texture set is obtained.
In the embodiment of the invention, the initial forgetting factor of the s-th pixel point to be filtered in the L-th texture set is obtained:
;
In the method, in the process of the invention,Representing an initial forgetting factor of an s-th pixel point to be filtered in the L-th texture set; /(I)Representing the vertical distance from the s-th pixel point to be filtered in the L-th texture set to the fitting straight line of the L-th texture set; /(I)Representing the likelihood that the L < th > texture set is the texture of the gear itself,/>Representing the gray level mutation degree of the s-th pixel point to be filtered in the L-th texture set; exp () represents an exponential function based on a natural constant, and in the embodiment of the present invention, an exp (-x) model is used to represent an inverse proportion relation and normalization processing, x represents an input of the model, and an implementer can set the inverse proportion function and the normalization function according to specific implementation situations.
It should be noted that, when the probability that any texture set is the texture of the gear itself is greater, it is described that a larger forgetting factor needs to be given to all pixels to be filtered in the texture set, the texture of the gear itself is smoothed out, and when the probability that any texture set is the texture of the gear itself is smaller, it is described that a smaller forgetting factor needs to be given to all pixels to be filtered in the texture set, so as to highlight the crack edge expression.
In the embodiment of the invention, a possibility threshold T is preset, and when the possibility that the L-th texture set is the gear texture is greater than or equal to the possibility threshold T, the L-th texture set is the gear texture, and the forgetting factor of the s-th pixel point to be filtered in the L-th texture set is the initial forgetting factor of the s-th pixel point to be filtered in the L-th texture set; when the probability that the L-th texture set is the gear texture is smaller than the probability threshold T, the L-th texture set is a crack edge, and the forgetting factor of the s-th pixel point to be filtered in the L-th texture set isIn the embodiment of the present invention, the probability threshold t=0.92 is preset, and in other embodiments, the operator may preset the value of the probability threshold T according to the specific implementation.
The forgetting factor of each pixel point to be filtered in each texture set is obtained, and according to the forgetting factor of each pixel point to be filtered in each texture set, each pixel point to be filtered in the transmission gear image is subjected to filtering processing by using an RLS filtering algorithm to obtain a transmission gear image after the filtering processing.
S004, carrying out crack defect detection according to the transmission gear image after the filtering treatment.
In the embodiment of the invention, a large number of transmission gear images with crack defects are used, a neural network model is trained, the transmission gear images after the filtering treatment are input into the trained neural network model for crack defect identification, and if the transmission gear images after the filtering treatment are detected to have crack defects, early warning is sent out to remind relevant staff to carry out treatment.
The above description is only of the preferred embodiments of the present invention and is not intended to limit the invention, but any modifications, equivalent substitutions, improvements, etc. within the principles of the present invention should be included in the scope of the present invention.