Circlip Defect Detection Method Based on Image Processing

Through the spring defect detection method based on image processing, the spring profile and detection defect are extracted using the OpenCV library function, which solves the problem of time-consuming and labor-intensive and large errors in manual detection, and achieves efficient and accurate spring defect detection.

CN115082410BActive Publication Date: 2025-03-21XI'AN POLYTECHNIC UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210755826.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-29
Publication Date
2025-03-21
Estimated Expiration
2042-06-29

AI Technical Summary

Technical Problem

In the prior art, manual detection of spring defects is time-consuming and labor-intensive and has a large error, making it difficult to achieve efficient and accurate detection.

Method used

The spring defect detection method based on image processing is adopted. By collecting spring images, extracting outline areas of interest, detecting defects such as pits, hole blockages, deformations and missing edges, the OpenCV library function is used for image preprocessing and defect extraction.

Benefits of technology

It realizes accurate positioning and precise detection of defects on the surface of the spring parts, improves detection accuracy and productivity, reduces manual intervention, and avoids cumbersome operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115082410B_ABST
    Figure CN115082410B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for detecting defects of retaining springs based on image processing: firstly, an image of retaining springs is obtained; then, corresponding processing is performed on the acquired image, such as graying, edge filtering, binarization, etc.; retaining spring parts are extracted through mask, circle fitting algorithm, etc., and the center distance, area of ​​region of interest, etc. are calculated; then, retaining spring defects are identified according to corresponding threshold value comparison algorithm to determine whether the retaining spring is a good product or what kind of defects it has. The method of the present invention can accurately identify defects such as hole blockage, pits, deformation, and missing edges on the retaining spring surface, and can detect quantitative retaining springs on a production line, thereby improving the degree of automation and accuracy of detection, while replacing manual detection, avoiding human missed detection, and reducing labor costs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of parts defect detection, and in particular relates to a method for detecting defects of retaining springs based on image processing. Background Art

[0002] Circlips, also called retaining rings or snap rings, are a type of fastener that is mainly installed in shaft slots or hole slots of machines and equipment to prevent the axial movement of parts on the shaft or hole. The main material of circlips is spring steel. Defects such as hole blockage, pits, deformation, and missing edges caused during the rolling, drawing, coiling, and stamping processes will reduce the fatigue strength, corrosion resistance, and service life of the circlips, and seriously affect the quality of the finished circlips. Therefore, it is necessary to conduct strict surface defect inspections on the finished products.

[0003] Common defect types in actual production are hole blockage, pits, deformation, and missing edges. Currently, many manufacturers mainly use manual inspection methods. Defective products are manually selected by visual inspection. However, manual inspection takes a long time, requires high labor intensity, and requires high proficiency of inspectors. In addition, the inspection speed depends on manual experience, and the inspection error is large for high-precision parts, making the inspection efficiency low. Summary of the invention

[0004] The purpose of the present invention is to provide a method for detecting defects of retaining springs based on image processing, which solves the problem that manual inspection in the prior art is time-consuming and labor-intensive and has large detection errors.

[0005] The technical solution adopted by the present invention is a method for detecting defects of retaining springs based on image processing, which is specifically implemented in the following steps:

[0006] Step 1, collect the picture of the spring to be tested;

[0007] Step 2, extracting the contour area of ​​interest of each part of the circlip;

[0008] Step 3: pit defect detection;

[0009] Step 4: hole plugging detection;

[0010] Step 5: Center point positioning;

[0011] Step 6: Calculate the center distance using the center coordinates obtained in step 5 and the Euclidean distance calculation formula The calculated distance between the centers of the circles;

[0012] Step 7: Deformation defect detection;

[0013] Step 8: Detect missing edges.

[0014] The present invention is also characterized in that

[0015] The specific operation of step 1 is: obtaining a sample image of the clip to be tested, wherein a single sample image only contains a complete clip part.

[0016] Step 2, the specific operations are as follows: perform bilateral filtering denoising on the sample images of the snap springs, perform grayscale binarization to eliminate uneven illumination, extract the outer contour of the snap springs through the contour extraction algorithm, and fill the inside of the outer contour of the snap springs, and finally obtain the region of interest of the outer contour of the snap springs by using the bitwise AND operation function of the image; perform secondary contour extraction on the obtained region of interest of the outer contour of the snap springs, extract the contours of the pits and the small holes of the snap springs, put these contour information and the outer contour information of the snap springs in a list, use the contour area calculation function to calculate the internal area of ​​each contour respectively, and sort them in descending order by area size, set the empirical threshold to 100, delete the contour information with an area less than 100 in the list, and obtain the total number of contour information.

[0017] The binarization uses the single threshold algorithm cv2.threshold() for binary output, and the bilateral filtering algorithm uses cv2.bilateralFilter() to remove noise;

[0018] Secondary contour extraction uses the cv2.findContours() function based on OpenCV to extract the contour of the spring image to obtain the contour information, and stores the contour information in the contours list, and calculates the area of ​​contours using cv2.contourArea().

