Flange size measuring method and device
Through an optical detection system composed of a telecentric light source and camera, combined with template matching and image processing algorithms, automated contactless measurement of flange size is realized, solving the problems of low manual measurement efficiency and poor accuracy, and improving detection accuracy and production efficiency.
Patent Information
- Application Number
- CN202310230177.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-10
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2043-03-10
AI Technical Summary
In the prior art, flange size detection relies on manual measurement, and there are problems such as high vision requirements, high labor intensity, low efficiency, high randomness and unstable quality, resulting in poor sealing effect and safety hazards.
An optical detection system composed of a telecentric light source and a camera is used, combined with template matching and image processing algorithms, to automatically measure the inner and outer contours and geometric features of the flange to achieve contactless dimensional measurement.
It improves detection accuracy and efficiency, reduces manual labor damage, ensures the accuracy and consistency of measurement, eliminates unqualified products, and avoids safety hazards.
Smart Images

Figure CN116237266B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of optical measurement systems and relates to a flange size measurement method and equipment. Background Art
[0002] Regarding a flange in an automotive accessory, it is made through processing techniques such as blank sintering, press molding, and turning. During the processing, there may be dimensional deviations, resulting in the flange failing to achieve a sealing effect, oil leakage after installation, and even potential safety hazards in subsequent vehicle use. Therefore, dimensional inspection is required.
[0003] At present, automobile flange manufacturers generally use manual methods such as vernier calipers, go / no-go gauges and fixtures to measure the diameter, circle spacing, and outer contour length and width of such flanges during final inspection to eliminate unqualified products and ensure product quality.
[0004] This manual inspection method has the following shortcomings: (1) It requires high vision; (2) It is labor-intensive and causes great damage to the eyes; (3) Manual judgment is highly random and the quality of flanges cannot be guaranteed; (4) It is inefficient and the continuous working time cannot be too long, which affects production efficiency; (5) The increasing labor cost also brings great pressure to enterprises. Summary of the Invention
[0005] In order to overcome the deficiencies of the prior art, the present invention provides a flange size measuring method and equipment.
[0006] In order to achieve the above object, the present invention adopts the following technical solution: a flange size measurement method, comprising the following steps:
[0007] S1. Use a telecentric light source to illuminate the back of the workpiece from below the stage, and use a camera above the stage to obtain a projection image of the workpiece;
[0008] S2. The analysis and processing unit calls the corresponding template to match the workpiece, and performs position correction on the projection image of the current workpiece according to the position information of the template;
[0009] S3. After the position is corrected, the analysis and processing unit selects the edge contour point set of each circle from all the inner contour point sets of the workpiece;
[0010] S3.1. Using the obtained edge contour point set of the circle, perform circle fitting on the circle to obtain the circle center information;
[0011] S3.2. Obtain the center distance information between the circles based on the circle center information;
[0012] S4. After the position is corrected, the analysis and processing unit screens and extracts the edge contour point set of each long side of the workpiece from the workpiece outer contour point set;
[0013] S4.1. Using the obtained edge contour point set of the long edge, fit the long edge to obtain several straight lines;
[0014] S4.2. Fitting a polygon with a plurality of straight lines to obtain a plurality of diagonals of the polygon;
[0015] S4.3. Find the edge of the workpiece based on the angle and position information of the diagonal line to obtain two points where the diagonal line intersects with the workpiece edge point set, and obtain the length or width of the workpiece based on the distance between the two points;
[0016] S5. The analysis and processing unit outputs all measured dimensional information.
[0017] Furthermore, the template matching in step S2 includes the following steps:
[0018] S2.1, performing grayscale binarization on each pixel in the grayscale image to be inspected;
[0019] S2.2, using the Sobel edge detection algorithm to obtain a grayscale gradient image;
[0020] S2.3. Perform contour finding processing on the grayscale gradient image to obtain the outer contour point set and inner contour point set information of the workpiece;
[0021] S2.4. Obtain the ROI area information of the workpiece, that is, the minimum circumscribed rectangle information of the outer contour of the workpiece.
[0022] Furthermore, the method also includes comparing the minimum external rectangle information of the workpiece with the template to determine the matching degree between the template and the workpiece.
[0023] Furthermore, in step S2.1, the grayscale value binarization includes: setting the grayscale value of pixels greater than 100 to 1, and vice versa.
[0024] Furthermore, in step S2.4, the minimum bounding rectangle information includes: the center point and rotation angle of the minimum bounding rectangle.
[0025] Furthermore, in step S2, the position correction includes: establishing a position offset reference according to the center point of the matching template and the angle of the matching template, realizing the coordinate rotation offset of the ROI area, so that the ROI area keeps pace with the changes in image angle and pixels.
[0026] Furthermore, in step S3.1, the circle fitting is performed using a circle fitting method implemented by combining the Ransac algorithm principle with the least squares method principle.
[0027] Furthermore, in step S4.1, the long side is fitted using a circle fitting method implemented by combining the Ransac algorithm principle with the least squares method principle.
[0028] A flange size measuring device adopts the above-mentioned flange size measurement method, comprising a stage, a telecentric light source, a camera, and an analysis and processing unit; the stage is used to place a workpiece, the telecentric light source and the camera are respectively arranged on two sides of the workpiece opposite to each other, and when the telecentric light source is turned on, the camera obtains a grayscale image of the workpiece; the analysis and processing unit stores template information, receives the grayscale image, and calls the corresponding template for matching and position correction.
[0029] In summary, the present invention is beneficial in that:
[0030] 1) The present invention replaces humans with machines, that is, an automated non-contact optical detection system is used to measure the dimensions of the flange and reject unqualified products. Optical image detection replaces the human eye, has no vision requirements, and has guaranteed clarity. It also avoids the problems of personal injury and reduced efficiency caused by long-term manual labor.
[0031] 2) The present invention obtains an image containing the inner and outer contour edges of the workpiece through projection, uses template matching to determine the detection area, improves the detection accuracy, and then accurately obtains the geometric features of the workpiece by fitting the edge contour point set of the holes and edges on the workpiece to obtain the geometric size information of the workpiece. The measurement accuracy is high and the consistency is strong. The quality and efficiency of the detected products are greatly improved compared with manual labor. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 Schematic diagram of the flange size measuring device of the present invention.
[0033] Figure 2 Schematic diagram of the defect detection system.
[0034] Figure 3 Schematic diagram of the defect detection method.
[0035] Figure 4 Schematic diagram of the template matching process.
[0036] Figure 5 Schematic diagram of the dimension measurement process.
[0037] Figure 6 It is a schematic diagram of the size composition of the flange of the present invention.
[0038] Markings in the figure: 1. Detection device; 11. Telecentric light source; 12. Coaxial light source; 13. Horizontal light source; 14. Camera; 15. Stage; 16. Housing; 17. Telecentric lens; 2. Gear manipulator; 3. Conveyor belt; 4. Vibrating screen plate; 5. Photoelectric sensor. DETAILED DESCRIPTION
[0039] The following describes the embodiments of the present invention through specific examples. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments. The details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the following embodiments and features in the embodiments can be combined with each other unless they conflict.
[0040] It should be noted that the illustrations provided in the following embodiments are merely schematic illustrations of the basic concept of the present invention. Therefore, the illustrations only show components related to the present invention and are not drawn according to the number, shape, and size of components in actual implementation. In actual implementation, the type, quantity, and proportion of each component may be changed arbitrarily, and the component layout may also be more complex.
[0041] All directional indications in the embodiments of the present invention (such as up, down, left, right, front, back, horizontal, vertical...) are only used to explain the relative position relationship, movement status, etc. between the components in a certain specific posture. If the specific posture changes, the directional indication will also change accordingly.
[0042] like Figure 1 As shown, a detection system includes a vibrating screen plate 4, a conveyor belt 3, a rack robot 2, a photoelectric sensor 5, a detection device 1, etc., which is used to detect surface defects of the workpiece to be tested (specifically a flange), analyze, count and sort qualified and unqualified products.
[0043] The detection system in this embodiment adopts machine replacement. The vibrating screen plate 4 is arranged at one of the transmission ends of the conveyor belt 3, and the detection device 1 is arranged at the other transmission end of the conveyor belt 3. An analysis and processing unit is provided in the detection device 1, and the analysis and processing unit is communicated with the conveyor belt 3, the rack manipulator 2, and the photoelectric sensor 5. When detecting and screening multiple flanges, the flanges are laid flat on the vibrating screen plate 4, and the vibrating screen plate 4 vibrates to shake the flanges off on the conveyor belt 3 in sequence, and the conveyor belt 3 transports the flanges toward the detection device 1. The photoelectric sensor 5 is arranged at The position on the conveyor belt 3 close to the detection device 1 is also within the working range of the rack robot 2. Its photoelectric detection range covers the top of the conveyor belt 3 at this position. When the flange moves into the detection range, the photoelectric sensor 5 triggers the conveyor belt 3 to pause, and at the same time triggers the rack robot 2 to grab the flange and place it in the detection device 1; when the detection device 1 completes the detection, the analysis and processing unit sends a detection result classification signal and a grabbing signal to the rack robot 2, and the rack robot 2 grabs the qualified products and unqualified products into the conveyor belt 3 and the waste box respectively according to the classification signal.
[0044] The rack manipulator 2 is equipped with a controller, which is used to control the movement of the rack manipulator 2 and also to communicate with the analysis and processing unit, the photoelectric sensor 5 and the like.
[0045] Among them, the detection device 1 includes a shell 16, in which a camera 14, a coaxial light source 12, a horizontal light source 13, and a telecentric light source 11 are fixedly arranged in sequence from top to bottom. The camera 14 is directed directly downward to shoot. Specifically, the camera 14 is coaxially arranged with the coaxial light source 12 and the telecentric light source 11; a stage 15 is arranged between the coaxial light source 12 and the telecentric light source 11 in the vertical direction, the coaxial light source 12 illuminates the stage 15 from top to bottom, the telecentric light source 11 illuminates the stage 15 from bottom to top, and the horizontal light source 13 illuminates the stage 15 from the side. The flange is placed on the stage 15, and the coaxial light source 12, the telecentric light source 11, and the horizontal light source 13 provide front, back, and side light illumination for the flange respectively.
[0046] Furthermore, the stage 15 should be made of a light-transmitting material, or be transparent, so that at least the light from the telecentric light source 11 can illuminate the camera 14 .
[0047] The horizontal light source 13 is composed of four strip light sources to form a U-shape. When the flange is placed on the stage 15, the flange should be located inside the U-shape, so that the horizontal light source 13 can provide lateral inclined illumination for the flange.
[0048] In the entire detection system of this embodiment, the camera 14, the telecentric light source 11, the coaxial light source 12, and the horizontal light source 13 are all in communication with the analysis and processing unit and are controlled by the analysis and processing unit. To ensure the clarity of the workpiece image under various light sources, the telecentric light source 11, the coaxial light source 12, and the horizontal light source 13 are selectively activated as follows:
[0049] When and only when the telecentric light source 11 is turned on (the first illumination condition), the camera 14 captures an image (projection image) of the workpiece illuminated by the telecentric light source 11 above the workpiece. In the projection image, only the flange area is black, while other areas are white, thereby clearly highlighting the edge of the flange.
[0050] When and only when the coaxial light source 12 is turned on (second illumination condition), the camera 14 captures an image of the upper surface of the flange from above the coaxial light source 12. That is, the image captured by the camera 14 after the vertical light generated by the coaxial light source 12 located above the workpiece hits the upper surface of the flange (first surface image) can highlight defects such as pits, missing material, tool chatter, and negative and positive surfaces.
[0051] When and only when the horizontal light source 13 is turned on (the third illumination condition), the camera 14 collects another image of the upper surface of the flange downward from above the horizontal light source 13, that is, the image (second surface image) that can be captured by the camera 14 after the side light generated by the horizontal light source 13 located on the side of the workpiece is obliquely hit on the upper surface of the flange, which can highlight defects such as scratches.
[0052] For these three types of images that can be collected, defect detection of the flange can be realized, and the analysis and processing unit in the detection device 1 performs detection and analysis based on the image collected by the camera 14; the detection specifically includes through-hole detection, front and back detection, size measurement, pit detection, material shortage detection, knife vibration detection, positive and negative surface detection, scratch detection, etc.
[0053] The flange in this embodiment is specifically a flange for fastening the oil cover, which is made through blank sintering, press molding, turning and other processing techniques. The following situations may exist during the processing: pits and material shortages occur during the blank production process; scratches on the plane are caused by the flow of each process; for unqualified processed surfaces that can be reworked, the negative and positive surfaces are caused after further processing due to insufficient processing allowance; tool damage during processing leads to tool vibration; dimensional deviations occur during processing, so it is necessary to distinguish between qualified and unqualified products through the above-mentioned defect detection.
[0054] In addition, the flange in this embodiment needs to be distinguished because it has a front and a back side due to its own process; and the flange also includes two types: a through-hole flange and a non-through-hole flange, that is, the through-hole flange has a circular hole with a smooth inner wall, and the non-through-hole flange has a circular hole with features such as threads or flanges on the inner wall (that is, the size of the circular hole includes an inner circle and an outer circle), so it also needs to be distinguished.
[0055] To distinguish between through holes and non-through holes, a template matching process is performed in the projection image under the first illumination condition, and then the flange is judged as a through hole flange or a non-through hole flange based on the matched template; and after the flange is template matched, the analysis and processing unit generates a classification signal according to the flange type, so as to control the rack robot 2 to sort and count it after the subsequent detection process.
[0056] A defect detection method performed by the above-mentioned defect detection system includes the following steps:
[0057] S1, turning on the telecentric light source 11, the camera 14 collects the projection image of the workpiece, and performs a template matching process based on the projection image to determine whether the workpiece is a through hole or a non-through hole;
[0058] S2, turning on the coaxial light source 12, the camera 14 captures the first surface image of the workpiece, and performs grayscale value statistical analysis based on the first surface image to determine whether the workpiece is the front or back side;
[0059] S3, turning on the coaxial light source 12, the camera 14 captures a first surface image of the workpiece, and performing a defect detection process based on the first surface image to determine whether the workpiece has four defects: pits, missing material, tool vibration, and positive and negative surfaces; turning on the horizontal light source 13, the camera 14 captures a second surface image of the workpiece, and performing a defect detection process based on the second surface image to determine whether the workpiece has scratch defects;
[0060] S4, turn the workpiece over;
[0061] S5. Turn on the coaxial light source 12, and the camera 14 captures a first surface image of the workpiece. Based on the first surface image, a defect detection process is performed to determine whether the workpiece has four defects: pits, missing material, tool vibration, and yin-yang surface defects. Turn on the horizontal light source 13, and the camera 14 captures a second surface image of the workpiece. Based on the second surface image, a defect detection process is performed to determine whether the workpiece has scratch defects.
[0062] S6, turning on the telecentric light source 11, the camera 14 collects the projection image of the workpiece, and performs a size detection process based on the projection image to determine whether the size of the workpiece is compliant;
[0063] S7 , turning on the coaxial light source 12 , the camera 14 collects a first surface image of the workpiece, and measures the outer diameter of the non-through hole based on the first surface image.
[0064] Among them, step S6 can be performed before or after any one of steps S2, S3, S4, and S5.
[0065] Among them, after the workpiece has successively undergone steps S1 and S2, if the workpiece is judged to be a non-through hole workpiece and the current surface is the front side, step S7 is performed after step S4; if the workpiece is judged to be a non-through hole workpiece and the current surface is the back side, step S7 is performed between steps S2 and S4.
[0066] The template matching process in step S1 includes the following steps:
[0067] S1.1. Binarize each pixel in the grayscale image to be inspected, i.e., set the grayscale value of pixels with a grayscale value greater than 100 to 1, and vice versa to 0;
[0068] S1.2, using the Sobel edge detection algorithm to obtain a grayscale gradient image;
[0069] S1.3. Perform contour finding processing on the grayscale gradient image to obtain the outer contour point set and inner contour point set information of the workpiece;
[0070] S1.4. Obtain the minimum circumscribed rectangle of the workpiece's outer contour, including the center point, rotation angle, length, and width of the minimum circumscribed rectangle, and the minimum circumscribed circle area of the maximum inner contour;
[0071] S1.5. Traverse each prepared template model and compare the minimum circumscribed rectangle area and aspect ratio information of the template with the workpiece. If either the area ratio or the aspect ratio is not within the range of 98% to 102%, it is determined that the match has failed and the traversal continues to the next template. If both ratios are within the range of 98% to 102%, the minimum circumscribed circle area of the maximum inner contour of the template is further compared with that of the workpiece. If the ratio is within the range of 98% to 102%, it is determined that the match has succeeded. Otherwise, it is determined that the match has failed and the traversal continues to the next template.
[0072] S1.6. If a certain template is successfully matched when traversed, the traversal ends and the template matching information is output; if all templates are traversed and no match is successful, the interface prompts that the template matching failed.
[0073] First, the contour search algorithm is implemented by calling the contour search function in the open source algorithm library Opencv. The principle of contour search is that for a binary image with a black background and a white target, if a white point is found in the image and its 8-neighborhood (or 4-neighborhood) are also white, it means that the point is an internal point of the target and is set to black, which visually looks like the inside is hollowed out; otherwise, the white color remains unchanged, and the point is the boundary point of the target (or contour point). By traversing the entire image according to the above method, each contour (or contour point set) will be obtained and stored in the form of a point vector. In addition, the topological information of an image is also obtained, that is, the index number of the next contour, the previous contour, the parent contour and the embedded contour of a contour.
[0074] Secondly, step S1.1 specifically refers to converting the detection area image after grayscale binarization into a black and white image, where a grayscale value of 0 represents black and a grayscale value of 255 represents white; and then performing Sober edge detection processing on the detection area image after binarization.
[0075] The Sober edge detection process is as follows:
[0076] S1.2.1. Assume that the matrix A represents the pixel value matrix of the detection area image;
[0077] S1.2.2. Calculate the derivatives in the horizontal (x) and vertical (y) directions respectively.
[0078] Horizontal direction: Convolve A with a kernel of size 3, as shown in formula (1):
[0079]
[0080] In formula (1), G x Represents the grayscale gradient value in the horizontal direction.
[0081] Vertical direction: Convolve A with a kernel of size 3, as shown in formula (2):
[0082]
[0083] In formula (2), G y Represents the grayscale gradient value in the vertical direction.
[0084] The grayscale gradient value of each pixel in the horizontal and vertical directions of the image is combined by the following formula (3) to calculate the grayscale gradient value of the point.
[0085]
[0086] In formula (3), G represents the grayscale gradient value of the current pixel.
[0087] In step S2, for the front and back side detection, it is because in the case of a non-through hole workpiece, the measurement of the outer diameter of the non-through hole needs to be carried out from the back side, and thus the front and back sides of the flange need to be distinguished. Specifically, under the second illumination condition, the grayscale value of the surface of the flange is statistically analyzed in the first surface image, and the average value of the grayscale value is compared to determine whether the current side is the front side or the back side.
[0088] In step S6, refer to Figure 5 and Figure 6 , the size detection process includes the following steps:
[0089] S6.1. Obtaining ROI area information of the workpiece;
[0090] S6.1.1. The workpiece ROI area information is the minimum circumscribed rectangle information of the workpiece outer contour point set;
[0091] S6.2. Correct the position of the current workpiece image according to the position information of the template;
[0092] S6.2.1. Position correction is a tool that assists in positioning, corrects target motion offset, and assists in precise positioning. It establishes a position offset benchmark based on the center point and angle of the matching template in the template matching results, and then implements coordinate rotation offset of the ROI area, that is, allowing the ROI area to keep up with changes in image angle and pixels.
[0093] S6.3. After position correction, the detection frame areas of the left, center, and right circles are also corrected accordingly. Based on the position-corrected detection frame areas, the edge contour point sets of the left, center, and right circles are selected from all the inner contour point sets of the workpiece.
[0094] S6.4. Using the obtained left circle contour point set, perform circle fitting on the left circle to obtain circle 1; using the obtained middle circle contour point set, perform circle fitting on the middle circle to obtain circle 2; using the obtained right circle contour point set, perform circle fitting on the right circle to obtain circle 3;
[0095] S6.5. Obtain the center distance between circle 1 and circle 2 based on the circle center information; obtain the center distance between circle 2 and circle 3 based on the circle center information;
[0096] S6.6. After the position correction, the detection frame areas of the four long sides of the workpiece are also corrected accordingly. Based on the position-corrected detection frame areas, the contour point sets of the four long sides of the workpiece are screened and extracted from the workpiece outer contour point set.
[0097] S6.7. Using the obtained contour point sets of the four long sides of the workpiece, fit the four long sides of the workpiece to obtain lines 1, 2, 3, and 4;
[0098] S6.8, fit a quadrilateral through lines 1, 2, 3, and 4;
[0099] S6.9. Obtain the long diagonal 1 and the short diagonal 2 of the quadrilateral;
[0100] S6.10. Find the edge of the workpiece based on the angle and position information of diagonal line 1;
[0101] S6.10.1. Edge search is to find the point of intersection with the workpiece outer contour point set based on the straight line equation of diagonal line 1. The intersection point on the left is the left edge, and the intersection point on the right is the right edge.
[0102] S6.11. Obtain the workpiece length based on the distance between the left edge point and the right edge point;
[0103] S6.12. Find the edge of the workpiece based on the angle and position information of diagonal line 2;
[0104] S6.12.1. Edge search is to find the point of intersection with the workpiece edge point set based on the straight line equation of diagonal line 2. The upper intersection point is the upper edge, and the lower intersection point is the lower edge.
[0105] S6.13. Obtain the workpiece width based on the distance between the upper edge and the lower edge;
[0106] S6.14. Output all measured dimensional information.
[0107] Among them, the circle fitting method used in step S6.4 and the straight line fitting method used in step S6.7 are realized by combining the Ransac algorithm principle with the least squares method principle.
[0108] Specifically, in step S6.4, the circle fitting method is as follows:
[0109] S6.4.1, let the contour point set extracted from the corresponding detection area There are n pixels, where point (x j ,y j ) represents the jth pixel point in the contour point set. Assume that the equation of the circle is: (xA) 2 +(yB) 2 =R 2 , where A represents the horizontal coordinate point of the circle center, B represents the vertical coordinate point of the circle center, and R represents the radius of the circle;
[0110] S6.4.2. Randomly select three points from n pixels and substitute them into the circle equation (xA) 2 +(yB) 2 =R 2 , find A, B and R;
[0111] S6.4.3. Calculate the distance from other points to the circle. Any points smaller than a certain threshold (in this embodiment, the threshold is set to 2 pixels) are considered inliers and the number of inliers is counted.
[0112] S6.4.4. Repeat steps S6.4.2 to S6.4.3 M times to obtain the inner point set with the largest number of points.
[0113] S6.4.5. The inner point set with the largest number of points Running the least squares method yields
[0114]
[0115]
[0116]
[0117]
[0118]
[0119]
[0120]
[0121]
[0122]
[0123]
[0124] Among them, C, D, E, G, H, a, b, and c are all intermediate calculation parameters in the derivation process of A, B, and R, that is, the calculation formulas of A, B, and R are reasonably split and used to refer to the parameters of each split formula.
[0125] The required circle equation (xA) is obtained 2 +(yB) 2 =R 2 ,
[0126] The point (x i ,y i ) represents the i-th pixel in the inlier set, and N represents the number of pixels in the inlier set;
[0127] The value of M can be estimated by the following formula Among them, p represents the probability of the internal point, p 2 Indicates the probability that all three points are interior points, 1-p 3 represents the probability that there is at least one outlier (sampling failure) among the three, z = 1-(1-p 3 ) M It indicates the probability of at least one success in M samplings;
[0128] In this embodiment, assuming that p=0.8 and z=0.99, the value of M can be 7.
[0129] Specifically, in step S6.7, the straight line fitting method is as follows:
[0130] S6.7.1, let the contour point set extracted from the corresponding detection area There are n pixels, where point (x j ,y j ) represents the j-th pixel point in the contour point set. Assume that the equation of the straight line is: y = a*x + b, where a represents the slope of the straight line and b represents a constant;
[0131] S6.7.2. Randomly select two points from n pixels and substitute them into the linear equation y = a*x + b to find a and b.
[0132] S6.7.3. Calculate the distance from other points to the line. Any points smaller than a certain threshold (in this embodiment, the threshold is set to 2 pixels) are considered inliers and their number is counted.
[0133] S6.7.4. Repeat steps S6.7.2 to S6.7.3 M times to obtain the inner point set with the largest number of points.
[0134] S6.7.5. The inner point set with the largest number of points Running the least squares method yields
[0135] The required straight line equation is y=a*x+b;
[0136] The point (x i ,y i ) represents the i-th pixel in the inlier set, and N represents the number of pixels in the inlier set;
[0137] The value of M can be estimated by the following formula Among them, p represents the probability of the internal point, p 2 Indicates the probability that two points are both interior points, 1-p 2 represents the probability that there is at least one outlier (sampling failure) between 2 points.
[0138] z=1-(1-p 2 ) M It indicates the probability of at least one success in M samplings;
[0139] In this embodiment, assuming that p=0.8 and z=0.99, the value of M can be 5.
[0140] In summary, for the above-mentioned circle fitting and straight line fitting process, if only the least squares method is used to fit the circle or straight line, when there are small burrs, small convex points or small concave points locally on the edge of the workpiece, outliers will exist when the extracted contour is used for fitting, which will lead to inaccurate fitting. The method in this paper is to first use the idea of Ransac algorithm, and according to the settings, randomly extract a contour point from the detection object (contour point set) to be an inner point (non-outlier point) with the probability p and the probability z of at least one successful sampling in M times, and then know the number of sampling times M, and then count the inner point set with the largest number of points, and then perform least squares fitting, which can effectively eliminate outliers and improve fitting accuracy, that is, improve measurement accuracy.
[0141] In step S3 / S5, for pit detection and material shortage detection, under the second illumination condition, less light is reflected back to the camera 14 from the pits and material shortage, so the area they occupy is darker than other normal areas, that is, the grayscale value of the pixels they contain is smaller than that of other normal areas, so the grayscale value is set according to the set value (preferably 80 in this embodiment). Figure 2 The grayscale value of pixels greater than the set value is set to 1, and the grayscale value of pixels not greater than the set value is set to 0. Then the connected domain with the pixel grayscale value of 0 is extracted. If the area of the extracted connected domain is greater than the set value (preferably 1.5mm in this embodiment), the connected domain is extracted. 2 ), which is judged as a pit or missing material.
[0142] In step S3 / S5, for the detection of vibration knife and yin-yang surface, under the second illumination condition, the vibration knife and yin-yang surface areas have lost the inherent halo-shaped shallow lines on the surface due to excessive processing, making their brightness brighter than other normal areas, that is, the grayscale values of the pixels they contain are larger than those of other normal areas. Therefore, the grayscale image is first mean filtered, and then the maximum inter-class variance is used to obtain the optimal threshold k for grayscale thresholding. * Then judge k * Is it within the set range (the preferred setting range in this embodiment is 100 to 180), if not, it is determined that there is no vibration knife, yin and yang surface area, if so, the defect exists, and the obtained k is used to determine whether the vibration knife or yin and yang surface area exists. * Count the area occupied by the vibration knife and the positive and negative surfaces. If it is larger than the set value (preferably 4mm in this embodiment), 2 ), it is determined to be a vibration knife or yin-yang surface defect area, otherwise, the occupied area is too small and it is determined that the defect does not exist.
[0143] Among them, the mean filtering is to traverse each pixel point in the grayscale image and perform the following processing on each pixel point: the pixel point is called the target pixel point, and a filtering template is formed with the target pixel point as the center and the eight pixels around the target pixel point. The grayscale value of the target pixel point is then replaced by the grayscale average value of all pixels in the template.
[0144] The maximum inter-class variance method is used to obtain the optimal threshold k for grayscale thresholding. * The implementation ideas are as follows:
[0145] For the grayscale image, there are 256 gray levels [1, 2, ..., 256]. The number of pixels with gray level i is n i , then the total number of pixels is
[0146] Use the normalized grayscale histogram and consider it as the probability distribution of this image:
[0147]
[0148] Among them, p in formula (4) i Represents the probability that the gray level in this image is i.
[0149] Now suppose that these pixels are divided into two categories: C0 and C1 using a grayscale threshold of k; C0 represents pixels with grayscales of [1, 2, ..., k], and C1 represents pixels with grayscales of [k+1, ..., 256]. Then, the probability of each category appearing and the average grayscale of each category are given by the following equations:
[0150]
[0151] In formula (5), ω0 represents the probability of C0 appearing, and ω(k) represents the cumulative probability of gray levels from 1 to k.
[0152]
[0153] Wherein, ω1 in formula (6) represents the probability of C1 appearing.
[0154]
[0155] In formula (7), μ0 represents the average gray level of C0, and μ(k) represents the average gray level from gray levels 1 to k.
[0156]
[0157] Wherein, μ1 in formula (8) represents the average gray level of C1, μ T Represents the average gray level of the entire image.
[0158]
[0159]
[0160] are the cumulative occurrence probability and average gray level (first-order cumulative moment) of gray levels from 1 to k, respectively, and
[0161]
[0162] is the average gray level of the entire image.
[0163] For any chosen k, we have:
[0164] ω0μ0+ω1μ1=μ T ,ω0+ω1=1. (12)
[0165] The following formula (13) is used as the measurement standard to evaluate the “goodness” (separability) of selecting k as the threshold:
[0166]
[0167] in, represents the between-class variance, Represents the total variance of gray levels:
[0168]
[0169] According to formula (12), we can get:
[0170]
[0171] These two formulas are the between-class variance and the total grayscale variance respectively.
[0172] Use the following formula to select different k values to search sequentially, and find the optimal threshold k according to formulas (9) and (10): * Make η reach the maximum value, or equivalently make Reach the maximum.
[0173]
[0174]
[0175] And, the optimal threshold k * that is
[0176]
[0177] Among them, vibration tool and yin-yang surface defects will be generated during the processing of the workpiece, and the front side of the workpiece is the processing surface. Therefore, further, the vibration tool and yin-yang surface defect detection of this embodiment is only performed on the front side of the workpiece, and in the defect detection process, the defect detection of pits and missing materials is performed first. After the workpieces with pits and missing materials are eliminated, the vibration tool and yin-yang surface defect detection are performed to ensure the accuracy of the vibration tool and yin-yang surface defect detection.
[0178] In step S3 / S5, for scratch detection, under the third illumination condition, more light from the scratch is reflected back to the photosensitive surface of the camera 14, and less light from other normal areas is reflected back to the photosensitive surface of the camera 14. However, considering that scratch defects of different shapes and depths may exist at the same time, and the distinction between them and normal areas is not great, a deep learning method is used for detection. In the process of labeling defect targets in grayscale images, a morphological closing operation is first performed on the grayscale image so that some discontinuous scratches can be connected and presented as complete. After the model is trained, when performing detection, a morphological closing operation is also performed on the grayscale image to be detected before the model is called for detection. Specifically, according to the size of the trained model (for example, the model size is a matrix size of 5 pixels by 5 pixels), the grayscale image processed by the morphological closing operation is traversed. If the confidence level of a certain area in the grayscale image and the model reaches 90%, it is determined to be a scratch, otherwise it is not.
[0179] The training process of the deep learning model mentioned above includes the following steps:
[0180] S3 / 5.1 collects a large number of scratch sample images;
[0181] S3 / 5.2 Mark the scratch areas in all sample images;
[0182] S3 / 5.3 The labeled data and images are input into the backbone network;
[0183] S3 / 5.4 normalizes the sample images in the training set in the network and scales them to an integer multiple of 32;
[0184] S3 / 5.5 sets the width and height of the initial candidate box in the boundary regression module;
[0185] S3 / 5.6 starts iterative training of prediction models;
[0186] After S3 / 5.7 completes training, it generates a prediction model and exports it;
[0187] S3 / 5.8 uses the prediction model to reason about the actual detection image;
[0188] S3 / 5.9 Determine whether the detection accuracy exceeds 95%;
[0189] If the accuracy in S3 / 5.10 is less than 95%, proceed to step S3 / 5.11; if it is greater than 95%, proceed to step S3 / 5.14;
[0190] S3 / 5.11 Re-mark any missed scratches;
[0191] S3 / 5.12 Removal of marks in normal areas that were mistakenly detected as scratches;
[0192] S3 / 5.13 enters the re-labeled image into step S3 / 5.3;
[0193] S3 / 5.14 training completed.
[0194] In addition, in the detection device 1 in this embodiment, the three light sources and the camera 14 are arranged in the shell 16 in order to obtain a good illumination effect, avoid interference from external ambient light, etc., and avoid affecting the accuracy of the detection. After the shell 16 is set, the action of the frame manipulator 2 to move the flange to the stage 15 in the shell 16 has certain limitations, which is limited by the flexibility of the frame manipulator 2. Therefore, this embodiment also includes a telescopic mechanism, which is installed on the stage 15 and communicates with the analysis and processing unit to drive the stage 15 to extend out of the shell 16 to facilitate the frame manipulator to move and flip the flange on the stage 15; the telescopic mechanism in this embodiment can be preferably an electric linear slide.
[0195] It should be added that in order for the camera 14 to obtain better image information, a telecentric lens 17 is further provided at the shooting end of the camera 14. When the workpiece is placed on the stage 15, due to the influence of machine precision and other factors, its placement position cannot achieve a uniform coaxial effect with the shooting direction of the camera 14, that is, it is placed crookedly. In this case, it will have a certain impact on the various detection results mentioned above, especially in dimensional measurement. When the workpiece is placed crookedly, the side of the workpiece will also be photographed and easily merged into the upper surface range of the workpiece, thereby causing dimensional measurement errors. Therefore, this embodiment adopts a telecentric lens 17 installed at the shooting end of the camera 14, and utilizes the high resolution, ultra-wide depth of field, ultra-low distortion and unique parallel light design of the telecentric lens 17 to reduce the impact of the workpiece being crooked on the image obtained by the camera 14.
[0196] Obviously, the embodiments described are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
Claims
1. A flange size measurement method, characterized in that: The following steps are involved: S1. Turn on the telecentric light source, and the camera collects the projection image of the workpiece. The template matching process is performed based on the projection image to determine whether the workpiece is a through hole or a non-through hole; S2. Turn on the coaxial light source, use the camera to capture the first surface image of the workpiece, perform grayscale value statistical analysis based on the first surface image, and determine whether the workpiece is the front or back side; S3. Turn on the coaxial light source, and the camera collects the first surface image of the workpiece. The defect detection process is performed based on the first surface image to determine whether the workpiece has four defects: pits, missing materials, tool vibration, and positive and negative surfaces; Turn on the horizontal light source, and the camera collects the second surface image of the workpiece. The defect detection process is performed based on the second surface image to determine whether the workpiece has scratch defects; Turn the workpiece over and inspect the surface for defects such as pits, missing material, tool vibration, yin-yang surface, and scratches again; S4. Turn on the telecentric light source, and the camera collects the projection image of the workpiece. The size detection process is carried out based on the projection image to determine whether the size of the workpiece is compliant. The size detection process includes: S4.
1. Obtain the workpiece's ROI information and perform position correction on the projected image of the current workpiece based on the template's position information. Position correction includes: establishing a position offset reference based on the center point and angle of the matching template, achieving coordinate rotation and offset of the ROI, so that the ROI keeps pace with changes in image angle and pixels; S4.
2. After position correction, select the edge contour point sets of the left, middle and right circles from all the inner contour point sets of the workpiece; S4.2.
1. Using the obtained circle edge contour point set, perform circle fitting on the circle to obtain the circle center information. The circle fitting method is implemented by combining the Ransac algorithm principle with the least squares method principle. S4.2.
2. Obtain the center distance information between the circles based on the circle center information; S4.
3. After position correction, the edge contour point sets of the four long sides of the workpiece are screened and extracted from the workpiece outer contour point set; S4.3.
1. Using the obtained edge contour point sets of the four long sides, fit the four long sides of the workpiece to obtain four straight lines. The long sides are fitted using the straight line fitting method implemented by the Ransac algorithm combined with the least squares method. S4.3.
2. Fit a quadrilateral using four straight lines to obtain the long and short diagonals of the quadrilateral. S4.3.
3. Find the edge of the workpiece based on the angle and position information of the diagonal line to obtain the two points where the long diagonal line intersects the workpiece edge point set. Calculate the workpiece length based on the distance between the two points. Calculate the workpiece width based on the distance between the two points where the short diagonal line intersects the workpiece edge point set. S4.
4. Output all measured dimensional information.
2. A flange size measurement method according to claim 1, characterized in that: The template matching process includes: S1.1, performing grayscale binarization on each pixel in the grayscale image to be inspected; S1.2, using the Sobel edge detection algorithm to obtain a grayscale gradient image; S1.
3. Perform contour finding processing on the grayscale gradient image to obtain the outer contour point set and inner contour point set information of the workpiece; S1.
4. Obtain the ROI area information of the workpiece, that is, the minimum circumscribed rectangle information of the outer contour of the workpiece.
3. A flange size measurement method according to claim 2, characterized in that: It also includes comparing the minimum external rectangle information of the workpiece with the template to determine the matching degree between the template and the workpiece.
4. A flange size measurement method according to claim 2, characterized in that: In step S1.1, the grayscale value binarization includes: the grayscale value of the pixel points with a grayscale value greater than 100 is set to 1, and vice versa.
5. A flange size measurement method according to claim 2, characterized in that: In step S1.4, the minimum bounding rectangle information includes: the center point and rotation angle of the minimum bounding rectangle.
6. A flange size measuring device, using the flange size measuring method according to any one of claims 1 to 5, characterized in that: The system comprises a stage, a telecentric light source, a camera and an analysis and processing unit; the stage is used to place a workpiece, the telecentric light source and the camera are respectively arranged on two sides of the workpiece relative to each other, and when the telecentric light source is turned on, the camera obtains a grayscale image of the workpiece; the analysis and processing unit stores template information, receives grayscale images and calls corresponding templates for matching and position correction.
Citation Information
Patent Citations
Machine vision-based size measurement scoring system and measurement method
CN112284250A