Cloth simulation-based thread size parameter calculation method and system
Through fabric simulation technology, the threaded tooth top and tooth bottom are divided and the mathematical model is constructed, which solves the problem of insufficient template adaptability in the existing technology, realizes high-precision thread parameter measurement, and improves measurement efficiency and adaptability.
Patent Information
- Application Number
- CN202510434501.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-08
- Publication Date
- 2025-07-22
AI Technical Summary
During the existing visual thread parameter measurement process, the thread-building templates and templates of different specifications need to be insufficient adaptability, resulting in low measurement efficiency and limited accuracy.
The thread size parameter calculation method is used based on fabric simulation, and the thread profile points are obtained through edge detection algorithm, and the tooth bottom and tooth top are divided by fabric simulation, and the corresponding mathematical model is constructed for fitting, so as to calculate the dimensional parameters between adjacent teeth.
Improves the accuracy and adaptability of thread measurement, simplifies the measurement steps, enhances the adaptability of machine vision in thread measurement, and reduces measurement errors.
Smart Images

Figure CN120355769A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of thread measurement, and relates to a calculation method and system for thread size parameters based on cloth simulation. Background Art
[0002] In the field of industrial manufacturing, threads play a crucial role in component connection, load bearing, and precise assembly. The design and manufacturing quality of threads are directly related to the operational reliability and safety of mechanical systems. Therefore, quickly and accurately measuring the geometric parameters of threads has important engineering value. Currently, thread parameter measurement methods are mainly divided into two categories: contact type and non-contact type. Contact measurement usually relies on tools such as gauges to evaluate specific parameters, but this method has problems such as low measurement efficiency, high labor costs, and limited accuracy. In contrast, non-contact measurement is based on machine vision technology, which can achieve real-time detection of multiple parameters and has the advantages of higher measurement accuracy and efficiency. Therefore, it shows significant application prospects in modern industrial inspection.
[0003] In the field of machine vision, many scholars have conducted in-depth research on non-contact measurement of thread parameters. CN105157611A discloses a visual inspection method for pipe threads. This method requires establishing template contour features for standard thread workpieces and workpieces to be inspected, and judging whether the similarity of the two contour features reaches a preset value. Jiang Yulin et al. intercepted the peak segment contour by setting a threshold, and then used a peak extraction algorithm to extract peaks to solve the pitch parameter, but a reference value of the pitch needs to be given. Li Zhaoshun proposed an improved Zero Mean Normalized CrossCorrelation (ZNCC) algorithm. This algorithm is based on thread template features to match the image of the thread to be measured, thereby realizing the measurement of thread parameters. This algorithm requires a template with high precision, and different templates need to be established for different specifications. Yu Zhichao et al. rotated and corrected the thread image, obtained the mid-diameter point of the thread based on geometric relationships such as the projected area of the tooth profile region on the cross-section of the thread axis, and used the least squares method to fit the mid-diameter line. Finally, the pitch of the measured thread was obtained in combination with the tolerance principle. This method is prone to introducing error effects during the image rotation and correction process. Summary of the Invention
[0004] The technical problem to be solved by the present invention is the problem of insufficient adaptability of different specifications of templates and the need to establish templates for threads during the existing visual thread parameter measurement process.
[0005] The present invention solves the above technical problems through the following technical means:
[0006] A calculation method for thread size parameters based on cloth simulation specifically includes the following steps:
[0007] Step 1: For the original thread image, use the edge detection algorithm to obtain the thread contour points;
[0008] Step 2: The algorithm checks whether the contour points contain the pipe orifice and determines the gravity direction, and then performs the cloth simulation in the two gravity directions to separate the tooth bottom and the tooth top;
[0009] Step 3: Based on the tooth bottom and the tooth top found in Step 2, separate the individual teeth and establish the mathematical models of the tooth bottom and the tooth top respectively;
[0010] Step 4: The contour points of the tooth top and the tooth bottom are fitted according to the mathematical model to obtain the corresponding geometric feature points of each tooth;
[0011] Step 5: Obtain the thread dimension parameters between adjacent teeth according to the geometric feature points calculated in Step 4.
[0012] Furthermore, in Step 1, the canny edge detection algorithm is used to obtain the contour points in the thread image. First, Gaussian smoothing is used to remove the image noise points. Secondly, the solel operator is used to calculate the gradient and direction of the gray change in the image. Finally, non-maximum suppression and double-threshold algorithms are used to detect and connect the contours, where the resolution of the contour points is the resolution of the original image.
[0013] Furthermore, the specific process of Step 2 is as follows:
[0014] Step 2.1: Check the pipe orifice and determine the gravity direction: The original contour point data uses the least squares algorithm to find the contour line features, where the pipe orifice direction g m (0, wh max ) is perpendicular to the thread contour direction. Generally, there is only one direction for the contour points that do not contain the pipe orifice. For the contour points that contain the pipe orifice, the pipe orifice contour points need to be removed. In addition, the gravity direction g u (0, 0) and g d (0, wh max ) are also consistent with the pipe orifice direction; where g m is the pipe orifice direction, g u and g d are the cloth falling directions, and wh max is the maximum value of the image width and height;
[0015] Step 2.2: Construct the cloth and perform the tooth top simulation in the g u direction: After the thread contour is processed in Step 2.1, obtain the two-dimensional thread contour points. According to the X and Y coordinates of the contour data, construct a two-dimensional cloth that can cover the range of the contour points. The cloth is composed of mass points - springs, and its shape is approximately a grid, and the direction is consistent with the thread contour direction. The starting point and the ending point are p s (0, 0) and p s (whmax , 0); The particle moves freely along the direction of gravity and is affected by external and internal forces; According to Newton's second law:
[0016]
[0017] First of all, the fabric is subject to the gravity F g (x, t) at a specific time. According to the position of each particle in the 2D space and the gravitational acceleration, it is mainly reflected as:
[0018]
[0019] Among them, m is the mass of the particle, G is the gravity received by the particle, and Δt is the time step. Usually, given the time step and the initial position, the current position of the particle can be obtained;
[0020] In addition, in order to constrain the movement of the particles, springs are added between the particles to constrain the internal force. It is reflected that the force is transmitted through the spring between each pair of connected particles. By considering the neighborhood of each particle one by one, all the springs are traversed, and the height difference between the two particles forming this spring is compared; The spring force is calculated according to Hooke's law:
[0021]
[0022] F i (x, t) = ma i
[0023] Among them, k is the elastic coefficient of the spring, l is the current length of the spring, that is, the distance between the particles, l0 is the natural length of the spring, and x1 and x0 are the coordinates of the two connected particles; F i (x, t) and the mass m and acceleration a i The relationship between them is linear. The spring force will directly affect the acceleration of the particle, and thus further affect the speed and position of the particle:
[0024]
[0025] Among them, Δ t is the time step, is the speed of the particle after being affected by the spring force acceleration, a t is the acceleration under the combined action of adjacent particles. After the speed changes, the position is updated according to the speed;
[0026] Step 2.3 Collision of the fabric falling with the thread profile: According to Δ in Step 2.2 tGradually update the shape of the fabric to simulate the dynamic deformation effect of the fabric; during the falling process of the fabric, set the thread profile to block the falling of particles, add a judgment on whether the particles are fixed or movable, and finally calculate the distance from the profile point to the fabric, and the profile point less than the given threshold dist thr The profile point is the tooth apex;
[0027] Step 2.4 Change the fabric position and the gravity direction to perform the tooth bottom simulation in the g d direction: Construct a fabric grid with the same shape as g u The starting point and the ending point of the fabric are p s (0, wh max ) and p s (wh max , wh max ), and similarly, according to Δ in Step 2.2 t Gradually update the shape of the fabric in the g d direction, simulate the dynamic deformation of the fabric, and calculate the distance from the profile point to the fabric, and the profile point less than the given threshold dist thr is the tooth bottom point.
[0028] Furthermore, the specific process of Step 3 is as follows:
[0029] Establish a mathematical model for the tooth apex and tooth bottom profiles: After the thread profile points are divided into the tooth apex and tooth bottom, different mathematical models for the tooth apex and tooth bottom are established for different specifications of circular threads, trapezoidal threads or other types of threads; the tooth apex and tooth bottom of trapezoidal and serrated threads are straight line equations, and the tooth apex and tooth bottom of circular threads are curve equations. The following establishes a straight line equation and a quadratic polynomial:
[0030] ax + by + c = 0
[0031] P (x) = a0 + a1x + a2x 2
[0032] P (y) = b0 + b1y + b2y 2 .
[0033] Furthermore, the specific process of Step 4 is as follows:
[0034] Step 4.1 Fitting of the straight line equation for the tooth apex and tooth bottom profile points: Fit a straight line that is as close as possible to the given tooth apex or tooth bottom profile points, and it is necessary to minimize the sum of the squares of the perpendicular distances between the fitting points (x i , y i ) and the straight line ax + by + c = 0, that is:
[0035]
[0036] Add a constraint condition to set a 2 +b 2 = 1, and standardize a and b; minimize the above error function and transform it into matrix form; assume there are n data points P(X,Y) = (x1,y1), (x2,y2),…,(x n ,y n ), and define the matrix:
[0037]
[0038] Minimize the error function E(a,b,c) = ‖XC‖ 2 , that is, solve the linear equation system X T XC = 0, where X T is the transpose of matrix X, and C is the parameter vector (a,b,c) we need to solve;
[0039] Step 4.2 Fitting of the straight-line equation for the tooth tip and tooth root profile points: Assume there are m data points P(X,Y) = (x1,y1), (x2,y2),…,(x m ,y m ) participating in the fitting P (x) = a0 + a1x + a2x 2 , and write the mean square error between the fitting function and the data sequence as:
[0040]
[0041] According to the extreme value principle of multivariate functions, the minimum value of Q(a0,a1,a2) satisfies:
[0042]
[0043] Simplify to get:
[0044]
[0045] Establish the equation M·coeff = N; solve the equation through QR decomposition to obtain the coefficients coeff of the fitted parabola equation; the coefficient matrix coeff represents the parameters a0, a1, a2 in the quadratic equation P (x) = a0 + a1x + a2x 2 .
[0046] Furthermore, the specific process of step 5 is as follows:
[0047] Step 5.1 Pitch measurement: For the circular thread profile curve, select the extreme points in the parametric equation P (x) = a0 + a1x + a2x 2 between adjacent teeth as characteristic points, and calculate the distance between adjacent tooth tips as the pitch P r; For the trapezoidal thread, the adjacent tooth tops are straight lines l1 and l2, and the midpoints m1 and m2 of the straight lines l1 and l2 are selected as characteristic points to calculate the pitch P. t ;
[0048] Step 5.2 Tooth height measurement: k1(x1, y1) and k2(x2, y2) are the extreme points of the parametric equation P of the adjacent tooth bottom profile (x) = a0 + a1x + a2x 2 The tooth height h r The measurement method is the distance from the point p1(x0, y0) to the straight line k1k2:
[0049]
[0050] For the trapezoidal thread, n points P1, P2,..., P on the straight line l1: Ax + By + C = 0 n , and the average distance from the points on the straight line to l3: A'x + B'y + C' = 0 is the tooth height h t :
[0051]
[0052] The present invention also provides a visual measurement requirement for thread size parameters based on cloth simulation, including:
[0053] Thread profile acquisition module: For the original thread image, use the edge detection algorithm to obtain the thread profile points;
[0054] Tooth bottom and tooth top segmentation module: The algorithm searches whether the profile points contain the pipe orifice and determines the gravity direction, and performs cloth simulation in the double gravity directions to segment the tooth bottom and the tooth top;
[0055] Mathematical model construction module: Based on the tooth bottom and tooth top found by the tooth bottom and tooth top segmentation module, separate single teeth and establish mathematical models for the tooth bottom and the tooth top respectively;
[0056] Fitting module: The tooth top and tooth bottom profile points are fitted according to the mathematical model to obtain the corresponding geometric feature points of each tooth;
[0057] Calculation module: Obtain the thread size parameters between adjacent teeth according to the geometric feature points calculated by the fitting module.
[0058] Further, the specific process of the tooth bottom and tooth top segmentation module is as follows:
[0059] Step 2.1 Search for the pipe orifice and determine the gravity direction: The original profile point data uses the least square algorithm to search for the profile line features, where the pipe orifice direction g m (0, wh max) perpendicular to the thread profile direction, there is generally only one direction for the profile points that do not include the pipe orifice. For those including the pipe orifice, the profile points of the pipe orifice need to be removed. In addition, the gravitational direction g of the falling fabric u (0,0) and g d (0, wh max ) is also consistent with the pipe orifice direction; among them, g m is the pipe orifice direction, g u and g d is the falling direction of the fabric, wh max is the maximum value of the image width and height;
[0060] Step 2.2 Construct the fabric and perform the simulation of the tooth crest in the g u direction: After the thread profile is processed in Step 2.1, obtain the two-dimensional thread profile points. According to the X and Y coordinates of the profile data, construct a two-dimensional fabric that can cover the range of the profile points. The fabric is composed of particle-springs, and its shape is approximately a grid, with the direction consistent with the thread profile direction. The starting point and the ending point are p s (0,0) and p s (wh max ,0); The particles move freely in the gravitational direction and are affected by external forces and internal forces; According to Newton's second law:
[0061]
[0062] First of all, the fabric is subject to the gravitational force F g (x,t) at a specific time. According to the position of each particle in the 2D space and the gravitational acceleration, it is mainly reflected as:
[0063]
[0064] Among them, m is the mass of the particle, G is the gravitational force received by the particle, and Δt is the time step. Usually, given the time step and the initial position, the current position of the particle can be obtained;
[0065] In addition, in order to constrain the movement of the particles, springs are added between the particles for internal force constraint. It is reflected that the force is transmitted through the springs between each pair of connected particles. By considering the neighborhood of each particle one by one, traversing all the springs, and comparing the height difference between the two particles forming this spring; The spring force is calculated according to Hooke's law:
[0066]
[0067] Fi(x,t) = ma i
[0068] where k is the spring constant, l is the current length of the spring, i.e., the distance between the mass points, l0 is the natural length of the spring, x1 and x0 are the coordinates of two connected mass points; F i is linear between (x, t) and the mass m and acceleration a i The spring force directly affects the acceleration of the particles, which further affects the velocity and position of the particles:
[0069]
[0070] where Δ t is the time step, is the velocity of the particle after being affected by the spring force acceleration, a t is the acceleration under the combined action of adjacent particles. After the velocity changes, the position is updated according to the velocity;
[0071] Step 2.3 Collision of the falling fabric with the thread profile: According to Δ t in Step 2.2, gradually update the shape of the fabric to simulate the dynamic deformation effect of the fabric; during the falling process of the fabric, set the thread profile to block the falling of the particles, add a judgment on whether the particles are fixed or movable, and finally calculate the distance from the profile points to the fabric. The profile points less than the given threshold dist thr are the tooth apex points;
[0072] Step 2.4 Change the fabric position and the gravity direction, and perform the simulation of the tooth bottom under the g d direction: Construct a fabric grid with the same shape as g u . The starting point and the ending point of the fabric are p s (0, wh max ) and p s (wh max , wh max ). Similarly, according to Δ t in Step 2.2, gradually update the shape of the fabric under the g d direction to simulate the dynamic deformation of the fabric, and calculate the distance from the profile points to the fabric. The profile points less than the given threshold dist thr are the tooth bottom points.
[0073] Furthermore, the specific process of the fitting module is as follows:
[0074] Step 4.1 Fitting of the straight line equation of the tooth apex and tooth bottom profile points: Fit a straight line that is as close as possible to the given tooth apex or tooth bottom profile points. It is necessary to minimize the sum of the squares of the perpendicular distances between the fitting points (x i , y i ) and the straight line ax + by + c = 0, that is:
[0075]
[0076] Add a constraint condition and set a 2 +b 2 = 1, standardize a and b; minimize the above error function and transform it into matrix form; assume there are n data points P(X,Y) = (x1,y1), (x2,y2),…,(x n ,y n ), define the matrix:
[0077]
[0078] Minimize the error function E(a,b,c) = ‖XC‖ 2 , that is, solve the linear equation system X T XC = 0, where X T is the transpose of matrix X, and C is the parameter vector (a,b,c) we need to solve;
[0079] Step 4.2 Fitting of the straight line equation of the tooth tip and tooth bottom contour points: Assume there are m data points P(X,Y) = (x1,y1), (x2,y2),…,(x m ,y m ) participate in the fitting P (x) = a0 + a1x + a2x 2 , and the mean square error between the fitting function and the data sequence is written as:
[0080]
[0081] According to the extreme value principle of multivariate functions, the minimum value of Q(a0,a1,a2) satisfies:
[0082]
[0083] Simplify to get:
[0084]
[0085] Establish the equation M·coeff = N; solve the equation through QR decomposition to obtain the coefficients coeff of the fitted parabola equation; the coefficient matrix coeff represents the parameters a0, a1, a2 in the quadratic equation P (x) = a0 + a1x + a2x 2 .
[0086] Furthermore, the specific process of the calculation module is as follows:
[0087] Step 5.1 Pitch measurement: For the circular thread profile curve, select the parametric equation P (x) = a0 + a1x + a2x 2The extreme points in it are used as feature points, and the distance between adjacent tooth tops is calculated as the pitch P. r ; For trapezoidal threads, the adjacent tooth tops are straight lines l1 and l2. The midpoints m1 and m2 of the straight lines l1 and l2 are selected as feature points to calculate the pitch P. t ;
[0088] Step 5.2 Tooth height measurement: k1(x1, y1) and k2(x2, y2) are the parametric equations of the adjacent tooth bottom tooth profile P (x) = a0 + a1x + a2x 2 of the extreme points, and the tooth height h r The measurement method is the distance from the point p1(x0, y0) to the straight line k1k2:
[0089]
[0090] For trapezoidal threads, n points P1, P w , …, P n on the straight line l1: Ax + By + C = 0, and the average distance from the points on the straight line to l3: A′x + B′y + C′ = 0 is the tooth height h t :
[0091]
[0092] The advantages of the present invention are as follows:
[0093] Based on the original image of the thread, the present invention combines the image edge detection and graphics methods to perform the segmentation of the thread tooth top and tooth bottom. For the measurement of different thread parameters, the corresponding mathematical models are constructed and fitted, thus avoiding the process of establishing and matching standard templates in traditional thread measurement. This method not only simplifies the measurement steps, but also improves the response ability to the real surface of the thread and enhances the adaptability of machine vision in thread measurement. Description of the Drawings
[0094] Figure 1 is the flow block diagram of the measurement method in the embodiment of the present invention;
[0095] Figure 2 is the thread edge detection diagram in the embodiment of the present invention;
[0096] Figure 3 is the thread contour scatter diagram in the embodiment of the present invention;
[0097] Figure 4 is the segmentation diagram of the tooth top and tooth bottom of the original thread in the embodiment of the present invention;
[0098] Figure 5 is the schematic diagram of the thread parameter calculation method in the embodiment of the present invention. Detailed Embodiment
[0099] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts belong to the scope of protection of the present invention.
[0100] This embodiment provides a method for calculating the thread size parameters based on fabric simulation, including the following steps:
[0101] 1. A method for calculating the thread size parameters based on fabric simulation ( Figure 1 For the implementation flowchart), characterized in that it specifically includes the following steps:
[0102] Step 1: For the original thread image, use an edge detection algorithm to obtain the thread contour points;
[0103] Step 2: The algorithm checks whether the contour points contain the pipe orifice and determines the gravity direction, and then performs fabric simulation in the double gravity directions to separate the tooth bottom and the tooth top;
[0104] Step 3: Based on the tooth bottom and tooth top found in Step 2, separate individual teeth and establish mathematical models for the tooth bottom and the tooth top respectively;
[0105] Step 4: Fit the tooth top and tooth bottom contour points according to the mathematical models to obtain the corresponding geometric feature points of each tooth;
[0106] Step 5: Obtain the thread size parameters between adjacent teeth based on the geometric feature points calculated in Step 4.
[0107] In Step 1, for the original thread image, use an edge detection algorithm to obtain the thread contour points.
[0108] The high-precision acquisition of the thread contour is the basic step for parameter measurement, Figure 2 That is, the thread edge features shown in the original image, and the red ones are the thread contour points.
[0109] 2. According to the method for calculating the thread size parameters based on fabric simulation described in claim 1, characterized in that in Step 1, the canny edge detection algorithm is used to obtain the contour points in the thread image. First, Gaussian smoothing is used to remove the image noise points. Secondly, the solel operator is used to calculate the gradient and direction of the gray-scale change in the image. Finally, non-maximum suppression and double-threshold algorithms are used to detect and connect the contours, where the resolution of the contour points is the resolution of the original image.
[0110] Step 2: The algorithm searches for whether the contour points contain the pipe orifice and determines the gravity direction, conducts the cloth simulation in the two gravity directions, and divides the tooth bottom and tooth top.
[0111] The cloth simulation can accurately simulate the physical properties of the thread, thereby improving the measurement accuracy of the tooth top and tooth bottom and reducing the errors introduced by the traditional measurement method.
[0112] 3. A calculation method for thread size parameters based on cloth simulation according to claim 1, wherein the specific process of step 2 is as follows:
[0113] Step 2.1 Search for the pipe orifice and determine the gravity direction. The original contour point data uses the least squares algorithm to search for the contour line features, where the pipe orifice direction g m (0, wh max ) is perpendicular to the thread contour trend. There is generally only one direction for the contour points that do not contain the pipe orifice. For the contour points that contain the pipe orifice, the pipe orifice contour points need to be removed. In addition, the gravity direction g u (0, 0) of the falling cloth is the same as g d (0, wh max ). Among them, g m is the pipe orifice direction, g u and g d are the cloth falling directions, and wh max is the maximum value of the image width and height.
[0114] Step 2.2 Construct the cloth and conduct the tooth top simulation in the g u direction. After the thread contour is processed in step 2.1, obtain Figure 3 the two-dimensional thread contour points, and construct a two-dimensional cloth that can cover the range of the contour points according to the X and Y coordinates of the contour data. As shown in Figure 4 (a), the red points are the thread contour points, the green points are the constructed cloth, the cloth is composed of mass points - springs, the shape is approximately a grid, the direction is the same as the thread contour trend, and the starting point and the ending point are p s (0, 0) and p s (wh max , 0). The mass points move freely along the gravity direction and are affected by external forces (such as gravity, wind force, etc.) and internal forces (between mass points). According to Newton's second law:
[0115]
[0116] First of all, the cloth is affected by the gravity F g (x, t) at a specific time. According to the position of each particle in the 2D space, the gravity acceleration is mainly reflected as:
[0117]
[0118] Among them, m is the mass of the particle, G is the gravity acting on the particle, and Δt is the time step. Usually, given the time step and the initial position, the current position of the particle can be obtained.
[0119] In addition, in order to constrain the movement of the particles, springs are added between the particles to constrain the internal force. This is manifested as the force being transmitted between each pair of connected mass points through the spring. By considering the neighborhood of each particle one by one and traversing all the springs, the height difference between the two particles forming the spring is compared. The spring force is calculated according to Hooke's law:
[0120]
[0121] F i (x,t) = ma i
[0122] Among them, k is the spring constant, l is the current length of the spring, that is, the distance between the mass points, l0 is the natural length of the spring, and x1 and x0 are the coordinates of the two connected mass points. F i (x,t) has a linear relationship with the mass m and the acceleration a i and the spring force will directly affect the acceleration of the particle, thereby further affecting the speed and position of the particle:
[0123]
[0124] Among them, Δ t is the time step, is the speed of the particle after being affected by the spring force acceleration, a t is the acceleration under the combined action of adjacent particles. After the speed changes, the position is updated according to the speed.
[0125] Step 2.3 Collision of the falling cloth with the thread profile. According to Δ in Step 2.2 t gradually update the shape of the cloth to simulate the dynamic deformation effect of the cloth. As shown in Figure 4 (b), according to the given gravity direction, without adding collision conditions, the light green is the previous state position, and the green cloth points are updated to the new positions. During the falling process of the cloth, it is set that the thread profile blocks the falling of the particles, and a judgment of fixed or movable is added to the particles. Finally, the distance from the profile point to the cloth is calculated, and the profile point less than the given threshold dist thr is the tooth vertex. Figure 4 (c) shows the collision result of the cloth and the thread profile after adding collision conditions. The yellow points are the cloth points less than the given threshold dist thr after the cloth collides with the thread, and the part where the thread profile fits the cloth is the tooth vertex.
[0126] Step 2.4 Change the cloth position and the gravity direction, and perform the simulation of the tooth bottom under the g d direction. Construct a cloth starting point and an ending point that are consistent with the g u direction, and the starting and ending points of the cloth are p s (0, wh max ) and p s (wh max , wh max ). Similarly, according to Δ in Step 2.2 t gradually update the shape of the cloth, simulate the dynamic deformation of the cloth, and calculate the distance from the contour point to the cloth. The contour points less than the given threshold dist thr are the tooth bottom points. Figure 4 (d) shows the collision result after changing the cloth position and the gravity direction. The points that fit the cloth and are less than the dist thr threshold are the tooth bottom contour points.
[0127] Step 3. Based on the tooth bottom and tooth top found in Step 2, separate the individual teeth and establish the mathematical models of the tooth bottom and tooth top respectively.
[0128] Analyzing the tooth bottom and tooth top of the tooth separately can better extract the key feature points. In addition, for different types of tooth profiles, the model parameters can be flexibly adjusted to adapt to various thread specifications and application requirements.
[0129] 4. A calculation method for thread size parameters based on cloth simulation according to claim 1, wherein the specific process of step 3 is as follows:
[0130] Establish the mathematical models of the tooth top and tooth bottom contours. After the tooth top and tooth bottom are segmented from the thread contour points, different mathematical models of the tooth top and tooth bottom are established for different specifications of round threads, trapezoidal threads or other types of threads. The tooth top and tooth bottom of trapezoidal and serrated threads are generally linear equations, and the tooth top and tooth bottom of round threads are curve equations. The following linear equations and quadratic polynomials are established:
[0131] ax + by + c = 0
[0132] P (x) = a0 + a1x + a2x 2
[0133] P (y) = b0 + b1y + b2y 2
[0134] Step 4. Fit the tooth top and tooth bottom contour points according to the mathematical models to obtain the corresponding geometric feature points of each tooth.
[0135] Fitting the contour points can analyze the thread parameters more accurately and capture the errors in the thread process production.
[0136] 5. A calculation method for thread size parameters based on fabric simulation according to claim 1, wherein the specific process of step 4 is as follows:
[0137] Step 4.1 Fitting of the straight-line equation for the tooth tip and tooth root contour points. Fit a straight line that is as close as possible to the given tooth tip or tooth root contour points, and it is necessary to minimize the sum of the squares of the perpendicular distances between the fitting points (x i , y i ) and the straight line ax + by + c = 0, that is:
[0138]
[0139] Add a constraint condition, set a 2 + b 2 = 1 to standardize a and b. Minimize the above error function and transform it into matrix form. Suppose there are n data points P(X,Y) = (x1,y1), (x2,y2), …, (x n , y n ), and define the matrix:
[0140]
[0141] Minimize the error function E(a,b,c) = ‖XC‖ 2 , that is, solve the linear equation system X T XC = 0, where X T is the transpose of matrix X, and C is the parameter vector (a,b,c) we need to solve.
[0142] Step 4.2 Fitting of the straight-line equation for the tooth tip and tooth root contour points. Suppose there are m data points P(X,Y) = (x1,y1), (x2,y2), …, (x m , y m ) participating in the fitting P (x) = a0 + a1x + a2x 2 , and the mean square error between the fitting function and the data sequence is written as:
[0143]
[0144] According to the extreme value principle of multivariate functions, the minimum value of Q(a0,a1,a2) satisfies:
[0145]
[0146] Simplify to get:
[0147]
[0148] Establish the equation M·coeff = N. Solve the equation through QR decomposition to obtain the coefficients coeff of the fitted parabolic equation. The coefficient matrix coeff represents the parameters a0, a1, and a2 in the quadratic equation P (x) = a0 + a1x + a2x 2 .
[0149] Step 5. Obtain the thread size parameters between adjacent teeth based on the geometric feature points calculated in Step 4.
[0150] The geometric feature points provide a clear reference position, enabling accurate measurement of the size parameters between adjacent teeth. This high precision helps reduce measurement errors and improve the repeatability of measurements.
[0151] 6. A method for calculating thread size parameters based on cloth simulation according to claim 1, wherein the specific process of Step 5 is as follows:
[0152] Step 5.1 Pitch measurement. As Figure 5 shown, Figure 5 (a) For the circular thread profile curve, select the extreme points in the parametric equation P (x) = a0 + a1x + a2x 2 between adjacent teeth as feature points, Figure 5 the tooth tip extreme points in (a) are p1 and p2, and calculate the distance between adjacent tooth tips as the pitch P r ; similarly Figure 5 (b) For the trapezoidal thread, the adjacent tooth tips are the straight lines l1 and l2, and select the midpoints m1 and m2 of the straight lines l1 and l2 as feature points to calculate the pitch P t .
[0153] Step 5.2 Tooth height measurement. As Figure 5 shown, Figure 5 (a) k1(x1, y1) and k2(x2, y2) in are the extreme points of the parametric equation P (x) = a0 + a1x + a2x 2 of the adjacent tooth bottom profile, and the tooth height h r is measured as the distance from the point p1(x0, y0) to the straight line k1k2:
[0154]
[0155] For the trapezoidal thread, the average distance from n points P1, P2,..., P n on the straight line l1: Ax + By + C = 0 to the straight line l3: A'x + B'y + C' = 0 is the tooth height h t :
[0156]
[0157] In view of the problems existing in the existing visual thread parameter measurement process, namely the need to establish a template for the thread and the insufficient adaptability of templates for different specifications, this embodiment proposes an innovative solution based on computer graphics. This method focuses on the contours on both sides of the thread crest and thread root, and realizes the accurate detection of the thread crest and thread root through the two-way cloth simulation technology. On this basis, the present invention constructs respective mathematical curve models for different types of threads in order to extract the corresponding feature points. This process can not only achieve high-precision measurement of the pitch and tooth height of various threads, but also significantly improve the reliability of thread parameter measurement. In addition, this method provides a new idea for the adaptability of thread visual measurement and has reference value for the research and application in related fields. By introducing advanced computer graphics technology, the present invention improves the measurement accuracy while expanding the application scope of thread measurement technology.
[0158] The above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.
Claims
1. A method for calculating the thread size parameters based on cloth simulation, characterized in that, Specifically, it includes the following steps: Step 1: For the original thread image, use the edge detection algorithm to obtain the thread contour points; Step 2: The algorithm checks whether the contour points contain the pipe orifice and determines the gravity direction, and then performs cloth simulation in the double gravity directions to separate the tooth bottom and the tooth top; Step 3: Based on the tooth bottom and the tooth top found in Step 2, separate individual teeth and establish mathematical models for the tooth bottom and the tooth top respectively; Step 4: Fit the tooth top and tooth bottom contour points according to the mathematical model to obtain the corresponding geometric feature points of each tooth; Step 5: Obtain the thread dimension parameters between adjacent teeth based on the geometric feature points calculated in Step 4.
2. The calculation method of the thread size parameters based on fabric simulation according to claim 1, wherein In Step 1, the canny edge detection algorithm is used to obtain the contour points in the thread image. First, Gaussian smoothing is used to remove the image noise points. Secondly, the solel operator is used to calculate the gradient and direction of the gray change in the image. Finally, non-maximum suppression and double-threshold algorithms are used to detect and connect the contours, where the resolution of the contour points is the resolution of the original image.
3. The calculation method of the thread size parameters based on cloth simulation according to claim 1, characterized in that, The specific process of Step 2 is as follows: Step 2.1 Locate the pipe orifice and determine the gravity direction: The original contour point data uses the least squares algorithm to find the contour line features, where the pipe orifice direction g m (0, wh max ) is perpendicular to the thread contour direction. There is generally only one direction for the contour points that do not include the pipe orifice. For the contour points that include the pipe orifice, the pipe orifice contour points need to be removed. In addition, the gravity direction g u (0, 0) and g d (0, wh max ) are also in the same direction as the pipe orifice direction; where g m is the pipe orifice direction, g u and g d are the fabric falling directions, and wh max is the maximum value of the image width and height; Step 2.2 Construct the fabric and perform the tooth tip simulation in the g u After the thread profile is processed in Step 2.1, obtain the two-dimensional thread profile points. According to the X and Y coordinates of the profile data, construct a two-dimensional fabric that can cover the range of the profile points. The fabric is composed of mass points and springs, with a shape similar to a grid, and the direction is consistent with the thread profile trend. The starting point and the ending point are p s (0, 0) and p s (wh max , 0); The mass points move freely along the gravity direction and are affected by external forces and internal forces. According to Newton's second law: First, the fabric is subject to gravity F g (x,t) at a specific time, and according to the position of each particle in the 2D space, the gravitational acceleration is mainly reflected as follows: Where m is the mass of the particle, G is the gravity received by the particle, and Δt is the time step. Usually, given the time step and the initial position, the current position of the particle can be obtained; In addition, in order to constrain the movement of the particles, springs are added between the particles to constrain the internal force. The manifestation is that force is transmitted through the springs between each pair of connected mass points. By considering the neighborhood of each particle one by one and traversing all the springs, the height difference between the two particles forming this spring is compared; the spring force is calculated according to Hooke's law: F i (x,t) = ma i where k is the spring constant, l is the current length of the spring, which is the distance between the mass points, l0 is the natural length of the spring, and x1 and x0 are the coordinates of two connected mass points; F i (x, t) is linear with the mass m and the acceleration a i and the spring force directly affects the acceleration of the particle, which in turn further affects the velocity and position of the particle: Among them, Δ t is the time step, is the velocity of the particle after the influence of the spring force acceleration, a t is the acceleration under the combined action of adjacent particles. After the velocity changes, the position is updated according to the velocity; Step 2.3 Collision between the falling fabric and the thread profile: According to Δ in Step 2.2 t Gradually update the shape of the fabric to simulate the dynamic deformation effect of the fabric; during the falling process of the fabric, set the thread profile to block the falling of particles, add a judgment on whether the particles are fixed or movable, and finally calculate the distance from the profile points to the fabric. The profile points less than the given threshold dist thr are the tooth vertices; Step 2.4 Change the fabric position and the gravity direction, and conduct the simulation of the tooth bottom under the g d direction: Construct a fabric grid consistent with the g u shape. The starting point and the ending point of the fabric are p s (0, wh max ) and p s (wh max , wh max ). Similarly, according to Δ in Step 2.2 t gradually update the shape of the fabric under the g d direction, simulate the dynamic deformation of the fabric, and calculate the distance from the contour point to the fabric. The contour points with a distance less than the given threshold dist thr are the tooth bottom points.
4. The calculation method of the thread size parameters based on cloth simulation according to claim 1, characterized in that, The specific process of Step 3 is as follows: Establish the mathematical model of the tooth top and tooth bottom contour: After the tooth top and tooth bottom are segmented from the thread contour points, different mathematical models of the tooth top and tooth bottom are established for different specifications of round threads, trapezoidal threads or other types of threads; the tooth top and tooth bottom of trapezoidal and serrated threads are straight line equations, and the tooth top and tooth bottom of round threads are curve equations. The following establishes the straight line equation and the quadratic polynomial: ax + by + c = 0 P (x) = a0 + a1x + a2x 2 P (y) = b0 + b1y + b2y 2 .
5. The calculation method of the thread size parameters based on fabric simulation according to claim 4, wherein The specific process of Step 4 is as follows: Step 4.1 Fitting of the straight line equation for the tooth tip and tooth root profile points: Fit a straight line that is as close as possible to the given tooth tip or tooth root profile points, and it is necessary to minimize the sum of the squares of the perpendicular distances between the fitting points (x i , y i ) and the straight line ax + by + c = 0, that is: Add a constraint condition to set a 2 +b 2 = 1, standardize a and b; minimize the above error function and transform it into matrix form; assume there are n data points P(X,Y) = (x1,y1), (x2,y2),…,(x n ,y n ), define the matrix: Minimize the error function E(a, b, c) = ||XC|| 2 , that is, solve the linear equation system X T XC = 0, where X T is the transpose of matrix X, and C is the parameter vector (a, b, c) we want to solve for; Step 4.2 Fitting of the straight-line equations for the tooth tip and tooth root profile points: Suppose there are m data points P(X, Y) = (x1, y1), (x2, y2), …, (x m , y m ) participating in the fitting P (x) = a0 + a1x + a2x 2 , and the mean square error between the fitting function and the data sequence is written as: According to the extreme value principle of multivariate functions, the minimum value of Q(a0, a1, a2) satisfies: Simplify to get: Establish the equation \(M\cdot coeff = N\); solve the equation through QR decomposition to obtain the coefficients \(coeff\) of the fitted parabola equation; the coefficient matrix \(coeff\) represents the parameters \(a_0\), \(a_1\), \(a_2\) in the quadratic equation \(P\) (x) = \(a_0 + a_1x + a_2x\) 2 , where \(a_0\), \(a_1\), \(a_2\) are the parameters 6. The calculation method of the thread size parameters based on fabric simulation according to claim 1, characterized in that The specific process of Step 5 is as follows: Step 5.1 Pitch measurement: For the circular thread profile curve, select the extreme points in the parametric equation P (x) = a0 + a1x + a2x 2 as the feature points, and calculate the distance between adjacent tooth tops as the pitch P r ; For the trapezoidal thread, the adjacent tooth tops are the straight lines l1 and l2. Select the midpoints m1 and m2 of the straight lines l1 and l2 as the feature points to calculate the pitch P t ; Step 5.2 Tooth height measurement: k1(x1, y1) and k2(x2, y2) are the extreme points of the adjacent tooth bottom profile parametric equation P (x) = a0 + a1x + a2x 2 The tooth height h r The measurement method is the distance from the point p1(x0, y0) to the line k1k2: For trapezoidal threads, n points \(P_1, P_2, \cdots, P\) on the straight line \(l_1: Ax + By + C = 0\) n , and the average distance from the points on the straight line to \(l_3: A'x + B'y + C' = 0\) is the tooth height \(h\) t :
7. A calculation system for thread size parameters based on cloth simulation, characterized in that Including: Thread contour acquisition module: For the original thread image, use the edge detection algorithm to obtain the thread contour points; Tooth bottom and tooth top segmentation module: The algorithm checks whether the contour points contain the pipe orifice and determines the gravity direction, and then performs cloth simulation in the double gravity directions to separate the tooth bottom and the tooth top; Mathematical model construction module: Based on the tooth bottom and tooth top found by the tooth bottom and tooth top segmentation module, separate individual teeth and establish mathematical models for the tooth bottom and the tooth top respectively; Fitting module: Fit the tooth top and tooth bottom contour points according to the mathematical model to obtain the corresponding geometric feature points of each tooth; Calculation module: Obtain the thread dimension parameters between adjacent teeth based on the geometric feature points calculated by the fitting module.
8. The calculation system for thread size parameters based on fabric simulation according to claim 7, wherein The specific process of the tooth bottom and tooth top segmentation module is as follows: Step 2.1 Locate the pipe orifice and determine the gravity direction: The original contour point data uses the least squares algorithm to find the contour line feature, where the pipe orifice direction g m (0, wh max ) is perpendicular to the thread contour direction. There is generally only one direction for the contour points that do not include the pipe orifice. For the contour points that include the pipe orifice, the pipe orifice contour points need to be removed. In addition, the gravity direction g u (0, 0) and g d (0, wh max ) are also in the same direction as the pipe orifice direction; where g m is the pipe orifice direction, g u and g d is the fabric falling direction, wh max is the maximum value of the image width and height; Step 2.2 Construct the fabric and perform the tooth tip simulation in the g u After the thread profile is processed in Step 2.1, obtain the two-dimensional profile points of the thread. Construct a two-dimensional fabric that can cover the range of the profile points according to the X and Y coordinates of the profile data. The fabric is composed of mass points and springs, and its shape is approximately like a grid. The direction is consistent with the thread profile trend, and the starting point and the ending point are p s (0, 0) and p s (wh max , 0); The mass points move freely along the gravity direction and are affected by external forces and internal forces; According to Newton's second law: First, the fabric is subject to the gravitational force F g (x,t) at a specific time, and according to the position of each particle in the 2D space and the gravitational acceleration, it is mainly manifested as: Where m is the mass of the particle, G is the gravity received by the particle, and Δt is the time step. Usually, given the time step and the initial position, the current position of the particle can be obtained; In addition, in order to constrain the movement of particles, springs are added between particles to constrain the internal forces. Specifically, the force is transmitted between each pair of connected mass points through a spring. By considering the neighborhood of each particle one by one, all the springs are traversed, and the height difference between the two particles forming the spring is compared. The spring force is calculated according to Hooke's law: F i (x,t) = ma i where k is the spring constant, l is the current length of the spring, which is the distance between the particles, l0 is the natural length of the spring, and x1 and x0 are the coordinates of two connected particles; F i (x, t) is linear with the mass m and the acceleration a i The relationship between them is linear. The spring force directly affects the acceleration of the particle, which further affects the velocity and position of the particle: Among them, Δ t is the time step, is the velocity of the particle after the influence of the spring force acceleration, a t is the acceleration under the combined action of adjacent particles. After the velocity changes, the position is updated according to the velocity; Step 2.3 Collision of the fabric falling with the thread profile: According to Δ in Step 2.2 t Gradually update the shape of the fabric to simulate the dynamic deformation effect of the fabric; during the process of the fabric falling, set the thread profile to block the falling of particles, add a judgment on whether the particles are fixed or movable, and finally calculate the distance from the profile points to the fabric. The profile points smaller than the given threshold dist thr are the tooth vertices; Step 2.4 Change the fabric position and the gravity direction, and perform the simulation of the tooth bottom in the g d direction: Construct a fabric grid with the same shape as g u , where the starting point and the ending point of the fabric are p s (0, wh max ) and p s (wh max , wh max ). Similarly, according to Δ in Step 2.2 t , gradually update the shape of the fabric in the g d direction, simulate the dynamic deformation of the fabric, and calculate the distance from the contour point to the fabric. The contour points with a distance less than the given threshold dist thr are the tooth bottom points.
9. The calculation system for thread size parameters based on fabric simulation according to claim 7, characterized in that The specific process of the fitting module is as follows: Step 4.1 Fitting of the straight line equation for the tooth tip and tooth root profile points: Fit a straight line that is as close as possible to the given tooth tip or tooth root profile points, and it is necessary to minimize the sum of the squares of the perpendicular distances between the fitting points (x i , y i ) and the straight line ax + by + c = 0, that is: Add a constraint condition and set a 2 +b 2 = 1, standardize a and b; minimize the above error function and transform it into matrix form; assume there are n data points P(X,Y) = (x1,y1), (x2,y2), …, (x n ,y n ), define the matrix: Minimize the error function \(E(a, b, c)=\|XC\|\) 2 , that is, solve the linear equations \(X\) T \(XC = 0\), where \(X\) T is the transpose of matrix \(X\), and \(C\) is the parameter vector \((a, b, c)\) we want to solve for; Step 4.2 Fitting of the straight-line equations for the tooth tip and tooth root profile points: Suppose there are m data points P(X, Y) = (x1, y1), (x2, y2), …, (x m , y m ) participating in the fitting, and P (x) = a0 + a1x + a2x 2 , and the mean square error between the fitting function and the data sequence is written as: According to the extreme value principle of multivariate functions, the minimum value of Q(a0, a1, a2) satisfies: After simplification, we get: Establish the equation \(M\cdot coeff = N\); solve the equation by QR decomposition to obtain the coefficients \(coeff\) of the fitted parabola equation; the coefficient matrix \(coeff\) represents the parameters \(a0\), \(a1\), \(a2\) in the quadratic equation \(P\) (x) = \(a0 + a1x + a2x\) 2 , where \(a0\), \(a1\), \(a2\) are the parameters.
10. The calculation system for thread size parameters based on fabric simulation according to any one of claims 7 to 9, characterized in that, The specific process of the calculation module is as follows: Step 5.1 Pitch measurement: For the circular thread profile curve, select the extreme points in the parametric equation P (x) = a0 + a1x + a2x 2 as characteristic points, and calculate the distance between adjacent tooth tops as the pitch P r ; For the trapezoidal thread, the adjacent tooth tops are straight lines l1 and l2. Select the midpoints m1 and m2 of the straight lines l1 and l2 as characteristic points to calculate the pitch P t ; Step 5.2 Tooth height measurement: k1(x1, y1) and k2(x2, y2) are the extreme points of the adjacent tooth bottom profile parametric equation P (x) = a0 + a1x + a2x 2 The tooth height h r The measurement method is the distance from the point p1(x0, y0) to the straight line k1k2: For trapezoidal threads, n points \(P_1, P_2, \ldots, P\) on the straight line \(l_1: Ax + By + C = 0\) n The average distance from the points on the straight line to \(l_3: A'x + B'y + C' = 0\) is the tooth height \(h\) t :
Citation Information
Patent Citations
Visual detection method of pipe thread
CN105157611A