[0019] Step 3, the specific operation is to set the number of contour information Th1=3 according to experience. If the number of contour information obtained in step 2 is greater than 3, the part is a defective product with pit defects; if the number of contour information is not greater than 3, the part has no pit defects, and the contour with the largest area is the outer contour, and the rest is the small hole contour. Fill the inside of the small hole contour of the circlip part, use the bitwise AND operation function of the image to obtain the small hole area of ​​interest, and then continue to the next step of detection;

[0020] In step 3, the cv2.bitwise_and() function based on OpenCV is used to obtain the small hole region of interest.

[0021] Step 4, the specific operation is, if the number of contour information in step 3 is less than 3, it is directly determined that the retaining spring has a hole blocking defect and the detection process is terminated; if the number of contour information is equal to 3, namely the outer contour of the retaining spring and the contours of the two small holes, the threshold interval Th2 of the area difference between the two small hole contours is set according to experience, and the areas of the two small holes obtained in step 2 are compared. If the difference in the areas of the two small holes detected is within the given threshold range Th2, it is determined that the retaining spring does not have a hole blocking defect, and proceed to the next step of detection; otherwise, it is determined that the retaining spring has a hole blocking defect and the detection process is terminated.

[0022] The specific operation of step 5 is to extract the edge of the region of interest of the outer contour of the part obtained in step 2, use the Hough transform detection algorithm of the circle to detect the center and radius of the outer circle of the outer contour of the retaining spring part, and use the ellipse fitting algorithm to calculate the center points of the two regions of interest of the small hole obtained in step 3;

[0023] The cv2.Canny() function based on OpenCV is used to extract the edges of the regions of interest obtained in step 2 and step 3, and the cv2.HoughCircles() function based on OpenCV is used to extract the fitting circle of the outer contour of the circlip. The specific method of circle fitting is as follows:

[0024] Step 5.1: The gradient of each pixel in the image can be obtained by the Sobel operator, and the gradient G along the horizontal (x) and vertical (y) directions is obtained respectively. x and G y , and then use the formula To obtain the gradient amplitude of each pixel, after edge detection by Canny algorithm, a binary boundary image is obtained;

[0025] Step 5.2, determine the center of the circle, traverse the non-zero points in the boundary binary image, and draw line segments along the gradient direction and the reverse direction. The starting point and length of the line segment are determined by the radius range allowed by the parameters; any line segment drawn along the gradient direction and the reverse direction in the boundary binary image can be expressed by the following formula:

[0026] f[(a1, a2, ..., a n ), (x, y)] = 0

[0027] Among them, a1, a2, ..., a n is the characteristic parameter of the line segment. If it is swapped with the variables x and y, the formula is equivalent to:

[0028] g[(x,y),(a1,a2,...,a n )]=0

[0029] The above formula shows that the points on the same line segment in the boundary binary image are transformed by the formula and mapped to a point (x, y) in the plane coordinate system. The point is represented by the characteristic parameters a1, a2, ..., a n Sure;

[0030] Step 5.3, the equation of the known circle is (xa) 2 +(yb) 2 =r 2 , let (x i ,y i)(i=1,2,3...,n) is the set of points in the boundary binary graph that satisfy the circular characteristic. Then the point (x i ,y i ) in the space coordinate system is: (ax i ) 2 +(by i ) 2 =r 2 This equation represents a three-dimensional cone surface in the spatial coordinate system; all points in the boundary binary graph that satisfy the circular characteristic correspond to a set of cone cluster surfaces in the spatial coordinate system;

[0031] Step 5.4: Find the center coordinates (a, b) and radius r of the circle in the boundary binary image. You can create a three-dimensional accumulator array A(a, b, r). According to the three-dimensional cone equation, calculate the (a, b, r) of each non-zero point on the circumference of the boundary binary image and accumulate them. By comparing the accumulated points A n The accumulated value of (a, b, r) is selected as the maximum value A max (a, b, r), then (a, b) in the array is the coordinates of the center of the circle in the boundary binary graph, and r is the radius;

[0032] The cv2.fitEllipse function based on OpenCV is used to fit an ellipse to the small holes to obtain the center points of the two small holes. The specific method of ellipse fitting is as follows:

[0033] Input a set of points (x i ,y i ), using the polynomial F(a,x)=a·x=ax 2 +bxy+cy 2 +dx+cy+∫=0, and define the vector A=[a,b,c,d,e,f] T , X=[x 2 ,xy,y 2 , x, y, 1] T , we get the polynomial

[0034] In 4aac-b 2 = 1, define a matrix D

[0035]

[0036] The ellipse fitting problem can be restated as: Minimize E = ||Da|| 2 When it meets a T Under the condition of Ca=1,

[0037]

[0038] Construct the Lagrangian function L(D, Δ) = Aaa T D T -Δ(a T Ca-1) partial derivative is set to 0, and we get D T Da-ΔCa=0, find its eigenvalue and eigenvector to get the result.

