Disclosure of Invention
In order to solve the technical problems, the invention aims to provide a method and a system for detecting the defects of the gear based on template matching, and the adopted technical scheme is as follows:
the embodiment of the invention provides a gear defect detection method based on template matching, which comprises the following specific steps:
respectively collecting gear images of each gear in the same batch to obtain corresponding gray level images;
performing image segmentation on the current gray level image to obtain a tooth body image and a tooth image, and acquiring the similarity between the tooth body and a standard circle by combining the tooth body radius in the tooth image and the position difference between adjacent pixel points on the edge of the tooth body based on the circular characteristic of the tooth body, wherein the standard circle is the tooth body circular standard required by production; acquiring a tooth body standard template according to the similarity degree of the tooth body in each gray level image;
acquiring a length difference value of teeth according to the straight line lengths of two tooth roots of one tooth in the tooth image; carrying out angular point detection on the tooth profile to divide a curve corresponding to an addendum into a plurality of sub-curves, dividing the plurality of sub-curves into an arc curve and a non-arc curve, carrying out self-adaptive adjustment on an accumulator threshold value in the Hough gradient method according to the number of pixel points on the arc curve or the non-arc curve, and obtaining a first circle center corresponding to each arc curve and a second circle center corresponding to each non-arc curve through the adjusted accumulator threshold value; based on the symmetry of the tooth profile, calculating a symmetry difference value of the tooth profile according to the position deviation of a plurality of first circle centers, and acquiring a non-circular arc curve abnormal value according to the distance between each second circle center and the adjacent first circle center; combining the length difference value, the symmetry difference value and the non-circular arc curve abnormal value to obtain the abnormal degree of the teeth, and obtaining a tooth standard template according to the abnormal degree of each tooth in each gray level image;
and detecting the defects of the gear in each gear image based on the gear body standard template and the gear tooth standard template.
Further, the method for obtaining the similarity between the tooth body and the standard circle by combining the tooth body radius in the tooth image and the position difference between the adjacent pixel points on the edge of the tooth body includes:
carrying out Hough circle detection on the tooth body to obtain the radius of the tooth body, and comparing the radius of the tooth body with the radius of a standard tooth body to obtain a radius difference index;
forming a straight line by every two adjacent pixel points on the edge of the tooth body, calculating a straight line angle difference value between two straight lines corresponding to each pixel point to obtain an average angle difference value corresponding to the edge of the tooth body, and obtaining a circular difference index according to the difference between the straight line angle difference value and the average angle difference value of each pixel point;
and combining the radius difference index and the circle difference index to obtain the similarity degree.
Further, the method for dividing the plurality of sub-curves into circular-arc curves and non-circular-arc curves comprises the following steps:
and calculating the average angle difference value corresponding to each sub-curve, and dividing the sub-curves into circular arc curves and non-circular arc curves by using a k-means clustering method according to the difference of the average angle difference values between any two sub-curves.
Further, the method for adaptively adjusting the threshold of the accumulator in the hough gradient method according to the number of the pixels on the circular arc curve or the non-circular arc curve comprises the following steps:
obtaining an initial accumulator threshold of the arc curve according to the number of the pixel points on the arc curve and the minimum number of the pixel points required by the circle; obtaining an initial accumulator threshold of the non-circular-arc curve according to the number of pixels on the non-circular-arc curve and the minimum number of pixels required by the circle;
and obtaining a plurality of initial circle centers corresponding to the tooth profile based on the initial accumulator threshold, and respectively adjusting the initial accumulator threshold of the arc curve and the non-arc curve according to the number of the initial circle centers to obtain a corresponding new accumulator threshold.
Further, the method for calculating the symmetry difference value of the tooth profile according to the position deviation of the plurality of first circle centers comprises the following steps:
and obtaining a symmetry line of the tooth profile according to two tooth root straight lines of the teeth, respectively calculating the distance between each first circle center and the symmetry line, arranging the distances from small to large to obtain a distance sequence, and obtaining the symmetry difference value according to a distance difference value between two adjacent distances in the distance sequence.
Further, the method for obtaining the abnormal value of the non-circular arc curve according to the distance between each second circle center and the adjacent first circle center thereof comprises the following steps:
acquiring the Euclidean distance between any two circle centers of the second circle center and two adjacent first circle centers to obtain a position characteristic value of the second circle center; and combining the position characteristic value of each second circle center to obtain the abnormal value of the non-circular arc curve.
Further, the method for detecting the defects of the gear in each gear image based on the gear body standard template and the gear tooth standard template comprises the following steps:
performing first similarity calculation on the tooth body and the tooth body standard template in each gear image, and performing second similarity calculation on the teeth and the tooth standard template; setting a similarity threshold, comparing the first similarity and the second similarity with the similarity threshold respectively, and determining whether the gear has defects according to the comparison result.
Further, an embodiment of the present invention further provides a gear defect detecting system based on template matching, including a memory, a processor, and a computer program stored in the memory and running on the processor, where the processor implements the steps of any one of the above-mentioned gear defect detecting methods based on template matching when executing the computer program.
The embodiment of the invention at least has the following beneficial effects: the gear body template and the gear template of the gear are obtained in a self-adaptive mode through characteristic analysis of the gears in the same batch, and defect detection is carried out on the gears in the batch based on the gear body template and the gear template, so that the accuracy of the defect detection of the gears is guaranteed, and the use of unqualified gears is reduced.
Detailed Description
To further illustrate the technical means and effects of the present invention adopted to achieve the predetermined objects, the following detailed description of the embodiments, structures, features and effects of the method and system for detecting gear defects based on template matching according to the present invention will be made with reference to the accompanying drawings and preferred embodiments. In the following description, the different references to "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
The following describes a specific scheme of the gear defect detection method and system based on template matching in detail with reference to the accompanying drawings.
Referring to fig. 1, a flowchart of steps of a method for detecting gear defects based on template matching according to an embodiment of the present invention is shown, where the method includes the following steps:
and S001, respectively collecting the gear images of each gear in the same batch to obtain corresponding gray level images.
Specifically, in the embodiment of the present invention, an industrial camera is used to collect a corresponding gear image for each gear in the same batch in a form of a fixed light source, the collected gear image is an RGB image, and a graying process is performed on each RGB image in a weighted manner to obtain a corresponding grayscale image, where the graying process is performed in a manner of:
wherein,
is a gray value;
pixel values of three channels in the RGB image, respectively.
Step S002, performing image segmentation on the current gray level image to obtain a tooth body image and a tooth image, and acquiring the similarity between the tooth body and a standard circle by combining the tooth body radius in the tooth image and the position difference between adjacent pixel points on the edge of the tooth body based on the circular characteristic of the tooth body, wherein the standard circle refers to the circular standard of the tooth body required by production; and acquiring a tooth body standard template according to the similarity of the tooth body in each gray level image.
Specifically, the gear can be divided into two main parts, one part is the gear body of the gear, and the other part is the gear teeth of the gear, so that canny operator detection is carried out on the gray level image to obtain edge information of the gear, and the gray level image is divided into the gear body image and the gear teeth image according to the edge information.
According to priori knowledge, the gear body of the gear is usually circular, the closer the gear body is to the circular shape, the more standard the gear body is, the smaller defects are, therefore, the similarity between the gear body and a standard circle is analyzed according to the circular characteristic of the gear body, wherein the standard circle refers to the circular standard of the gear body required by production, and the analysis process of the similarity is as follows:
(1) and carrying out Hough circle detection on the tooth body to obtain the radius of the tooth body, and comparing the radius of the tooth body with the radius of a standard tooth body to obtain a radius difference index.
Specifically, a minimum circumscribed circle of the tooth body is obtained by using a Hough circle detection method, and then the radius of the minimum circumscribed circle is obtained and is used as the radius of the tooth body. Because gear production has the size requirement, then calculate the radius difference index of tooth body according to the difference between the standard tooth body radius that production required and the tooth body radius, then the computational formula of radius difference index is:
wherein,
is an index of radius difference;
is the tooth body radius;
is a standard tooth body radius.
(2) Every two adjacent pixel points on the edge of the tooth body form a straight line, the straight line angle difference between the two straight lines corresponding to each pixel point is calculated to obtain the average angle difference corresponding to the edge of the tooth body, and the circular difference index is obtained according to the difference between the straight line angle difference and the average angle difference of each pixel point.
Specifically, according to the priori knowledge, the change of the circular edge is smooth and uniform, so that in the embodiment of the invention, each pixel point and the adjacent pixel points in front and back of each pixel point form a straight line respectively, the straight line angle formed between each straight line and the horizontal straight line is obtained, and the straight line angle difference value between the straight line angles of the two straight lines corresponding to each pixel point is calculated
(ii) a Calculating the average angle according to the linear angle difference of each pixel point on the edge of the tooth bodyAnd (3) the difference value is further analyzed to obtain a circular difference index of the tooth body by analyzing the difference between the linear angle difference value and the average angle difference value of each pixel point, and the calculation formula of the circular difference index is as follows:
wherein,
is a circular difference index;
is as follows
The linear angle difference of each pixel point;
is the average angle difference;
the number of pixel points on the edge of the tooth body.
(3) And combining the radius difference index and the circle difference index to obtain the similarity.
In particular, degree of similarity
The calculation formula of (2) is as follows:
wherein the degree of similarity
The larger the size, the more satisfactory the tooth body.
Further, by using the analysis method of the similarity degree, the similarity degree of the tooth body in each gray level image is obtained, and then the tooth body image corresponding to the maximum value of the similarity degree is used as a tooth body standard template.
Step S003, acquiring a length difference value of the teeth according to the straight line length of two tooth roots of one tooth in the tooth image; carrying out angular point detection on the tooth profile to divide a curve corresponding to an addendum into a plurality of sub-curves, dividing the plurality of sub-curves into an arc curve and a non-arc curve, carrying out self-adaptive adjustment on an accumulator threshold value in the Hough gradient method according to the number of pixel points on the arc curve or the non-arc curve, and obtaining a first circle center corresponding to each arc curve and a second circle center corresponding to each non-arc curve through the adjusted accumulator threshold value; based on the symmetry of the tooth profile, calculating a symmetry difference value of the tooth profile according to the position deviation of a plurality of first circle centers, and acquiring a non-circular arc curve abnormal value according to the distance between each second circle center and the adjacent first circle center; and combining the length difference value, the symmetry difference value and the non-circular arc curve abnormal value to obtain the abnormal degree of the teeth, and acquiring a tooth standard template according to the abnormal degree of each tooth in each gray level image.
Specifically, the tooth profile itself is composed of a straight line and a circular arc, and referring to fig. 2, a schematic diagram of a tooth profile is shown, where the tooth is composed of a tooth root straight line 1, a tooth root straight line 2, and sub-curves 3-10, so that hough straight line detection is performed on any tooth in a tooth image to obtain two tooth root straight lines, the lengths of the two tooth root straight lines are obtained by a chain code method, and a length abnormal value of the tooth is obtained by comparing a standard tooth root straight line length required by production, and then a calculation formula of the length abnormal value is:
wherein,
in the form of a length outlier,
is a standardThe length of the straight line of the tooth root,
for the first root straight length,
the second root linear length.
Furthermore, since the tooth profile is formed of irregular curves, the curve corresponding to the tooth crest can be divided into a plurality of sub-curves by detecting the corner point of the tooth profile. Considering that a small irregular curve appears on an addendum due to machining defects in the gear machining process, and the smaller the curve is, the smaller the influence on the quality of the gear is, the sub-curves are divided into arc curves and non-arc curves, and the dividing method is as follows: and calculating the average angle difference corresponding to each sub-curve by using the method for acquiring the linear angle difference of each pixel point in the step S002, and dividing the plurality of sub-curves into arc curves and non-arc curves by using a k-means clustering method according to the difference of the average angle differences between any two sub-curves.
The circle center corresponding to each sub-curve is obtained by using a Hough gradient method for the circular arc curve and the non-circular arc curve, the Hough gradient method finds the circle center according to the modulus vector of each pixel point, and the circle center is determined by voting, namely, the circle center is determined based on the threshold value of an accumulator in the Hough gradient method, so that the threshold value of the accumulator in the Hough gradient method is adaptively adjusted according to the number of the pixel points on the circular arc curve or the non-circular arc curve, and the adjusting process is as follows:
(1) obtaining an initial accumulator threshold of the arc curve according to the number of the pixel points on the arc curve and the minimum number of the pixel points required by the circle; and obtaining the initial accumulator threshold of the non-circular arc curve according to the number of the pixel points on the non-circular arc curve and the minimum number of the pixel points required by the circle.
Specifically, when circle detection is performed, a circle can be determined by 3 pixels on the circumference, and therefore initial accumulator threshold values are respectively performed on an arc curve and a non-arc curve according to the minimum number of pixels required for determining the circleObtaining, for the arc curve, firstly counting the number of pixels on the arc curve, and obtaining the initial accumulator threshold of the arc curve by combining the number of pixels and the minimum number, where the calculation formula of the initial accumulator threshold is:
wherein, in the process,
the initial accumulator threshold for the circular arc curve,
the number of pixel points on the arc curve; for a non-circular arc curve, firstly counting the number of pixels on the non-circular arc curve, and obtaining an initial accumulator threshold of the non-circular arc curve by combining the number of the pixels and the minimum number, wherein the calculation formula of the initial accumulator threshold is as follows:
wherein
the initial accumulator threshold for the circular arc curve,
the number of pixels on the arc curve.
(2) And obtaining a plurality of initial circle centers corresponding to the tooth profile based on the initial accumulator threshold, and respectively adjusting the initial accumulator threshold of the arc curve and the non-arc curve according to the number of the initial circle centers to obtain a corresponding new accumulator threshold.
Specifically, under an ideal condition, each circular arc curve or non-circular arc curve has only one circle center, and an oversize or undersize threshold of the initial accumulator affects circle center detection, that is, an oversize threshold of the initial accumulator causes no circle center to be detected, and an undersize causes an oversize shadow of the calculated circle center to be subsequently determined, so that the initial accumulator thresholds of the circular arc curve and the non-circular arc curve are respectively adjusted according to a plurality of initial circle centers corresponding to tooth profiles obtained by the initial accumulator threshold to obtain corresponding new accumulator thresholds, and then the adjustment formula is as follows:
wherein,
in order for the new accumulator threshold to be reached,
an initial accumulator threshold for a curved arc or a non-curved arc,
;
the number of the initial circle centers.
And performing corresponding circle center detection on the arc curves and the non-arc curves by using the new accumulator threshold value to obtain a first circle center corresponding to each arc curve and a second circle center corresponding to each non-arc curve.
Further, according to the priori knowledge, the left and right profiles of the teeth are usually left-right symmetrical, so that the stronger the obtained circle center symmetry is, the more the production of the teeth meets the standard. Based on the symmetry of the tooth profile, calculating the symmetry difference value of the tooth profile according to the position deviation of a plurality of first circle centers corresponding to the circular arc curve, wherein the method comprises the following steps: the method comprises the steps of obtaining a symmetry line of a tooth profile according to two straight tooth root lines of teeth, respectively calculating the distance between each first circle center and the symmetry line, arranging the distances from small to large to obtain a distance sequence, and obtaining a symmetry difference value according to a distance difference value between two adjacent distances in the distance sequence.
As an example, the center position between two center points is obtained from the center point of each root straight line
Making a vertical line based on the central position, wherein the vertical line is a symmetrical line of the tooth profile; respectively calculating the distance from each first circle center to the symmetry line, knowing the calculated distance from the symmetry of the tooth profile as an even number, then arranging the distances from small to large to obtain a distance sequence, setting every two adjacent distances in the distance sequence as a group, respectively calculating the distance difference between two distances in each group, and accumulating the distance differences in each group to obtain a symmetry difference value
。
Considering that a non-circular arc curve generally exists between two circular arc curves, when the distance between the second center of the non-circular arc curve and the first center of the circular arc curve is close enough, the non-circular arc curve does not affect the performance of the gear, therefore, the abnormal value of the non-circular arc curve is calculated according to the distance between the second center of the non-circular arc curve and the adjacent first center, and the method comprises the following steps: acquiring the Euclidean distance between any two circle centers of the second circle center and two adjacent first circle centers to obtain a position characteristic value of the second circle center; and combining the position characteristic value of each second circle center to obtain a non-circular arc curve abnormal value.
As an example, assume that the second center of the circle is (
,
) The first circle center is respectively (
,
) And (a) and (b)
,
) Respectively calculate the second circle center (
,
) And a first center of a circle
,
) European distance between
The second circle center (
,
) And a first center of a circle
,
) European distance between
And a first center of a circle
,
) And a first center of a circle
,
) European distance between
Combined with Euclidean distance
European style distance
And Euclidean distance
Calculating the position characteristic value of the second circle center
The calculation formula is as follows:
(ii) a Then, the position characteristic values of a plurality of second circle centers are added to obtain abnormal values of the non-circular arc curves
。
Combining the length difference value, the symmetry difference value and the non-circular arc curve abnormal value to obtain the abnormal degree of the teeth, and determining the abnormal degree
The calculation formula of (2) is as follows:
further, the abnormal degree of each tooth in each gray level image is obtained by using the method for obtaining the abnormal degree of the tooth, and then the tooth image corresponding to the maximum abnormal degree is selected as a tooth standard template.
And step S004, detecting the defects of the gear in each gear image based on the gear body standard template and the gear tooth standard template.
Specifically, a first similarity calculation is carried out on a tooth body and a tooth body standard template in each gear image, and a second similarity calculation is carried out on teeth and the tooth standard template; and setting a similarity threshold, respectively comparing the first similarity and the second similarity with the similarity threshold, and determining whether the gear has defects according to the comparison result, namely when the first similarity and the second similarity are both greater than the similarity threshold, determining that the gear has no defects and meets the production requirements.
In summary, the embodiment of the present invention provides a method for detecting gear defects based on template matching, which includes acquiring gear images of each gear in the same batch to obtain corresponding grayscale images, dividing each grayscale image into a tooth body image and a tooth image, and analyzing the similarity of the tooth body in each tooth body image based on the circular characteristics of the tooth body to obtain a tooth body standard template; analyzing the abnormal degree of the teeth according to the symmetry difference value of the tooth profile and the length difference value of the tooth root straight line length of the teeth, and obtaining a tooth standard template according to the abnormal degree of each tooth image; and detecting the defects of the gear in each gear image based on the gear body standard template and the gear tooth standard template. The gear defect detection method has the advantages that the gear of the same batch is subjected to characteristic analysis, the gear body template and the gear template of the gear are obtained in a self-adaptive mode, the gear is subjected to defect detection based on the gear body template and the gear template, accuracy of the gear defect detection is guaranteed, and the use of unqualified gears is reduced.
Based on the same inventive concept as the method, the embodiment of the present invention further provides a gear defect detection system based on template matching, which includes a memory, a processor, and a computer program stored in the memory and running on the processor, and is characterized in that the processor implements the steps of any one of the above gear defect detection methods based on template matching when executing the computer program.
It should be noted that: the precedence order of the above embodiments of the present invention is only for description, and does not represent the merits of the embodiments. And specific embodiments thereof have been described above. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents, improvements and the like that fall within the spirit and principle of the present invention are intended to be included therein.