Multi-target template matching optimization method for gear defect detection
By using a multi-objective template matching optimization method, the problem of large computational load and complex environment in gear defect detection is solved, and efficient and accurate gear defect detection is achieved.
Patent Information
- Application Number
- CN202510969564.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-15
- Publication Date
- 2025-10-31
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing technologies for gear defect detection involve large computational loads, low efficiency in rotating template matching, and fail to effectively handle complex factory environments and special situations involving photographic imaging effects, leading to missed or false detections.
A multi-target template matching optimization method is adopted, including image preprocessing, multi-angle template matching, Kd-tree classification matching, non-maximum suppression, anomaly handling, and rotational cropping. The image processing flow is optimized through steps such as cropping and rotation correction, which reduces the amount of computation and improves the detection accuracy.
It improves the efficiency and accuracy of gear defect detection, adapts to complex factory environments, reduces missed and false detections, and meets the needs for rapid and accurate detection.
Smart Images

Figure CN120876803A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision inspection technology, and more specifically, to a multi-target template matching optimization method for gear defect detection. Background Technology
[0002] Defect detection is an indispensable part of industrial production. Factory environments are often complex and changeable, with high inspection requirements and large demand, necessitating fast and accurate algorithms. This poses a significant challenge to template-based algorithms. Currently, the demand for gear inspection in factories is high, requiring a fast and accurate inspection solution. Due to the uncertainty of defects, AI methods are needed, but these models generally require significant computation. Therefore, classification models are used for rapid prediction. However, the challenge then becomes how to process the image into a format suitable for the classification model. The goal is to detect defects on the gear tip, so it's necessary to eliminate other factors from the image and obtain images with the same gear tip position and size. This requires rotating template matching to obtain the desired image.
[0003] Rotational template matching is a method that takes all angles within a range and rotates them to obtain a position that approximates the template. However, template matching is computationally intensive and requires template matching for each angle, making it an optimization problem.
[0004] Currently, the broad rotation template matching does not take into account the optimization space of gears, nor does it take into account the unexpected situations that may occur during detection. Therefore, customized optimization and processing are required for gear scenarios.
[0005] In addition, the camera can take 20 photos of a gear. By controlling the field of view, each photo must show at least eight complete tooth tips or two near the edge, for a total of nine complete tooth tips. At least eight complete tooth tips must be cropped, or at least a few images can be cropped to show nine complete tooth tips; omissions are not allowed. Furthermore, the cropped images must be saved according to the original image ratio, and the images must be upright, with no right angles allowed. The operation is complex and tedious. Summary of the Invention
[0006] The purpose of this invention is to overcome the shortcomings of the existing technology and propose a multi-objective template matching optimization method for gear defect detection.
[0007] To solve the above problems, the present invention adopts the following technical solution:
[0008] A multi-objective template matching optimization method for gear defect detection includes the following steps:
[0009] 1. Capture the image with the camera to obtain the original high-resolution image;
[0010] 2. Image preprocessing: The original high-resolution image is reduced to low resolution. The highest non-boundary edge point of the lowest black contour and the lowest non-boundary edge point of the highest white contour are detected in the image. Their approximate positions in the original image are calculated. The original image is cropped after adding a cropping margin, and the image is output as a 0.1x reduced image for subsequent processing.
[0011] 3. Multi-angle template matching: Manually crop and align the template image, and perform binarization to eliminate noise on the gear surface; rotate the template within a preset angle range, and divide the matching area into positive and negative angle groups based on the x-value of the highest point of the tooth tip to generate a multi-angle fractional image;
[0012] IV. Kd-tree classification and matching: When there are too many matching positions in the score graph, Kd-trees are used to cluster candidate boxes to reduce the computational cost of non-maximum suppression.
[0013] V. Non-maximum suppression: Based on the non-parallel characteristics of gear tooth tips, the candidate boxes with the highest scores are selected from each score map. After sorting by score, the intersection rate between boxes is calculated, low-scoring and highly overlapping boxes are eliminated, and the optimal candidate boxes are retained.
[0014] VI. Handling of Abnormal Situations: If the number of matching boxes is insufficient or the distribution is abnormal, construct an arithmetic function based on the x-values of the already matched boxes to complete the local matching at the missing positions; if the number of matching boxes exceeds the limit, filter redundant boxes through the integrity threshold.
[0015] 7. Rotation Screenshot: Based on the rotation angle and center determined by the matching results, the cropped original image area is rotated and corrected, and a standardized image is output for the AI model to perform gear defect detection.
[0016] As a further aspect of the present invention: in the preprocessing step, the upper and lower limits of cropping are determined by multiplying the edge point positions of the low-resolution image by a magnification factor and adding a margin, to ensure that the key areas of the original image are completely preserved.
[0017] As a further aspect of the present invention: in the Kd-tree classification step, the Kd-tree is used to perform spatial indexing on high-scoring candidate boxes, quickly merge neighboring boxes, and reduce the traversal overhead of non-maximum suppression.
[0018] As a further aspect of the present invention: in the non-maximum suppression step, the matching box of the gear tooth tip must satisfy the angle uniqueness, each score image retains only the optimal matching box, and finally filters according to the global score and overlap rate.
[0019] As a further aspect of the present invention: in the abnormal situation handling step, if the number of matching boxes is insufficient, an arithmetic sequence is fitted based on the x-coordinate of the already matched boxes, and positive or negative angle matching is searched at the missing position.
[0020] As a further aspect of the present invention: in the rotation screenshot step: first, the target area is cropped and reduced in size in the original image, and then the toothed area is cropped after rotation correction, so as to balance calculation efficiency and output quality.
[0021] Compared with the prior art, the advantages of this invention are:
[0022] This invention provides an optimized method for gear defect detection. By employing rotating template matching, non-maximum suppression to remove redundant selection boxes, kd-tree selection of non-maximum suppression boxes, arithmetic sequence handling of abnormal cases, preprocessing to reduce the area requiring matching, and parallel template matching and post-processing, the efficiency of rotating template matching is greatly improved. It can also adapt to similar circumferential search problems. Only simple parameter modifications are needed to handle special cases and avoid missed or false detections. Taking into account the special characteristics of gear defects and photographic imaging effects, customized optimization is performed through an unsupervised model to meet the fast-paced requirements of gear production. Attached Figure Description
[0023] Figure 1 This is a schematic diagram of the process of the present invention;
[0024] Figure 2 The original image that needs to be manipulated;
[0025] Figure 3 The result image after the execution is complete. Detailed Implementation
[0026] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0027] Please see Figure 1 A multi-objective template matching optimization method for gear defect detection includes the following steps:
[0028] 1. Capture the image with the camera to obtain the original high-resolution image;
[0029] II. Image Preprocessing: The original high-resolution image is downsized to a low resolution. The highest non-boundary edge point of the lowest black contour and the lowest non-boundary edge point of the highest white contour are detected in the image. Their approximate positions in the original image are calculated. A cropping margin is added, and the original image is cropped. An image downsized to 0.1 times is output for subsequent processing. The upper and lower cropping limits are determined by multiplying the edge point positions of the low-resolution image by a scaling factor and adding a margin, ensuring that key areas of the original image are completely preserved.
[0030] 3. Multi-angle template matching: Manually crop and align the template image, and perform binarization to eliminate noise on the gear surface; rotate the template within the preset angle range, and divide the matching area into positive and negative angle groups based on the x-value of the highest point of the tooth tip, generating a multi-angle fractional image.
[0031] IV. Kd-tree Classification and Matching: When there are too many matching positions in the score graph, Kd-trees are used to cluster candidate boxes, reducing the computational cost of non-maximum suppression. Kd-trees are used for spatial indexing of high-scoring candidate boxes, quickly merging neighboring boxes and reducing the traversal overhead of non-maximum suppression.
[0032] V. Non-maximum suppression: Based on the non-parallel characteristic of gear tooth tips, the candidate boxes with the highest scores are selected from each score map. After sorting by score, the intersection rate between boxes is calculated, and low-scoring, highly overlapping boxes are eliminated, retaining the optimal candidate boxes. The matching boxes of gear tooth tips must satisfy the angular uniqueness requirement. Only the optimal matching box is retained from each score map, and finally, the selection is based on the global score and overlap rate.
[0033] VI. Handling Abnormal Situations: If the number of matching boxes is insufficient or their distribution is abnormal, an arithmetic progression function is constructed based on the x-values of the already matched boxes to fill in the missing matches at the missing positions. Specifically, an arithmetic progression is fitted based on the x-coordinates of the already matched boxes, and positive or negative angle matches are searched for at the missing positions.
[0034] If the number of matching boxes exceeds the limit, redundant boxes are filtered out using an integrity threshold.
[0035] 7. Rotation Screenshot: Based on the rotation angle and center determined by the matching results, the cropped original image area is rotated and corrected, and a standardized image is output for the AI model to perform gear defect detection. The target area is first cropped and reduced in size from the original image, then rotated and corrected before cropping the tooth area to balance computational efficiency and output quality.
[0036] Application Example 1 based on the above scheme: Multi-objective template matching optimization method for gear defect detection:
[0037] Includes: camera image capture; image preprocessing; multi-angle template matching; kd-tree classification matching; non-maximum suppression selection of matching boxes; anomaly handling; and rotational screenshotting.
[0038] Image preprocessing specifically involves: processing the original 5k*5k image (e.g., ...) Figure 2The image is resized to 0.05 times, resulting in a 250*250 image. The edge point with the highest y-value among the non-image boundaries of the black outline with the lowest y-value is found. Then, the edge point with the lowest y-value among the non-image boundaries of the white outline with the highest y-value is found. The y-values of these two edge points are multiplied by a scaling factor of 20 to obtain their approximate positions in the original image. After adding a certain cropping allowance, the original 5k*5k image is cropped as upper and lower limits, and a resized image to 0.1 times is output for subsequent calculations and processing.
[0039] The rotation template matching process involves manually cropping a template image, manually rotating and aligning it to the original aspect ratio, and binarizing it to remove the effects of roughness and noise on the gear. Based on the possible angle range of the gear, assumed to be -40 degrees to 40 degrees, step 2 is used. Since the gear is a circle, the tooth with the highest point is generally closer to 0 degrees. Therefore, template matching can use the x-value of this point as a dividing line. After adding a small margin, teeth on one side only need to be matched for negative angles, and teeth on the other side only need to be matched for positive angles. This is equivalent to cropping the image again and iterating through all angles of the template to obtain 80 template-matched score images.
[0040] Kd-tree classification works as follows: when there are too many qualified positions in the fractional graph, the computational cost of non-maximum suppression is too high; using a kd-tree to classify the neighboring boxes of possible boxes reduces the computational cost.
[0041] Non-maximum suppression works as follows: taking advantage of the fact that gears cannot have parallel teeth, only the top position needs to be taken from each angle score image. This will select the position of one tooth. In theory, the top of 80 images is assigned to 8 positions, and each tooth may have about 10 top positions. Then, after sorting the top scores of the 80 score images, the intersection rate required for non-maximum suppression is calculated using a kd-tree, and boxes with high intersection rates and low scores are deleted.
[0042] The anomaly handling is as follows: If a tooth tip has a defect, it may cause the corresponding angle to have a lower score when taken as the top, even lower than the score affected by the angle. In this case, the template matching result may have lower than the basic image features of at least eight boxes. The x-values of the matched boxes follow an arithmetic distribution, and the difference is allowed to fluctuate within a certain range. An arithmetic function is constructed using the x-values of the successfully matched boxes. If a position in the image may exist but does not, a portion of the position is selected with a margin, and a rotating template matching is performed on this position with only positive or only negative values. If the tooth tip is close to the edge, it may select nine gear positions. Here, a simple threshold is used to exclude the ninth position because it is not complete.
[0043] The rotation screenshot process involves cropping the original image to ensure it's output at its original scale. To eliminate the influence of the angle on the subsequent AI model, the image needs to be rotated correctly first. The rotation angle and rotation center can be obtained from the calculations above. However, rotating the original image is computationally intensive, so we first crop and reduce its size, then rotate and crop again to output a standardized image for the AI model to perform gear defect detection. Figure 3 As shown.
[0044] The above description is merely a preferred embodiment of the present invention; however, the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and its improved concepts, should be covered within the scope of protection of the present invention.
Claims
1. A multi-objective template matching optimization method for gear defect detection, characterized in that: Includes the following steps:
1. Capture the image with the camera to obtain the original high-resolution image; 2. Image preprocessing: The original high-resolution image is reduced to low resolution. The highest non-boundary edge point of the lowest black contour and the lowest non-boundary edge point of the highest white contour are detected in the image. Their approximate positions in the original image are calculated. The original image is cropped after adding a cropping margin, and the image is output as a 0.1x reduced image for subsequent processing.
3. Multi-angle template matching: Manually crop and align the template image, and perform binarization to eliminate noise on the gear surface; rotate the template within a preset angle range, and divide the matching area into positive and negative angle groups based on the x-value of the highest point of the tooth tip to generate a multi-angle fractional image; IV. Kd-tree classification and matching: When there are too many matching positions in the score graph, Kd-trees are used to cluster candidate boxes to reduce the computational cost of non-maximum suppression. V. Non-maximum suppression: Based on the non-parallel characteristics of gear tooth tips, the candidate boxes with the highest scores are selected from each score map. After sorting by score, the intersection rate between boxes is calculated, low-scoring and highly overlapping boxes are eliminated, and the optimal candidate boxes are retained. VI. Handling of Abnormal Situations: If the number of matching boxes is insufficient or the distribution is abnormal, construct an arithmetic function based on the x-values of the already matched boxes to complete the local matching at the missing positions; if the number of matching boxes exceeds the limit, filter redundant boxes through the integrity threshold.
7. Rotation Screenshot: Based on the rotation angle and center determined by the matching results, the cropped original image area is rotated and corrected, and a standardized image is output for the AI model to perform gear defect detection.
2. The multi-objective template matching optimization method for gear defect detection according to claim 1, characterized in that: In the preprocessing step, the upper and lower limits of cropping are determined by multiplying the edge point positions of the low-resolution image by a magnification factor and adding a margin, ensuring that the key areas of the original image are completely preserved.
3. The multi-objective template matching optimization method for gear defect detection according to claim 1, characterized in that: In the Kd-tree classification step, the Kd-tree is used to spatially index high-scoring candidate boxes, quickly merge neighboring boxes, and reduce the traversal overhead of non-maximum suppression.
4. The multi-objective template matching optimization method for gear defect detection according to claim 1, characterized in that: In the nonmaximum suppression step, the matching box of the gear tooth tip must satisfy the angle uniqueness, and only the optimal matching box is retained for each score image. Finally, the selection is based on the global score and the overlap rate.
5. The multi-objective template matching optimization method for gear defect detection according to claim 1, characterized in that: In the abnormal situation handling steps, if the number of matching boxes is insufficient, an arithmetic sequence is fitted based on the x-coordinate of the already matched boxes, and positive or negative angle matching is searched at the missing position.
6. The multi-objective template matching optimization method for gear defect detection according to claim 1, characterized in that: In the rotation screenshot step: first, the target area is cropped and reduced in size in the original image, then rotated and corrected before cropping the toothed area, in order to balance computational efficiency and output quality.