[0039] Step 7, the specific operation is that the deformation defects of the retaining spring parts are divided into two types: two-dimensional deformation and three-dimensional deformation. The two-dimensional deformation uses the coordinates of the three center points detected by the center point positioning in step 5 to calculate the Euclidean distances between the three centers respectively. According to experience, the Euclidean distance interval threshold between the center of the outer circle and the center of the upper small hole is set to Th3, and the Euclidean distance interval threshold between the center of the outer circle and the center of the lower small hole is set to Th4;

[0040] If the difference between the Euclidean distance between the center of the outer circle of the spring and the center of the two small holes and the Euclidean distance between the center of the two small holes exceed the corresponding threshold interval, the spring part undergoes two-dimensional deformation, and the detection process ends;

[0041] If the Euclidean distances between the three centers in the spring clip are all within the corresponding threshold range, it is determined that the spring clip firmware has no two-dimensional deformation and proceeds to the next step of detection; the three-dimensional deformation is determined by utilizing the different position heights between the two small holes and the different shadow areas generated by the light in the middle of the two small holes. The two small hole interest regions obtained in step 3 are processed using the same grayscale binarization algorithm, and the number of pixels with a grayscale value of 255 is detected. According to experience, the threshold value of the difference between the number of pixels of the two small holes is set to Th5. If the measured difference is not within the threshold Th5, the spring clip firmware has produced three-dimensional deformation. If the measured difference is within the threshold Th5, the spring clip firmware has no three-dimensional deformation and proceeds to the next step of the detection process.

[0042] Step 8, the specific operation is, according to the coordinates of the center of the outer circle detected in step 5, the radius of the outer circle is reduced by two pixels to obtain the first circle; the coordinates of the center of the circle remain unchanged, and the radius of the outer circle is further reduced by eleven pixels to obtain the second circle, using two concentric circles of different radii and a mask processing method to obtain the region of interest of the ring, the ring is processed by a grayscale binarization algorithm, the number of pixels of the ring with a grayscale value of 255 is detected, and a pixel number threshold Th6 is set according to experience. If the measured number of pixels is less than the threshold Th6, the spring clamp is a defective product with missing edges; if the measured number of pixels is not less than the threshold Th6, the spring clamp does not have a missing edge defect;

[0043] The cv2.bitwise_and function is used to perform a bitwise AND operation on the img and mask images to obtain the region of interest (ROI) of the circular ring. The area of ​​the circular ring is tested to see if it meets the defect threshold within the specified range, so as to determine whether the retaining spring has a missing edge defect.

[0044] The beneficial effect of the present invention is that the present invention adopts image processing technology, fully combines machine vision, and based on the OpenCV retaining spring fastener defect detection method, it can accurately locate the part image, effectively extract the area of ​​interest, improve the detection accuracy, and can automatically identify the defects such as hole blockage, pits, deformation, and missing edges on the surface of the part, effectively solve the various drawbacks of manual detection, and improve productivity. The retaining spring visual defect detection process does not require manual intervention, avoids cumbersome operation process, effectively improves the detection accuracy, and greatly improves the detection speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] Figure 1 is a flow chart of a method for detecting defects of retaining springs based on image processing according to the present invention;

[0046] Figure 2 It is a schematic diagram of Hough transform circle detection in the clip defect detection method based on image processing of the present invention;

[0047] Figure 3 It is a detailed diagram of the retaining spring in the retaining spring defect detection method based on image processing of the present invention; among them, a) is an example diagram of the retaining spring hole blocking defect; b) is an example diagram of the retaining spring hole blocking defect; c) is an example diagram of the retaining spring two-dimensional deformation defect; d) is an example diagram of the retaining spring three-dimensional deformation defect; e) is an example diagram of the retaining spring pit defect; f) is an example diagram of the retaining spring edge defect. DETAILED DESCRIPTION

[0048] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0049] The overall process of the method for detecting defects of circlips based on image processing and the method for batch detecting defects of circlip fasteners of the present invention is as follows: Figure 1 As shown. Circlip fasteners are basically divided into three categories. The present invention mainly detects C-type circlips. Figure 2 As shown in the figure, the defect types detected are hole plugging, pits, deformation, and edge missing. Figure 3 .b, the two-dimensional deformed parts are as follows Figure 3 .c, the three-dimensional deformed parts are as follows Figure 3 .d, the pit parts are as shown Figure 3 .e, the missing edge parts are as follows Figure 3.f. The present invention mainly uses the library function in OpenCV to preprocess the image and extract defects. At present, the detection of surface defects of circlip fasteners mainly relies on manual naked eye detection, which has high labor intensity and low detection efficiency, consistency and accuracy. The present invention can automatically identify the defects of circlip parts and finally realize the sorting of qualified products and defective products.

[0050] The present invention provides a method for detecting defects of retaining springs based on image processing, the flow chart of which is as follows: Figure 1 As shown, the specific implementation steps are as follows:

