An image recognition-based compressed spring fault automatic detection method
By dividing the compressed spring image into local regions, dynamically calculating the adaptive threshold and combining it with shape matching, the accuracy problem of traditional edge detection algorithms in uneven lighting environments is solved, and efficient automatic fault detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG HERSHEY SPRING IND CO LTD
- Filing Date
- 2026-02-28
- Publication Date
- 2026-06-12
AI Technical Summary
Traditional edge detection algorithms, which use globally uniform threshold parameters, are difficult to adapt to the characteristics of extremely uneven lighting in compression spring detection, thus affecting detection accuracy and robustness.
The grayscale image of the compression spring is divided into local regions. An adaptive Canny edge detection high threshold is dynamically calculated based on the material reflectivity and deformation distortion of the local regions, and the fault is determined by combining the shape matching algorithm.
It significantly improves the accuracy and robustness of fault detection in complex lighting environments, avoids false edge interference, and realizes fully automated quality inspection.
Smart Images

Figure CN122199416A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology. More specifically, this invention relates to an automatic fault detection method for compression springs based on image recognition. Background Technology
[0002] Compression springs, as a widely used general-purpose basic component, play an indispensable role in many industrial fields such as automotive, electronics, and machinery manufacturing. They are primarily used for shock absorption, energy storage, and controlling the movement of mechanisms. Particularly in the field of high-end precision medical equipment, such as the force feedback actuators of endoscopic surgical robots or the drug flow rate control valves of precision infusion pumps, miniature compression springs play a crucial role in precise reset and force control. In these applications, the physical properties of the spring directly affect the accuracy and safety of the medical device during surgery or treatment. Any minute physical deformation, fatigue crack, or structural abnormality can lead to device malfunction or even serious medical accidents. Therefore, on automated production lines, full inspection of springs before they leave the factory is a critical step in ensuring product qualification rates and medical safety.
[0003] Currently, automated inspection technology based on machine vision has gradually replaced traditional manual visual inspection and become the mainstream quality inspection method due to its advantages of high efficiency and objectivity. In this type of technology, industrial cameras are usually used to capture images of springs, and edge detection algorithms (such as the Canny operator) are used to extract the contour of the spring. Then, by comparing the contour with a standard template, it is determined whether there are faults such as unstable bending, uneven pitch, breakage, or severe deformation.
[0004] However, in actual production, this detection method faces severe challenges in real-world industrial scenarios. Compression springs are typically made of metal, and their cylindrical helical structure, under industrial light sources, simultaneously produces bright specular reflection areas and deep inter-coil shadow areas. Furthermore, residual oil films or fine oxide spots on the spring surface further exacerbate the complexity of local lighting and shadows in the image. Traditional edge detection algorithms often employ globally uniform threshold parameters, a one-size-fits-all approach that struggles to adapt to the highly uneven lighting characteristics within spring images. Increasing the threshold to suppress false edges in highlight areas may prevent the effective detection of true contours in shadow areas, resulting in broken contours. Conversely, lowering the threshold to preserve dark contours introduces numerous noisy edges caused by reflections and oil contamination, severely interfering with subsequent fault identification and significantly reducing the accuracy and robustness of the detection system. Summary of the Invention
[0005] This invention provides an automatic fault detection method for compression springs based on image recognition. It aims to solve the problem that traditional edge detection algorithms in related technologies often use globally uniform threshold parameters. This one-size-fits-all approach is difficult to adapt to the extremely uneven illumination characteristics inside the spring image, which seriously interferes with subsequent fault identification and affects the accuracy of the detection system.
[0006] This invention provides an automatic fault detection method for compression springs based on image recognition, comprising: acquiring a grayscale image of the compression spring and dividing the grayscale image into multiple local regions; determining the material reflectivity of each local region based on the brightness distribution characteristics of pixels within the local regions; determining the deformation and distortion degree of each local region based on the gradient direction distribution characteristics of pixels within the local regions; calculating an adaptive Canny edge detection high threshold for each local region based on the material reflectivity and the deformation and distortion degree; and applying the adaptive Canny edge detection high threshold corresponding to each local region to extract edges from the grayscale image, and determining whether the compression spring is faulty based on the extracted edge contours. By dividing the image into local regions and dynamically calculating two innovative features—material reflectivity and deformation and distortion degree—for each region, a detection threshold that precisely matches it is generated. This local adaptive strategy can effectively suppress specular artifacts while preserving the true contours of shadow areas, greatly improving the accuracy and automation level of spring fault detection.
[0007] Furthermore, determining the material reflectivity of each local region includes: obtaining the maximum and minimum brightness values and grayscale standard deviations of all pixels within the local region; dividing the product of the difference between the maximum and minimum brightness values and the grayscale standard deviation by the average grayscale value of the global image to obtain the material reflectivity. By combining the maximum / minimum brightness difference and the grayscale standard deviation within the local region, and normalizing it with the global average grayscale, a specific calculation method is provided that can objectively and quantitatively assess the complexity of local lighting and shadow. Compared to a general description, this method makes the calculation of material reflectivity more accurate and reproducible, providing a reliable data foundation for the accurate generation of subsequent adaptive thresholds, thereby improving the stability of the entire detection algorithm.
[0008] Further, determining the degree of deformation distortion in each local region includes: obtaining the gradient direction angle of each pixel within the local region, calculating the mean of all gradient direction angles within the local region, and dividing the sum of the absolute differences between each gradient direction angle and its corresponding mean by the product of the total number of pixels in the local region and a correction factor to obtain the degree of deformation distortion; wherein, the correction factor is an exponential term calculated based on the material reflectivity of the corresponding local region. By introducing a correction factor based on material reflectivity, this method can reduce the sensitivity to gradient direction deviation in highly reflective areas, while maintaining high sensitivity in areas with uniform illumination. This makes the assessment of the degree of deformation more intelligent, effectively avoiding misjudging artifacts caused by uneven illumination as structural defects in the spring, and improving the accuracy of fault identification.
[0009] Furthermore, the adaptive Canny edge detection high threshold for each local region is calculated, including: normalizing the material reflectivity and deformation distortion degree of each local region; adding the product of the normalized material reflectivity and the first weight coefficient, and the product of the normalized deformation distortion degree and the second weight coefficient; multiplying the sum of the preset base threshold and the product to obtain the adaptive Canny edge detection high threshold for each local region. By normalizing and weighting the two features, this method establishes a non-linear mapping relationship from local image features to the core parameters of Canny detection, making the threshold adjustment not only adaptive but also controllable and optimizable. It allows for fine-tuning of the weight coefficients according to the actual application scenario, thereby achieving a better balance between noise suppression and detail capture.
[0010] Furthermore, determining whether the compression spring is faulty based on the extracted edge contour includes: using a shape matching algorithm to compare the edge contour with a pre-stored standard spring template contour, and determining whether the spring is faulty based on the comparison result. Compared to traditional methods that only measure individual parameters such as pitch and outer diameter, shape matching can perform a global comparison of the entire spring contour. Therefore, it has a better detection capability for complex fault types that are difficult to describe with simple parameters, such as unstable bending, local fracture, or irregular deformation, resulting in a wider coverage and more reliable results in fault determination.
[0011] Furthermore, determining whether the spring is faulty based on the comparison results includes: if the similarity between the edge contour and the pre-stored standard spring template contour is lower than a preset threshold, then the compression spring is determined to be faulty and an alarm is triggered. By setting a clear matching similarity threshold, the complex shape comparison results are transformed into a simple yes or no decision, completely eliminating the subjectivity and inconsistency of manual judgment. Automatic alarms are triggered when the matching degree is lower than this threshold, achieving full automation from image acquisition to fault alarm, improving the efficiency and objectivity of production line quality inspection.
[0012] Furthermore, the method for obtaining the pre-stored standard spring template contour includes: selecting standard springs, detecting the contours of the standard springs, and using them as the standard spring template contours. By selecting physical standard springs and extracting their contours as a benchmark, the accuracy and consistency of the scale used in subsequent shape matching are ensured. This is a prerequisite for ensuring the stable and reliable operation of the entire detection system and avoids systematic detection deviations caused by non-standard templates.
[0013] Furthermore, the gradient direction angle of each pixel within the local region is obtained, wherein the gradient direction angle is calculated using the Sobel operator. Compared with other gradient operators, the Sobel operator is characterized by its simplicity, speed, and smoothing effect on noise. Selecting this operator can ensure the accuracy of gradient information while meeting the real-time requirements of industrial automation inspection, thus ensuring the engineering practicality of the algorithm.
[0014] Furthermore, after acquiring the grayscale image of the compression spring, the process further includes: denoising the grayscale image using a median filtering algorithm. Image acquisition in industrial settings is susceptible to impulse noise (salt-and-pepper noise) caused by electromagnetic interference and other factors. Median filtering can effectively remove these isolated noise points while maximizing the preservation of the spring's edge clarity. This step improves the quality of the input image, providing a cleaner and more reliable data source for subsequent local feature analysis and edge extraction, thereby improving detection accuracy from the source.
[0015] Furthermore, the first weight coefficient ranges from 0.3 to 0.6; the second weight coefficient ranges from 0.4 to 0.8. Optimal ranges for the two core weight coefficients are provided, allowing users to fine-tune them within these suggested ranges. This enables the algorithm to achieve optimal performance more quickly, shortens the system debugging cycle, and improves the ease of use and application effectiveness of the method.
[0016] Beneficial effects: By dividing the image into local regions and combining the material reflectivity and deformation distortion of each region, an adaptive Canny edge detection high threshold is dynamically calculated for each region. This enables the complete extraction of the true contour of the shadow region while suppressing false edges in the highlight region. This significantly improves the accuracy and robustness of compression spring fault detection in complex industrial lighting environments and solves the problem of contour breakage or noise interference caused by the single threshold in traditional methods. Attached Figure Description
[0017] Figure 1 This is a schematic diagram illustrating a compression spring fault detection flowchart according to an embodiment of the present invention;
[0018] Figure 2 This is a schematic original image illustrating a compression spring according to an embodiment of the present invention; Figure 3 This is a schematic diagram illustrating the detection results of the Canny edge detection algorithm on the original image in the prior art; Figure 4 This is a schematic diagram illustrating the detection results of the improved Canny edge detection algorithm of the present invention on the original image. Detailed Implementation
[0019] The specific embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0020] like Figure 1 As shown, S101: Acquire spring images and preprocess them.
[0021] In this embodiment, a high-resolution industrial camera deployed on the side of the industrial production line or the equipment to be inspected first acquires raw images of the compression spring after production. These raw images are high dynamic range color images to ensure rich surface detail information is captured.
[0022] Specifically, to reduce the complexity of subsequent calculations and focus on brightness information, the acquired original image needs to be converted to grayscale to obtain a grayscale image. Considering that camera sensors in industrial settings may introduce impulse noise, and that the physical edges of the spring appear as steep grayscale changes in the image, median filtering is used to denoise the grayscale image. Median filtering can effectively remove isolated noise points while preserving the steepness of the edges to the maximum extent, laying the foundation for accurate edge detection in the future.
[0023] Subsequently, the preprocessed grayscale image was divided into These are local regions that do not overlap or partially overlap. This block-based processing is a prerequisite for achieving local adaptive adjustment of parameters. In this embodiment, the size of the local region is preferably... In other embodiments targeting larger springs or higher resolution images, the size of this local region can also be [pixel size]. Pixels. For partially overlapping local regions: In order to avoid the discontinuity effect of calculation at the block boundary, a certain proportion (such as 10%-20%) of overlap area can be set between adjacent local regions to ensure the smoothness of parameter transition of the whole image.
[0024] S102: Constructing material reflectivity based on surface light and shadow characteristics.
[0025] In this embodiment, since compression springs are typically made of metal, their cylindrical wires create highly contrasting light-facing and shadow-facing surfaces under illumination. Furthermore, the presence of an oil film on the surface can produce locally bright specular reflections. These pseudo-edges caused by lighting and shadow factors severely interfere with the extraction of true physical edges. Therefore, this step aims to construct a material reflectivity that can quantify the complexity of lighting and shadow in local areas.
[0026] The basis for constructing material reflectivity sensitivity lies in the fact that the more extreme the lighting environment within a local area, the greater the difference between the maximum and minimum brightness values of its internal pixels, and the higher the dispersion of pixel grayscale (i.e., texture complexity). Based on this logic, material reflectivity sensitivity... The calculation formula is constructed as follows: In the formula, For the first Material reflectivity in a localized area; For the first The maximum gray value of all pixels in a local area reflects the brightness of the strongest reflective point in that area. For the first The minimum gray value of all pixels within a local area reflects the brightness of the deepest shadow within that area; The average gray value of the global image serves as a normalization benchmark to eliminate the impact of fluctuations in overall ambient light intensity. For the first The grayscale standard deviation of all pixels within a local region is used to characterize the degree of texture change in that region.
[0027] As shown in the formula above, the reflectivity of a material is positively correlated with the complexity of local lighting and shadows. When the... Highly bright specular reflections exist simultaneously in a localized area. Extremely large) and deep shadows between the circles ( At its smallest value, the brightness is extremely poor. It will increase significantly. If the texture of that area is also quite complex at this time, i.e., the [missing information]... If the standard deviation of grayscale values of all pixels within a local region is large, then the first... The material reflectivity calculated for each local region will increase accordingly. A higher material reflectivity means that the region has a higher risk of false edges caused by lighting and shadow factors. Therefore, the material reflectivity can serve as a key basis for subsequent dynamic adjustment of the high threshold of the Canny operator.
[0028] S103: Determine the degree of deformation and distortion based on structural geometric characteristics.
[0029] In this embodiment, when a compression spring experiences instability, bending, uneven pitch, fatigue cracks, or other faults, the geometric regularity of its projected helical profile in the image will be disrupted. Ideally, the physical edges of a spring exhibit high structural self-similarity. This step aims to utilize this prior knowledge to construct a deformation distortion measure that can assess structural regularity.
[0030] The rationale behind this metric is that at real physical edges, the gradient direction of pixels exhibits strong consistency and directionality; however, in areas composed of reflections or noise, the gradient direction often displays a chaotic distribution. To further eliminate the interference of lighting factors, this scheme introduces the material reflectivity calculated in S102 to correct structural features. Based on this, the formula for calculating the degree of deformation distortion is constructed as follows: In the formula, For the first The degree of deformation and distortion in a local area; For the first in this local area The gradient direction angle of each pixel, as a preferred approach, can be calculated using the Sobel operator; For the first The mean of the gradient direction angles of all pixels within a local region; For the first The total number of pixels in a local region; For the first Material reflectivity in a localized area; This is an exponential correction term, that is, a correction factor used to weight and compensate structural features using light and shadow characteristics.
[0031] According to this formula, when a spring deforms or cracks, the direction of its physical edges is no longer smooth, causing the gradient direction angle of each pixel in the local area to change. Its mean The degree of deviation increases, and the numerator term This increases, leading to a higher degree of deformation and distortion. Simultaneously, the material's reflectivity is introduced as an adjustment term in the denominator. Its function is that in highly reflective regions, where the material's reflectivity is high, deviations in the gradient direction may be primarily caused by lighting noise rather than structural anomalies. The value of the term will decrease, which will reduce the overall denominator, thereby suppressing the degree of deformation and distortion. This ensures that the degree of deformation and distortion can more purely reflect the degree of deformation of the physical structure, and avoids misjudging light and shadow noise as structural defects.
[0032] S104: Adaptive mapping and edge extraction of Canny operator core parameters.
[0033] In this embodiment, the quality of edge detection directly determines the accuracy of the final fault identification. Traditional Canny algorithms rely on manually set fixed high and low thresholds, making it difficult to simultaneously address noise suppression in highlight areas and edge connectivity in shadow areas (such as...). Figure 3 The image shown is a detection result of the Canny edge detection algorithm on the original image in the prior art. In this embodiment, this step deeply integrates the material reflection sensitivity (light and shadow features) and deformation distortion degree (geometric features) constructed above, so as to realize the adaptive dynamic adjustment of the core parameter of the Canny algorithm - that is, the high threshold for judging strong edges.
[0034] The adaptive high threshold is based on the principle that the high threshold setting should match the image characteristics of the local region: in areas with severe reflection or complex structures, the threshold should be appropriately increased to suppress false edges; in areas with clean backgrounds and smooth structures, the threshold should be decreased to ensure the continuity of true edges. Based on this logic, for the first... Adaptive high threshold for local regions The calculation formula is constructed as follows: In the formula, In order to target the Adaptive high threshold for local regions; The preset base threshold value typically ranges from [value range missing]. between; This is the reflectivity adjustment weighting coefficient, used to control the algorithm's suppression intensity of metallic reflectivity. Its preferred value range is... In this embodiment, the value of the reflectivity adjustment weight coefficient can be set to 0.4; is the deformation sensitivity coefficient, used to control the algorithm's sensitivity to capturing structural details (such as crack edges), and its preferred value range is [value range missing]. In this embodiment, the value of the deformation sensitivity coefficient can be set to 0.6; and These are the maximum values of material reflectivity and distortion in all local areas of the entire image, respectively, used for normalization.
[0035] As can be seen from the above formula, when the reflection in a certain local area is severe or the structure is complex, the formula will adjust the weighting coefficients. and The weighting effect automatically increases the high threshold of the region. In the hysteresis thresholding of the Canny algorithm, only gradient magnitudes higher than 0.5 are considered. Only points with high gravitational intensity are identified as strong edges. Therefore, increasing the threshold can effectively filter out false features with relatively low gradient amplitudes, such as those formed by oil stain reflections and fine oxidation spots. Conversely, in areas with clean backgrounds and smooth spring structures, the material's reflectivity and distortion are both low, and the threshold... It will automatically lower to ensure the continuity and integrity of the spring's physical edges, avoiding edge breakage due to excessively high thresholds.
[0036] S5: Fault identification and judgment implementation.
[0037] In this embodiment, after using the aforementioned adaptive threshold to perform fine edge extraction on the entire image, the system obtains a binarized spring contour image, and then proceeds to the fault identification and judgment stage (e.g., Figure 4 The image shown is the detection result of the improved Canny edge detection algorithm on the original image. Specifically, this embodiment uses a shape matching algorithm to compare the contour of the spring to be detected with the contour of a pre-stored standard spring template image to achieve the final determination of complex shape faults.
[0038] The specific process for final fault determination is as follows: Calculate the distance between the key points on the spring contour extracted from the image to be inspected and the corresponding matching point pairs in the standard template image, and calculate the average distance of all matching point pairs. Note that Euclidean distance can be used to calculate the distance. Then, compare this average distance with a preset distance threshold. In this embodiment, this distance threshold can be empirically set as follows: Each pixel is considered a distance. When the calculated average distance is greater than this threshold, it means that the outline of the spring under inspection deviates significantly from the standard shape. The system determines that the current compression spring has faults such as instability, bending, abnormal pitch, or breakage, and then outputs an alarm signal and rejection command to the production line through the PLC interface. Conversely, if the average distance is less than or equal to the threshold, the spring geometry is deemed qualified, and the product flows to the next process.
[0039] The method for obtaining the standard template image is as follows: a standard spring whose physical parameters perfectly meet the design requirements is selected in advance, and its image is acquired under the same lighting and shooting conditions, and the standard contour is extracted to obtain the standard template image.
[0040] In summary, this invention constructs the material reflectivity and deformation distortion degree, and establishes a nonlinear mapping relationship between them and the high threshold of the Canny operator, thereby realizing intelligent and adaptive adjustment of the core parameters in the spring fault detection process. This significantly improves the accuracy, robustness, and automation level of the detection algorithm in complex industrial environments.
[0041] The embodiments described above are merely examples of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention.
Claims
1. An automatic fault detection method for compression springs based on image recognition, characterized in that, include: Obtain a grayscale image of the compression spring and divide the grayscale image into multiple local regions; Based on the brightness distribution characteristics of pixels within the local region, the material reflectivity of each local region is determined; based on the gradient direction distribution characteristics of pixels within the local region, the degree of deformation and distortion of each local region is determined. Based on the material reflectivity and the degree of deformation distortion of each local region, an adaptive Canny edge detection high threshold is calculated for each local region; and the adaptive Canny edge detection high threshold corresponding to each local region is applied to extract edges from the grayscale image, and the presence of a fault in the compression spring is determined based on the extracted edge contours.
2. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, Determining the material reflectivity of each of the aforementioned local regions includes: Obtain the maximum brightness, minimum brightness, and grayscale standard deviation of all pixels within the local area; divide the product of the difference between the maximum and minimum brightness and the grayscale standard deviation by the average grayscale value of the global image to obtain the material's reflectivity.
3. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, Determining the degree of deformation and distortion in each of the aforementioned local regions includes: The gradient direction angle of each pixel in the local area is obtained, the mean of all gradient direction angles in the local area is calculated, and the sum of the absolute differences between each gradient direction angle and its corresponding mean is divided by the product of the total number of pixels in the local area and a correction factor to obtain the degree of deformation distortion; wherein, the correction factor is an exponential term calculated based on the material reflectivity of the corresponding local area.
4. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, The adaptive Canny edge detection high threshold for each local region is calculated, including: The material reflectivity and deformation distortion of each local region are normalized respectively. The product of the normalized material reflectivity and the first weight coefficient, and the product of the normalized deformation distortion and the second weight coefficient are added together. The preset base threshold is multiplied by the sum of the products to obtain the adaptive Canny edge detection high threshold for each local region.
5. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, Determining whether the compression spring is faulty based on the extracted edge contour includes: using a shape matching algorithm to compare the edge contour with a pre-stored standard spring template contour, and determining whether the spring is faulty based on the comparison result.
6. The automatic fault detection method for compression springs based on image recognition according to claim 5, characterized in that, Determining whether a spring is faulty based on the comparison results includes: If the similarity between the edge contour and the pre-stored standard spring template contour is lower than a preset threshold, the compression spring is determined to be faulty and an alarm is triggered.
7. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, Methods for obtaining pre-stored standard spring template contours include: Standard springs are selected, and their outlines are detected to serve as standard spring template outlines.
8. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, Obtain the gradient direction angle of each pixel within the local region, wherein the gradient direction angle is calculated using the Sobel operator.
9. The automatic fault detection method for compression springs based on image recognition according to claim 1, characterized in that, After obtaining the grayscale image of the compression spring, the method further includes: performing noise reduction processing on the grayscale image using a median filtering algorithm.
10. The automatic fault detection method for compression springs based on image recognition according to claim 4, characterized in that, The first weighting coefficient has a value range of 0.3 to 0.6; the second weighting coefficient has a value range of 0.4 to 0.8.