Curve fitting method and device and computer readable storage medium
By dividing the curve to be fit into multiple curve segments and fitting, and selecting the appropriate set of curve segments based on the error value, the universality problem of noise filtering in the industrial curve processing path is solved, high-precision curve fitting and interpolation are achieved, which improves processing yield and reduces sampling cost.
Patent Information
- Application Number
- CN202510214997.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-26
- Publication Date
- 2025-06-17
AI Technical Summary
There is a lack of a universal method in the prior art to effectively filter out noise in industrial curve processing paths, making it difficult to improve the accuracy of the processing paths in situations where high precision is required.
By interleaving and dividing the curves to be fit into multiple curve segments according to the preset window length, fitting each curve segment, and calculating the functional equation and error value of each curve segment, then selecting the appropriate set of curve segments from multiple curve segments based on this information to combine to generate the final curve.
A curve fitting method for segmented quadratic superposition correction is realized, which can not only effectively eliminate noise in the processing trajectory, but also perform interpolation, improve processing yield and reduce sampling cost.
Smart Images

Figure CN120162533A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of visual detection, and particularly to a curve fitting method, device, and computer-readable storage medium. Background Art
[0002] In existing industrial scenarios, it is a common situation to obtain a processing path through sampling by various sensors. However, any sensor will introduce noise. In occasions with high-precision requirements, it is usually necessary to filter out the noise in the processing trajectory. In addition, most of the points obtained by the sensor are discrete. Therefore, it is also necessary to complete the processing path by interpolation. Both of the above situations involve curve fitting.
[0003] Currently, the commonly used cubic spline fitting is suitable for the interpolation of most curves, but this solution cannot solve the noise problem. And the smoothing spline is overly dependent on parameter selection, so it does not have universality. The same problem also exists in ordinary polynomial fitting. For example, a quartic polynomial can only handle curves in the shape of a straw hat. Based on this, a common practice in the industry is to adopt specific fitting methods for different scenarios to solve problems. For example, if the known processing path is a circle, then circular fitting is directly adopted. And the method of filtering can solve part of the high-frequency noise, but this method is only applicable to certain specific scenarios.
[0004] In summary, there is currently no universal method for effectively filtering noise in the industrial curve processing path. In order to improve the accuracy, only the stability of sampling can be improved, but this may greatly increase the cost. And in some scenarios, the stability of sampling is also difficult to be effectively improved. Summary of the Invention
[0005] In order to overcome the deficiencies in the prior art, the purpose of the present invention is to provide a curve fitting method, device, and computer-readable storage medium to solve the problem that there is currently no universal method for effectively filtering noise in the industrial curve processing path.
[0006] The present invention proposes a curve fitting method, which includes:
[0007] Interleaving and dividing the curve to be fitted into multiple curve segments according to a preset window length, where the first points of two adjacent curve segments are adjacent;
[0008] Fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments;
[0009] Selecting a set of curve segments from the multiple curve segments according to the function equation and the error value to combine and generate the final curve.
[0010] Optionally, assume that the curve to be fitted consists of k data points, and the window length is n, where n < k. Interleaving and dividing the curve to be fitted into multiple curve segments according to the preset window length specifically includes:
[0011] Determine the k data points as a point sequence with a length of k;
[0012] Interleavingly divide the point sequence into m curve segments, where m = k - n + 1.
[0013] Optionally, fitting each of the curve segments, calculating the function equation and the error value of each of the curve segments specifically includes:
[0014] For each of the curve segments, take the first point p1 and the nth point pn. Among them, the coordinates of point p1 are denoted as <x1, y1>, and the coordinates of point pn are denoted as <xn, yn>;
[0015] Compare and calculate point p1 and point pn. Among them, if fabs(xn - x1) < fabs(yn - y1), then exchange the values of x and y to make the x - direction span of the fitting function greater than the y - direction span.
[0016] Optionally, fitting each of the curve segments, calculating the function equation and the error value of each of the curve segments further includes:
[0017] Assume that the curve formula of the least - squares method for quadratic fitting is y = a·x 2 + b·x + c;
[0018] Solve the parameter equation To obtain the function equation.
[0019] Optionally, fitting each of the curve segments, calculating the function equation and the error value of each of the curve segments further includes:
[0020] According to the formula Calculate the error value of each of the curve segments. Among them, if the point sequence from x1 to xn of the curve segment is not a monotonic sequence, then set the error value of the curve segment to infinity.
[0021] Optionally, denote the m curve segments as curve segment f1 to curve segment fm. Selecting a set of curve segments from the multiple curve segments according to the function equation and the error value to combine and generate the final curve specifically includes:
[0022] Select curve segment f1, and set q = 1, that is, f1 is fq;
[0023] From the next curve segment fq+1 of the curve segment fq to the curve fq+n-1 starting from the penultimate point of fq, select the curve segment with the smallest error value and add it to the set;
[0024] Set q as the serial number of the newly selected curve segment;
[0025] Repeat the selection operation until the selected curve segment contains the last data point to obtain the set composed of the selected curve segments.
[0026] Optionally, the step of selecting a set composed of a group of curve segments from multiple curve segments according to the function equation and the error value to combine and generate the final curve further includes:
[0027] For each data point among the k data points, determine the curve segment in the set that contains the data point;
[0028] If there is only one curve segment that contains the data point, use the projection of the data point on the curve segment as the data point of the final curve;
[0029] If there are multiple curve segments that contain the data point, use the projections of the data point on the multiple curve segments as candidate points, and calculate the weighted average position in combination with the candidate points to use as the data point of the final curve.
[0030] Optionally, the step of calculating the weighted average position in combination with the candidate points to use as the data point of the final curve specifically includes:
[0031] Calculate the central offset distance s of the data point on each curve segment. Where, assuming the data point is the jth point of the curve segment, then s = abs((x1 + xn) / 2 – xj);
[0032] Calculate the weight value t = s / (Σs), where Σs is the sum of the central offset distances s of all the curve segments calculated;
[0033] Assume the candidate coordinates of each candidate point are <xi, yi>, and the corresponding weight value is ti, then the coordinates of the data point of the final curve are <x, y>, where: x = Σ(xi * ti), y = Σ(yi * ti).
[0034] The present invention also provides a curve fitting device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the curve fitting method described in any one of the above are implemented.
[0035] The present invention also provides a computer-readable storage medium, on which a curve fitting program is stored. When the curve fitting program is executed by a processor, the steps of the curve fitting method described in any one of the above are implemented.
[0036] Implementing the curve fitting method, device and computer-readable storage medium of the present invention, by staggeredly dividing the curve to be fitted into multiple curve segments according to a preset window length, wherein the first points of two adjacent curve segments are adjacent; fitting each of the curve segments, calculating the function equation and error value of each of the curve segments; selecting a set of curve segments from the multiple curve segments according to the function equation and the error value to combine and generate the final curve. A curve fitting method of piecewise quadratic superposition correction is realized, which can fit any curve, effectively eliminate the noise in the processing trajectory, and can also perform interpolation, improve the processing yield rate and reduce the sampling cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The present invention will be further described below in conjunction with the drawings and embodiments. In the drawings:
[0038] Figure 1 is the first flowchart of the curve fitting method of the present invention;
[0039] Figure 2 is the second flowchart of the curve fitting method of the present invention;
[0040] Figure 3 is the third flowchart of the curve fitting method of the present invention;
[0041] Figure 4 is the fourth flowchart of the curve fitting method of the present invention;
[0042] Figure 5 is the fifth flowchart of the curve fitting method of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0043] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0044] In the following description, suffixes such as "module", "component" or "unit" used to represent elements are only for the convenience of describing the present invention, and they have no specific meaning in themselves. Therefore, "module", "component" or "unit" can be used interchangeably.
[0045] Figure 1 is the first flowchart of the curve fitting method of the present invention. This embodiment provides a curve fitting method, which includes:
[0046] S1. Interleave and segment the curve to be fitted into multiple curve segments according to a preset window length, where the first points of two adjacent curve segments are adjacent;
[0047] S2. Fit each of the curve segments, and calculate the function equation and error value of each curve segment;
[0048] S3. Select a set of curve segments from the multiple curve segments according to the function equation and the error value to combine and generate the final curve.
[0049] In this embodiment, first, the curve to be fitted is interleaved and segmented into multiple curve segments according to a preset window length, where the first points of two adjacent curve segments are adjacent. In this way, the specific segmentation method of the data points is determined, so that the data points of each segment are suitable for fitting with a quadratic function, and it is ensured that the curves fitted for these segments can form the final complete curve. Based on this, in this embodiment, each of the curve segments is then fitted, and the function equation and error value of each curve segment are calculated; finally, a set of curve segments is selected from the multiple curve segments according to the function equation and the error value to combine and generate the final curve.
[0050] The beneficial effect of this embodiment is that by interleaving and segmenting the curve to be fitted into multiple curve segments according to a preset window length, where the first points of two adjacent curve segments are adjacent; fitting each of the curve segments and calculating the function equation and error value of each curve segment; selecting a set of curve segments from the multiple curve segments according to the function equation and the error value to combine and generate the final curve. A curve fitting method of segmented quadratic superposition correction is realized, which can fit any curve, effectively eliminate the noise in the machining trajectory, and can also perform interpolation, improve the machining yield, and reduce the sampling cost.
[0051] Figure 2 This is the second flowchart of the curve fitting method of the present invention. Based on the above embodiment, in this embodiment, it is assumed that the curve to be fitted is composed of k data points, and the window length is n, where n < k. The step of interleaving and segmenting the curve to be fitted into multiple curve segments according to a preset window length specifically includes:
[0052] S11. Determine the k data points as a point sequence with a length of k;
[0053] S12. Interleave and segment the point sequence into m curve segments, where m = k - n + 1.
[0054] In this embodiment, for any curve to be fitted, it consists of k data points. Optionally, according to the actual accuracy or efficiency requirements, a window length n (n < k) is set. Based on this parameter n, the segmentation method is to stagger and segment the point sequence of length k into m = k - n + 1 curve segments. Among them, the first points of two adjacent curve segments are adjacent, and the length of this curve segment is k.
[0055] The beneficial effect of this embodiment is that by determining k data points as a point sequence of length k, and then staggering and segmenting the point sequence into m curve segments, where m = k - n + 1, it realizes setting the window length according to the actual accuracy or efficiency requirements, and provides a data basis for the subsequent fitting of curve segments through the above-mentioned staggered segmentation method.
[0056] Figure 3 It is the third flowchart of the curve fitting method of the present invention. Based on the above embodiment, in this embodiment, fitting each of the curve segments and calculating the function equation and error value of each curve segment specifically include:
[0057] S21. For each curve segment, take the first point p1 and the nth point pn. Among them, the coordinates of point p1 are denoted as <x1, y1>, and the coordinates of point pn are denoted as <xn, yn>.
[0058] S22. Compare and calculate points p1 and pn. Among them, if fabs(xn - x1) < fabs(yn - y1), then exchange the values of x and y to make the x-direction span of the fitting function greater than the y-direction span.
[0059] In this embodiment, perform quadratic least-squares fitting on the above m curve segments to obtain m curve segments, and record the error estimation of each curve segment. Specifically: for each curve segment, take the coordinates of the first point p1 and the nth point pn, that is, <x1, y1> and <xn, yn>, and perform comparison calculations. Among them, if fabs(xn - x1) < fabs(yn - y1), then exchange the values of x and y in the subsequent calculations, so that the x-direction span of the fitting function is greater than the y-direction span.
[0060] In this embodiment, fitting each of the curve segments and calculating the function equation and error value of each curve segment further include:
[0061] Let the curve formula of the quadratic least-squares method be y = a·x 2 +b·x + c;
[0062] Solve the parameter equation to obtain the function equation.
[0063] In this embodiment, the above-mentioned curve segment is defined as the curve segment from p1 to pn, and the extended parts on both sides of the curve segment are invalid.
[0064] Optionally, the fitting of each of the curve segments to calculate the function equation and error value of each of the curve segments further includes:
[0065] According to the formula Calculate the error value of each of the curve segments. Wherein, if the point sequence x1 to xn of the curve segment is not a monotonic sequence, the error value of the curve segment is set to infinity.
[0066] In this embodiment, a group of curve segments is selected from the above-mentioned m curve segments for combined generation of the final curve. Specifically, the selection conditions in this embodiment include three aspects: First, the error is the smallest within the optional range; Second, after the selection, each data point is included in at least one curve segment; Third, the head and tail two points of each function are included in at least two curves. It should be noted that if the third curve segment at the head or tail of the entire curve segment set cannot meet the above selection conditions, it can be an exception. Among them, the m curve segments are denoted as curve segment f1 to curve segment fm. The selection of a set of curve segments from the multiple curve segments according to the function equation and the error value for combined generation of the final curve specifically includes: Select curve segment f1, and set q = 1, that is, f1 is fq; From the next curve segment fq+1 of curve segment fq to the curve fq+n-1 starting from the penultimate point of fq, select the curve segment with the smallest error value and add it to the set; Set q to the serial number of the newly selected curve segment; Repeat the selection operation until the selected curve segments include the last data point to obtain the set composed of the selected curve segments.
[0067] The beneficial effect of this embodiment is that by fitting each of the curve segments to calculate the function equation and error value of each of the curve segments, and further combining the above function equation and error value, a group of curve segments is selected from all the curve segments and forms a set, providing an effective projection curve segment for subsequent combined generation of the final curve.
[0068] Figure 4 This is the fourth flowchart of the curve fitting method of the present invention. Based on the above embodiment, in this embodiment, the selection of a set of curve segments from the multiple curve segments according to the function equation and the error value for combined generation of the final curve further includes:
[0069] S31. For each of the k data points, determine the curve segment in the set that contains the data point;
[0070] S32. If there is only one such curve segment that contains the data point, then use the projection of the data point on the curve segment as the data point of the final curve.
[0071] S33. If there are multiple such curve segments that contain the data point, then use the projections of the data point on the multiple curve segments as candidate points, and calculate the weighted average position in combination with the candidate points to be used as the data point of the final curve.
[0072] In this embodiment, according to the selected set of curve segments, a final complete curve is combined. Specifically: for each data point, find the curve segments in the set of curve segments that contain this point. If there is only one curve segment, then the projection of this point on the curve segment is the data point of the final curve. If multiple curve segments contain this data point, then first find the projections of the data point on all candidate curve segments as candidate points, and then calculate the weighted average position of these candidate points as the data point of the final curve segment.
[0073] The beneficial effect of this embodiment is that by determining the number of curve segments that contain the data point and determining the corresponding data point mapping scheme based on different numbers, the position of the data point for generating the final curve is made more accurate and effective.
[0074] Figure 5 This is the fifth flowchart of the curve fitting method of the present invention. Based on the above embodiment, in this embodiment, the calculating the weighted average position in combination with the candidate points to be used as the data point of the final curve specifically includes:
[0075] S331. Calculate the central offset distance s of the data point on each curve segment. Wherein, assume the data point is the j-th point of the curve segment, then s = abs((x1 + xn) / 2 - xj).
[0076] S332. Calculate the weight value t = s / (Σs), where Σs is the sum of the central offset distances s of all the curve segments calculated.
[0077] S333. Assume the candidate coordinates of each candidate point are <xi, yi>, and the corresponding weight value is ti, then the coordinates of the data point of the final curve are <x, y>, where: x = Σ(xi * ti), y = Σ(yi * ti).
[0078] In this embodiment, first, calculate the central offset distance of the current data point on each curve segment. Assume that this point is the j-th point of the curve segment, then the central offset distance s = abs((x1 + xn) / 2 – xj); then, calculate the weight t = s / (Σs), where Σs represents the sum of the central offset distances calculated for all the above candidate curve segments; finally, calculate the coordinates of the data points on the final curve. Specifically: Assume the number of candidate points is p, each candidate coordinate is <xi, yi>, and the corresponding weight is ti, then the data point coordinate is <x, y>, where: x = Σ(xi * ti), y = Σ(yi * ti). Thus, the combination can be determined as the final complete curve.
[0079] The beneficial effect of this embodiment is that when it is determined that there are multiple curve segments containing the data point, the projections of the data point on multiple curve segments are used as candidate points, and the weighted average position is calculated in combination with the candidate points to be used as the data points on the final curve, thereby further improving the position of the data points on the generated final curve.
[0080] Based on the above embodiment, the present invention also proposes a curve fitting device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the curve fitting method described in any one of the above.
[0081] It should be noted that the above device embodiment and the method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the device embodiment, so they will not be elaborated here.
[0082] Based on the above embodiment, the present invention also proposes a computer-readable storage medium, on which a curve fitting program is stored. When the curve fitting program is executed by a processor, it implements the steps of the curve fitting method described in any one of the above.
[0083] It should be noted that the above medium embodiment and the method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are correspondingly applicable in the medium embodiment, so they will not be elaborated here.
[0084] Implementing the curve fitting method, device and computer-readable storage medium of the present invention, the curve to be fitted is staggered and segmented into multiple curve segments according to a preset window length, wherein the first points of two adjacent curve segments are adjacent; fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments; selecting a set of curve segments from the multiple curve segments according to the function equation and the error value, so as to combine and generate the final curve. A curve fitting method with piecewise quadratic superposition correction is realized, which can fit any curve, effectively eliminate the noise in the machining trajectory, and perform interpolation, improving the machining yield and reducing the sampling cost.
[0085] Through the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. The computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0086] It should be noted that in this article, the term "including", "comprising" or any other variant thereof is intended to cover a non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such a process, method, article or device. Without further limitation, an element defined by the statement "including a..." does not exclude the existence of another identical element in the process, method, article or device including that element.
[0087] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit and scope protected by the present invention and the claims. All of these fall within the protection scope of the present invention.
Claims
1. A curve fitting method, characterized in that: The method includes: Interleaving and dividing the curve to be fitted into multiple curve segments according to a preset window length, where the first points of two adjacent curve segments are adjacent; Fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments; Selecting a set of curve segments from the multiple curve segments according to the function equation and the error value, for combining and generating the final curve.
2. The curve fitting method according to claim 1, characterized in that: Assume that the curve to be fitted consists of k data points, and the window length is n, where n < k. The interleaving and dividing the curve to be fitted into multiple curve segments according to the preset window length specifically includes: Determining the k data points as a point sequence with a length of k; Interleaving and dividing the point sequence into m curve segments, where m = k - n + 1.
3. The curve fitting method according to claim 2, characterized in that: The fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments specifically includes: For each of the curve segments, taking the first point p1 and the nth point pn, where the coordinates of point p1 are denoted as <x1, y1>, and the coordinates of point pn are denoted as <xn, yn>; Comparatively calculating point p1 and point pn, where if fabs(xn - x1) < fabs(yn - y1), then exchanging the values of x and y to make the x-direction span of the fitting function greater than the y-direction span.
4. The curve fitting method according to claim 3, characterized in that: The fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments further includes: Suppose the least squares curve formula of quadratic fitting is y = a·x 2 +b·x+c; Solving parametric equations The function equation is obtained.
5. The curve fitting method according to claim 4, characterized in that: The fitting each of the curve segments, and calculating the function equation and error value of each of the curve segments further includes: By formula The error value of each curve segment is calculated, wherein if the point sequence x1 to xn of the curve segment is not a monotonic sequence, the error value of the curve segment is set to be infinite.
6. The curve fitting method according to claim 2, characterized in that: Denoting the m curve segments as curve segment f1 to curve segment fm. The selecting a set of curve segments from the multiple curve segments according to the function equation and the error value, for combining and generating the final curve specifically includes: Selecting curve segment f1, and setting q = 1, that is, f1 is fq; Selecting the curve segment with the minimum error value from the next curve segment fq + 1 of curve segment fq to the curve fq + n - 1 starting from the penultimate point of fq, and adding it to the set; Setting q as the serial number of the newly selected curve segment; Repeating the selection operation until the selected curve segments contain the last data point, to obtain the set composed of the selected curve segments.
7. The curve fitting method according to claim 6, characterized in that: The selecting a set of curve segments from the multiple curve segments according to the function equation and the error value, for combining and generating the final curve further includes: For each of the k data points, determining the curve segment in the set that contains the data point; If there is only one curve segment that contains the data point, then taking the projection of the data point on the curve segment as the data point of the final curve; If there are multiple curve segments that contain the data point, then taking the projections of the data point on the multiple curve segments as candidate points, and calculating the weighted average position in combination with the candidate points, to be used as the data point of the final curve.
8. The curve fitting method according to claim 7, characterized in that: The calculating the weighted average position in combination with the candidate points, to be used as the data point of the final curve specifically includes: Calculate the center offset distance s of the data point on each curve segment, wherein, assuming that the data point is the jth point of the curve segment, then s=abs((x1+xn) / 2–xj); A weight value t=s / (Σs) is calculated, wherein Σs is the calculated sum of the center offset distances s of all the curve segments; Let the candidate coordinates of each candidate point be<xi,yi> , the corresponding weight is ti, then the coordinates of the data points of the final curve are<x,y> , where: x=Σ(xi*ti), y==Σ(yi*ti).
9. A curve fitting device, characterized in that: The device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the computer program implements the steps of the curve fitting method according to any one of claims 1 to 8 when executed by the processor.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a curve fitting program, and when the curve fitting program is executed by the processor, the steps of the curve fitting method according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Method and device for resolving silk-screen printing path of convex-surface special-shaped bottle body
CN122232311A
Method and device for calculating screen printing path of convex irregular bottle body
CN122232311B