[0051] Step 1, collect the picture of the spring to be tested;

[0052] Obtain a sample image of the circlip to be tested. The conveyor belt continuously loads the circlip parts in sequence. The camera takes a picture of a circlip part each time to obtain a sample image, wherein a single sample image only contains a complete circlip part.

[0053] Step 2, extracting the contour area of ​​interest of each part of the circlip;

[0054] In order to prevent the presence of impurities on the conveyor belt from affecting the detection of image defects, bilateral filtering is performed on the sample images of the snap ring parts to remove image noise and retain contour information. The bilateral filtering function is cv2.bilateralFilter(), parameter 1 is 9, parameter 2 is 500, and parameter 3 is 500. Grayscale binarization eliminates uneven illumination, and a binarization algorithm cv2.threshold() with a single threshold of 127 is used for binary output. The outer contour of the snap ring part is extracted through the contour extraction algorithm, and the inner part of the outer contour of the snap ring part is filled. The region of interest, the outer contour of the snap ring part, is finally obtained using the bitwise AND operation function of the image;

[0055] The obtained contour area of ​​interest is extracted twice by using the cv2.findContours() contour extraction algorithm to extract the contours of two small holes. If there is a pit defect on the part, the pit contour will be extracted. These contour information and the outer contour information of the circlip are placed in a contours list, and the contour area calculation function cv2.contourArea() is used to calculate the area of ​​contours, and the internal areas of these contours are calculated respectively. The list information is sorted in descending order by area size, and the contour information with an area less than 100 in the list is deleted (excluding the contours belonging to noise points and impurities), and the total number of contour information is obtained.

[0056] In step 2, the contour search algorithm of connected domain extraction is first used to find the outer contour of the part, and then the inside of the outer contour is filled. The image is divided into contour area and non-contour area by image bitwise AND operation with the original image after bilateral filtering. The contour area is extracted as the area of ​​interest, avoiding the stains in the non-contour area from affecting the detection results.

[0057] Step 3: pit defect detection;

[0058] According to experience, the number of contour information is set to Th1=3 (outer contour plus two small holes). If the number of contour information obtained is greater than 3, the part is a defective product with pit defects; if the number of contour information is not greater than 3, the part has no pit defects, and the contour with the largest area is the outer contour, and the rest are small hole contours. Fill the inside of the two small hole contours of the retaining spring part, and perform the bitwise AND operation function cv2.bitwise_and() on the original image after bilateral filtering to obtain the two regions of interest of the two small hole contours, and then proceed to the next step of detection;

[0059] Step 4, hole plugging detection. If the number of contour information in step 3 is less than 3, it is directly determined that the retaining spring has a hole plugging defect, and the detection process ends; if the number of contour information is equal to 3, that is, the outer contour of the retaining spring and the contours of the two small holes, the threshold interval Th2 (0-50) of the area difference of the two small hole contours is set according to experience, and by comparing the areas of the two small holes obtained in step 2, if the difference in the areas of the two small holes detected is within the given threshold range Th2, it is determined that the retaining spring does not have a hole plugging defect, and enters the next step of detection; otherwise, it is determined that the retaining spring has a hole plugging defect, and the detection process ends;

[0060] Step 5: Center point positioning: extract the edge of the region of interest of the outer contour of the part obtained in step 2, use the circle Hough transform detection algorithm to detect the center and radius of the outer circle of the outer contour of the retaining spring part, and use the ellipse fitting algorithm to calculate the center points of the two regions of interest of the small holes obtained in step 3, so as to avoid the problem of inaccurate detection of the center of the circle caused by lens distortion;

[0061] The cv2.Canny() function based on OpenCV is used, parameter 1 is 128, parameter 2 is 200, and the edges of the regions of interest obtained in step 2 and step 3 are extracted. The cv2.HoughCircles() function based on OpenCV is used to extract the fitting circle of the outer contour of the circlip. Parameter 1 is 1, parameter 2 is 80, parameter 3 is 17, parameter 4 is 38, parameter 5 is 5, and parameter 6 is 180. The specific method of circle fitting is as follows:

[0062] Step 5.1: The gradient of each pixel in the image can be obtained by the Sobel operator, and the gradient G along the horizontal (x) and vertical (y) directions is obtained respectively. x and G y , and then use the formula To obtain the gradient amplitude of each pixel. After the Canny algorithm edge detection, the boundary binary image is obtained;

[0063] Step 5.2, determine the center of the circle, traverse the non-zero points in the boundary binary image, and draw line segments along the gradient direction and the reverse direction. The starting point and length of the line segment are determined by the radius range allowed by the parameter; any line segment drawn along the gradient direction and the reverse direction in the boundary binary image can be expressed by the following formula:

[0064] f[(a1, a2, ..., a n ), (x, y)] = 0

[0065] Among them, a1, a2, ..., a n is the characteristic parameter of the line segment. If it is swapped with the variables x and y, the formula is equivalent to:

[0066] g[(x,y),(a1,a2,...,a n )]=0

[0067] The above formula shows that the points on the same line segment in the boundary binary image are transformed by the formula and mapped to a point (x, y) in the plane coordinate system. The point is represented by the characteristic parameters a1, a2, ..., a n Sure.

[0068] Step 5.3, the equation of the known circle is (xa) 2 +(yb) 2 =r 2 , let (x i ,y i )(i=1,2,3...,n) is the set of points in the boundary binary graph that satisfy the circular characteristic. Then the point (x i ,y i ) in the space coordinate system is: (ax i ) 2 +(by i ) 2 =r 2 .This equation represents a three-dimensional cone surface in the spatial coordinate system; all points in the boundary binary graph that satisfy the circular characteristics correspond to a set of cone cluster surfaces in the spatial coordinate system. Figure 2 Shown

[0069] Step 5.4: To find the center coordinates (a, b) and radius r of the circle in the boundary binary image, we can create a three-dimensional accumulator array A(a, b, r). According to the three-dimensional cone equation, we can calculate the (a, b, r) of each non-zero point on the circumference of the boundary binary image and accumulate them. n The accumulated value of (a, b, r) is selected as the maximum value A max (a, b, r), then (a, b) in the array is the coordinates of the center of the circle in the boundary binary image, and r is the radius.

[0070] The cv2.fitEllipse() function based on OpenCV is used to fit an ellipse to the small holes and obtain the center points of the two small holes.

[0071] The specific method of ellipse fitting is as follows:

[0072] Input a set of points (xi, y i ), using the polynomial F(a,x)=a·x=ax 2 +bxy+cy 2 +dx+cy+∫=0, and define the vector A=[a,b,c,d,e,f] T , X=[x 2 ,xy,y 2 , x, y, 1] T , the polynomial can be written as

[0073] Consider 4ac-b 2 = 1, define a matrix D

[0074]

[0075] The ellipse fitting problem can be restated as: Minimize E = ||Da|| 2 When it meets a T Under the condition of Ca=1,

[0076]

[0077] Then construct the Lagrangian function L(D, Δ) = Aaa T D T -Δ(a T Ca-1) partial derivative is set to 0, and we get D T Da-ΔCa=0, find its eigenvalue and eigenvector to get the result.

[0078] When extracting the edge of the target contour, the Hough transform of the circle and the fitting algorithm of the ellipse are used at the same time to improve the accuracy of the edge extraction of the target contour. The outer contour uses the Hough transform of the circle, which is convenient, easy and accurate. The eyelet of the circlip is small and easy to deform. The ellipse fitting can more accurately find the center point and edge contour of the small circle.

[0079] Step 6: Calculate the center distance using the center coordinates obtained in step 5 and the Euclidean distance calculation formula Calculate the center distance between the fitted circles. Figure 3 a), the detection accuracy is high and can reach the pixel level;

[0080] Step 7, deformation defect. The deformation defect of the retaining spring parts is divided into two types: two-dimensional deformation and three-dimensional deformation. The two-dimensional deformation uses the coordinates of the three center points detected by the center point positioning in step 5 to calculate the Euclidean distance between the three centers. According to experience, the Euclidean distance interval threshold between the center of the outer circle and the center of the two small holes is set to Th3 (130-140), and the Euclidean distance interval threshold between the center of the two small holes is set to Th4 (150-160). If any of the Euclidean distances between the three centers in the spring clip exceeds the corresponding threshold interval, the spring clip firmware undergoes two-dimensional deformation, and the detection process ends; if the Euclidean distances between the three centers in the spring clip are all within the corresponding threshold interval, it is determined that the spring clip firmware does not have two-dimensional deformation, and the next step of detection is entered; the three-dimensional deformation uses the different position heights between the two small holes, resulting in different shadow areas generated by light in the middle of the two small holes. The two small holes obtained in step 3 are processed with the same grayscale binarization algorithm, and the number of pixels with a grayscale value of 255 is detected. The pixel number difference threshold Th5 (0-50) is set according to experience. If the difference in the number of pixels between the two small holes is not within the threshold Th5, the spring clip firmware has undergone three-dimensional deformation. If the difference in the number of pixels between the two small holes is within the threshold Th5, the spring clip firmware does not have three-dimensional deformation, and the next step of the detection process is entered;

[0081] The three-dimensional deformation of the retaining spring will cause the two small holes of the retaining spring to be not in the same plane. According to the different areas of shadows produced by light in the two small holes, the present invention performs grayscale binarization processing on the obtained small hole areas, and then calculates their respective areas, and determines whether the part has three-dimensional deformation based on the area difference.

[0082] Step 8, missing edge detection, according to the center coordinates of the outer circle detected in step 5, reduce the radius of the outer circle by two pixels to obtain the first circle; the center coordinates remain unchanged, and the radius of the outer circle is further reduced by eleven pixels to obtain the second circle. Using two concentric circles of different radii, the mask processing method is used to obtain the region of interest of the ring. The ring is processed with a grayscale binarization algorithm, and the number of pixels with a grayscale value of 255 of the ring is detected. The pixel number threshold Th6=900 is set according to experience. If the measured number of pixels is greater than the threshold Th6, the spring clamp firmware is a defective product with missing edges; if the measured number of pixels is not greater than the threshold Th6, the spring clamp firmware does not have a missing edge defect.

[0083] The cv2.bitwise_and function is used to perform a bitwise AND operation on the img and mask images to obtain the region of interest (ROI) of the circular ring. The area of ​​the circular ring is tested to see if it meets the defect threshold within the specified range, so as to determine whether the retaining spring has a missing edge defect.

[0084] Reducing the radius of the outer circle by two pixels can avoid the situation where pixels with a grayscale value of 255 exist on the edge; reducing the radius of the outer circle by eleven pixels further can find pixels with a grayscale value of 255 that exist due to the missing edge problem, and if the range is further reduced, the pixels with a grayscale value of 255 in the two small holes will be included.

[0085] Example 1

[0086] Table 1 is the data record of each experiment

[0087] Table 1 Experimental data records

[0088]

[0089] Pit defect: The number of contour information in the retaining spring obtained in step 2 is 4, and then in step 3, according to the judgment condition: the number of contour information is greater than the threshold value Th1=3, it can be detected that the retaining spring has a pit defect.

[0090] Two-dimensional deformation sample 1: From step 5, the Euclidean distances between the center of the outer circle of the retaining spring and the center points of the two small holes are 137 and 94 respectively, and the Euclidean distance between the center points of the two small holes is 122. Then, in step 7, according to the judgment conditions: 1. The Euclidean distance between the center of the outer circle and the center points of the two small holes is not within the threshold value Th3=130-140; 2. The Euclidean distance between the center points of the two small holes is not within the threshold value Th4=150-160, it can be detected that the retaining spring has a two-dimensional deformation defect.

[0091] Two-dimensional deformation sample 2: From step 5, the Euclidean distances between the center of the outer circle of the retaining spring and the center points of the two small holes are 163 and 138 respectively, and the Euclidean distance between the center points of the two small holes is 184. Then, in step 7, according to the judgment conditions: 1. The Euclidean distance between the center of the outer circle and the center points of the two small holes is not within the threshold value Th3=130-140; 2. The Euclidean distance between the center points of the two small holes is not within the threshold value Th4=150-160, it can be detected that the retaining spring has a two-dimensional deformation defect.

[0092] Three-dimensional deformation: The two small holes of the spring are obtained in step 3. After grayscale processing, it is detected that the difference in the number of black pixels of the two holes is 867. Then in step 7, according to the judgment condition: the difference in the number of pixels of the two holes is not within the threshold value Th5=0-50, it can be detected that the spring has a three-dimensional deformation defect.

[0093] Hole plugging defect: From step 3, the difference in area between the two small holes of the retaining spring is 259. Then, in step 4, according to the judgment condition: the area difference is not within the threshold range Th2=0-50, it can be detected that the retaining spring has a hole plugging defect.

[0094] Missing edge defect: The coordinates of the center of the outer circle of the spring are obtained in step 5, and the circular ring area is obtained after mask processing. After grayscale conversion, it is detected that the area of ​​black pixels in the circular ring is 1019. Then, in step 8, according to the judgment condition: the number of pixels with a grayscale value of 255 in the circular ring is less than the threshold value Th6=900, it can be detected that the spring has a missing edge defect.

[0095] Defect-free sample 1: The number of contour information in the spring obtained from step 2 is 3 (less than or equal to the threshold Th1); the difference between the two small hole surfaces of the spring obtained from step 3 is 18.5 (within the threshold Th2 range); the Euclidean distances between the center of the outer circle of the spring and the center points of the two small holes obtained from step 5 are 140 and 135 respectively (within the threshold Th3 range), and the Euclidean distance between the center points of the two small holes is 155 (within the threshold Th4 range); the two small hole regions of interest of the spring are obtained from step 3, and after grayscale processing, the difference in the number of black pixels of the two small holes is detected to be 6 (within the threshold Th5 range); the coordinates of the center of the outer circle of the spring are obtained from step 5, and the circular area is obtained after mask processing. After grayscale processing, the black pixel area in the circular ring is detected to be 867 (less than the threshold Th6); it can be detected that the spring is defect-free.

[0096] Defect-free sample 2: The number of contour information in the spring obtained from step 2 is 3 (less than or equal to the threshold Th1); the difference between the two small hole surfaces of the spring obtained from step 3 is 5.5 (within the threshold Th2 range); the Euclidean distances between the center of the outer circle of the spring and the center points of the two small holes obtained from step 5 are 136 and 138 respectively (within the threshold Th3 range), and the Euclidean distance between the center points of the two small holes is 157 (within the threshold Th4 range); the two small hole regions of interest of the spring are obtained from step 3, and after grayscale processing, the difference in the number of black pixels of the two small holes is detected to be 42 (within the threshold Th5 range); the coordinates of the center of the outer circle of the spring are obtained from step 5, and the circular area is obtained after mask processing. After grayscale processing, the black pixel area in the circular ring is detected to be 880 (less than the threshold Th6); it can be detected that the spring is defect-free.

Claims

1. A method for detecting spring defects based on image processing, characterized in that: Please follow the steps below to implement: Step 1, collect the picture of the spring to be tested; Step 2, extracting the contour area of ​​interest of each part of the circlip; Step 3: pit defect detection; The specific operation of step 3 is to set the number of contour information to Th1=3 according to experience. If the number of contour information obtained in step 2 is greater than 3, the part is a defective product with a pit defect; if the number of contour information is not greater than 3, the part has no pit defect, and the contour with the largest area is the outer contour, and the rest is the small hole contour. The inside of the small hole contour of the circlip part is filled, and the small hole region of interest is obtained by using the bitwise AND operation function of the image, and then the next step of detection is continued; In step 3, the cv2.bitwise_and() function based on OpenCV is used to obtain the small hole region of interest; Step 4: hole plugging detection; The specific operation of step 4 is as follows: if the number of contour information in step 3 is less than 3, it is directly determined that the retaining spring has a hole blocking defect, and the detection process ends; if the number of contour information is equal to 3, that is, the outer contour of the retaining spring and the contours of the two small holes, the threshold interval Th2 of the area difference of the two small hole contours is set according to experience, and by comparing the areas of the two small holes obtained in step 2, if the difference in the areas of the two small holes obtained by detection is within the given threshold range Th2, it is determined that the retaining spring does not have a hole blocking defect, and the next step of detection is entered; otherwise, it is determined that the retaining spring has a hole blocking defect, and the detection process ends; Step 5: Center point positioning; The specific operation of step 5 is to extract the edge of the region of interest of the outer contour of the part obtained in step 2, detect the outer circle center and radius of the outer contour of the retaining spring part by using the Hough transform detection algorithm of the circle, and calculate the center points of the two regions of interest of the small holes obtained in step 3 by using the ellipse fitting algorithm; The cv2.Canny() function based on OpenCV is used to extract the edges of the regions of interest obtained in step 2 and step 3, and the cv2.HoughCircles() function based on OpenCV is used to extract the fitting circle of the outer contour of the circlip. The specific method of circle fitting is as follows: Step 5.1: The gradient of each pixel in the image can be obtained by the Sobel operator, and the gradient G along the horizontal (x) and vertical (y) directions is obtained respectively. x and G y , and then use the formula To obtain the gradient amplitude of each pixel, after edge detection by Canny algorithm, a binary boundary image is obtained; Step 5.2, determine the center of the circle, traverse the non-zero points in the boundary binary image, and draw line segments along the gradient direction and the reverse direction. The starting point and length of the line segment are determined by the radius range allowed by the parameters; any line segment drawn along the gradient direction and the reverse direction in the boundary binary image can be expressed by the following formula: f[(a1,a2,...,a n ),(x,y)]=0 Among them, a1, a2, ..., a n is the characteristic parameter of the line segment. If it is swapped with the variables x and y, the formula is equivalent to: g[(x,y),(a1,a2,...,a n )]=0 The above formula shows that the points on the same line segment in the boundary binary image are transformed by the formula and mapped to a point (x, y) in the plane coordinate system. The point is represented by the characteristic parameters a1, a2, ..., a n Sure; Step 5.3, the equation of the known circle is (xa) 2 +(yb) 2 =r 2 , let (x i ,y i ) is the set of points in the boundary binary graph that satisfy the circular property, i = 1, 2, 3, ..., n, then the point (x i ,y i ) in the space coordinate system is: (ax i ) 2 +(by i ) 2 =r 2 .This equation represents a three-dimensional cone surface in the spatial coordinate system; all points in the boundary binary graph that satisfy the circular characteristics correspond to a set of cone cluster surfaces in the spatial coordinate system; Step 5.4: To find the center coordinates (a, b) and radius r of the circle in the boundary binary image, we can create a three-dimensional accumulator array A(a, b, r). According to the three-dimensional cone equation, we can calculate the (a, b, r) of each non-zero point on the circumference of the boundary binary image and accumulate them. By comparing the accumulated points A n The accumulated value of (a, b, r) is selected as the maximum value A max (a, b, r), then (a, b) in the array is the coordinates of the center of the circle in the boundary binary graph, and r is the radius; The cv2.fitEllipse function based on OpenCV is used to fit an ellipse to the small hole to obtain the center point of the two small holes. The specific method of ellipse fitting is as follows: Input a set of points (x i ,y i ), using the polynomial F(a,x)=a·x=ax 2 +bxy+cy 2 +dx+cy+f=0, and define the vector A=[a,b,c,d,e,f] T ,X=[x 2 ,xy,y 2 , x, y, 1] T , we get the polynomial In 4ac-b 2 = 1, define a matrix D The ellipse fitting problem can be restated as: Minimize E = ||Da|| 2 When it meets a T Under the condition of Ca=1, Construct the Lagrangian function L(D, Δ) = Aaa T D T -Δ(a T Ca-1) partial derivative is set to 0, and we get D T Da-ΔCa=0, find its eigenvalue and eigenvector, and you can get the result; Step 6: Calculate the center distance using the center coordinates obtained in step 5 and the Euclidean distance calculation formula The calculated distance between the centers of the circles; Step 7: Deformation defect detection; The specific operation of step 7 is that the deformation defects of the retaining spring parts are divided into two types: two-dimensional deformation and three-dimensional deformation. The two-dimensional deformation uses the coordinates of the three center points detected by the center point positioning in step 5 to calculate the Euclidean distances between the three centers respectively. According to experience, the Euclidean distance interval threshold between the center of the outer circle and the center of the upper small hole is set to Th3, and the Euclidean distance interval threshold between the center of the outer circle and the center of the lower small hole is set to Th4; If the difference between the Euclidean distance between the center of the outer circle of the spring and the center of the two small holes and the Euclidean distance between the center of the two small holes exceed the corresponding threshold interval, the spring part undergoes two-dimensional deformation, and the detection process ends; If the Euclidean distances between the three centers in the spring clip are all within the corresponding threshold interval, it is determined that the spring clip firmware does not have two-dimensional deformation, and the next step of detection is entered; the three-dimensional deformation is determined by using the different position heights between the two small holes and the different shadow areas generated by the light between the two small holes. The two small hole interest regions obtained in step 3 are processed with the same grayscale binarization algorithm, and the number of pixels with a grayscale value of 255 is detected. According to experience, the threshold value of the difference between the number of pixels of the two small holes is set to Th5. If the measured difference is not within the threshold value Th5, the spring clip firmware has produced three-dimensional deformation. If the measured difference is within the threshold value Th5, the spring clip firmware does not have three-dimensional deformation, and the next step of the detection process is entered; Step 8, missing edge detection, the specific operation of step 8 is, according to the center coordinates of the outer circle detected in step 5, reducing the radius of the outer circle by two pixels to obtain the first circle; the center coordinates remain unchanged, and the radius of the outer circle is further reduced by eleven pixels to obtain the second circle, using two concentric circles of different radii and a mask processing method to obtain the region of interest of the ring, processing the ring with a grayscale binarization algorithm, detecting the number of pixels of the ring with a grayscale value of 255, and setting a pixel number threshold Th6 according to experience, if the measured number of pixels is less than the threshold Th6, then the spring clamp firmware is a defective product with missing edges; if the measured number of pixels is not less than the threshold Th6, then the spring clamp firmware does not have a missing edge defect; The cv2.bitwise_and function is used to perform a bitwise AND operation on the img and mask images to obtain the region of interest (ROI) of the circular ring. The area of ​​the circular ring is tested to see if it meets the defect threshold within the specified range, so as to determine whether the retaining spring has a missing edge defect.

2. The method for detecting spring defects based on image processing according to claim 1, characterized in that: The specific operation of step 1 is: obtaining a sample image of the spring clip to be detected, wherein a single sample image only contains one complete spring clip part.

3. The method for detecting spring defects based on image processing according to claim 2 is characterized in that: The specific operations of step 2 are as follows: bilateral filtering and denoising are performed on the sample images of the snap springs, grayscale binarization is performed to eliminate uneven illumination, the outer contour of the snap springs is extracted by a contour extraction algorithm, and the inside of the outer contour of the snap springs is filled, and the region of interest of the outer contour of the snap springs is finally obtained by using the bitwise AND operation function of the image; secondary contour extraction is performed on the obtained region of interest of the outer contour of the snap springs to extract the contours of the pits and the small holes of the snap springs, and these contour information and the outer contour information of the snap springs are placed in a list, and the contour area calculation function is used to calculate the internal area of ​​each contour respectively, and the contours are sorted in descending order by area size, and an empirical threshold of 100 is set to delete the contour information with an area less than 100 in the list to obtain the total number of contour information.

4. The method for detecting spring defects based on image processing according to claim 3 is characterized in that: The binarization adopts the single threshold algorithm cv2.threshold() to perform binarization output, and the bilateral filtering algorithm adopts cv2.bilateralFilter() to remove noise; Secondary contour extraction uses the cv2.findContours() function based on OpenCV to extract the contour of the spring image to obtain the contour information, and stores the contour information in the contours list, and calculates the area of ​​contours using cv2.contourArea().

Citation Information

Patent Citations

  • OpenCV-based high-reflection bottle cap defect detection method

    CN114018946A

  • Rubber ring defect batch detection method and detection system

    CN114384080A