Constraint-based 3D straight line fitting method
Through the combined method of RANSAC algorithm and least squares fitting, the error problem caused by external points in three-dimensional linear fitting is solved, high-precision linear fitting and reduced operation complexity are achieved, and application requirements under constraints are met.
Patent Information
- Application Number
- CN202210246943.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-14
- Publication Date
- 2025-08-29
- Estimated Expiration
- 2042-03-14
AI Technical Summary
The existing technology has external points in three-dimensional linear fitting, which leads to errors in fitting linear parameters, which cannot meet the application requirements under constraints.
The RANSAC-based random iteration method is used to determine the suboptimal straight line, and the external point interference is removed through least squares fitting, combined with plane projection, the operation complexity is reduced, and high-precision spatially fitted straight line parameters are obtained.
The accuracy of three-dimensional linear fitting is improved, the impact of extraneous points on the fitting results is reduced, the operation complexity is reduced, and the application needs are met under constraints.
Smart Images

Figure CN114638955B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of 3D vision, and in particular to a constraint-based three-dimensional straight line fitting method. Background Art
[0002] In 3D vision inspection and measurement projects, it is usually necessary to perform straight line shape detection and straightness measurement on the workpiece contour, which requires three-dimensional straight line fitting of the workpiece surface contour point cloud data.
[0003] At present, the surface contour point cloud data of the workpiece is collected by the sensor, and the contour point cloud data is fitted with a three-dimensional straight line through the least square method to obtain the fitting line and its parameters; when there are outliers in the fitting contour point cloud data, such as Figure 1 As shown, when the linear fitting is performed based on the least squares, the obtained fitting straight line 10 is consistent with the contour point cloud data ( Figure 1 There are deviations in the mid-contour point cloud data (there are outliers).
[0004] However, in some detection or measurement project applications, it is necessary to fit a straight line and its parameters under constraints. The fitting straight line and its parameters obtained by the above method have errors and do not meet the application requirements of the scene. Summary of the Invention
[0005] This application provides a constraint-based three-dimensional straight line fitting method to solve the technical problem that the current fitted straight line has errors and does not meet the requirements of scene applications.
[0006] In order to achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0007] The present application provides a constraint-based three-dimensional straight line fitting method, which includes the following steps:
[0008] Determine the point cloud data to be fitted;
[0009] The point cloud data to be fitted is used to determine a spatial fitting line and parameters of the spatial fitting line by a preset fitting method, wherein the preset fitting method includes fitting with outliers and least squares fitting;
[0010] The spatial fitting line is projected onto a preset plane to obtain a plane fitting line and parameters of the plane fitting line, wherein the second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the spatial fitting line.
[0011] In one implementable manner, the point cloud data to be fitted is extracted from point cloud data of the object to be measured according to preset index requirements, the point cloud data includes index information and data information, and the preset index requirements are composed of index information.
[0012] In one implementable manner, when the preset fitting method is fitting with outliers, determining the spatial fitting straight line includes:
[0013] The point cloud data to be fitted is used to determine a suboptimal straight line based on random iteration of RANSAC;
[0014] A spatial fitting straight line is determined based on the suboptimal straight line.
[0015] In one possible implementation, the point cloud data to be fitted is used to determine a suboptimal line based on random iteration of RANSAC, including:
[0016] Get the total number of iterations;
[0017] Obtain the current line and its number of inliers for each iteration, where the current line is fitted by randomly selecting two points from the point cloud data to be fitted, and the number of inliers is the number of points whose distance to the current line is within a preset distance threshold;
[0018] Determining the maximum number of iterations for each iteration according to the inlier point ratio of the current straight line, wherein the inlier point ratio is the ratio of the number of inlier points to the total number of points in the point cloud data to be fitted;
[0019] When the maximum number of iterations is less than the total number of iterations, the corresponding current straight line is determined to be a suboptimal straight line.
[0020] In one possible implementation, determining the maximum number of iterations for each iteration includes:
[0021] Obtain the interior point ratio, which is calculated according to the following formula:
[0022]
[0023] Where t is the ratio of inliers, M is the number of inliers of the current line, and N is the total number of points in the point cloud data to be fitted;
[0024] The confidence level is obtained by calculating the confidence level according to the following formula:
[0025] P=1-(1-t 2 ) k
[0026] Where P is the confidence level, k is the maximum number of iterations of the current inlier ratio;
[0027] The above formula is transformed to obtain the maximum number of iterations:
[0028]
[0029] In one possible implementation, the point cloud data to be fitted is used to determine a suboptimal line based on random iteration of RANSAC, further comprising:
[0030] When the maximum number of iterations is not less than the total number of each iteration, continue iterating.
[0031] In one achievable manner, the determination of the suboptimal straight line includes:
[0032] Sampling the point cloud data to be fitted according to index step sampling and / or random sampling to obtain sampled point cloud data;
[0033] The sampling point cloud data is used to determine a suboptimal straight line based on random iteration of RANSAC.
[0034] In one possible implementation, determining the spatial fitting straight line includes:
[0035] determining a first inlier point according to the suboptimal straight line and a preset distance threshold;
[0036] The first interior point is fitted with a middle straight line according to least squares, and the middle straight line and a preset distance are used to determine the second interior point;
[0037] When the number of adjacent inner points no longer increases, the corresponding middle straight line is the spatial fitting line.
[0038] In one implementable manner, the second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the space fitting line, including:
[0039] The plane fitting straight line and the space fitting straight line determine a construction plane;
[0040] A second RMS and a second offset among the parameters of the plane fitting line are determined, where the second offset and the second RMS are equivalent to a third offset and a third RMS of the point cloud with respect to the construction plane.
[0041] In one implementation, the parameters of the spatial fitting line include a first direction vector, a first position point, a first inner point index, a first number of inner points, a first RMS and a first offset; the parameters of the plane fitting line include a second direction vector, a second position point, a second inner point index, a second number of inner points, a second RMS and a second offset.
[0042] As can be seen from the above technical solution, the present application provides a constraint-based three-dimensional straight line fitting method, which includes determining point cloud data to be fitted; determining a spatial fitting line and the parameters of the spatial fitting line using a preset fitting method for the point cloud data to be fitted, wherein the preset fitting method includes fitting with outliers and least squares fitting; projecting the spatial fitting line onto a preset plane to obtain a plane fitting line and the parameters of the plane fitting line, wherein the second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the spatial fitting line. The present application overcomes the interference of outliers on straight line fitting through the preset fitting method, improves the accuracy of straight line fitting, and reduces the complexity of point cloud projection operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0044] Figure 1 This is a schematic diagram of straight line fitting when there are outliers in the prior art of this application;
[0045] Figure 2 This is a flowchart of a constraint-based three-dimensional straight line fitting method according to an embodiment of the present application;
[0046] Figure 3 The preset fitting method in the embodiment of the present application is a flow chart for determining a spatial fitting line when fitting with outliers;
[0047] Figure 4 This is a schematic diagram of constructing a straight line by randomly selecting two points in the point cloud data to be fitted based on RANSAC in an embodiment of the present application;
[0048] Figure 5 A schematic diagram of determining a suboptimal straight line according to an embodiment of the present application;
[0049] Figure 6 A schematic diagram of determining a spatial fitting straight line in an embodiment of the present application;
[0050] Figure 7 for Figure 1 Schematic diagram of a straight line fitted using the method of fitting with outliers in this application;
[0051] Figure 8 A schematic diagram of a straight line fitting of a preset plane projection = in an embodiment of the present application;
[0052] Figure 9 for Figure 8 A top view of
[0053] Among them: 10 - fitting line with outliers; 20 - fitting line without outliers; 30 - point cloud data to be fitted; 31 - interior point; 32 - exterior point; 33 - suboptimal line; 34, 41 - spatial fitting line; 42 - plane fitting line; 43 - projection plane; 44 - construction plane. DETAILED DESCRIPTION
[0054] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in 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 this application.
[0055] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0056] Currently, 3D line fitting is usually performed on a global point cloud. When outliers exist in the fitting data, errors occur in the parameters of the fitted 3D line. This increases the error in 3D line fitting under constraints and prevents fast calculation of the root mean square (RMS) and offset. This leads to errors in subsequent fitted line applications such as shape detection and straightness measurement.
[0057] Therefore, in order to solve the above problems, the present invention provides a constraint-based three-dimensional straight line fitting method, such as Figure 2 As shown, the method includes the following steps:
[0058] S101: Determine point cloud data to be fitted.
[0059] The point cloud data to be fitted is extracted from the point cloud data of the object to be measured according to preset index requirements.
[0060] In some embodiments, the point cloud data to be fitted can also be obtained through a point cloud extraction method commonly used by those skilled in the art.
[0061] S102: Determine a spatial fitting line and parameters of the spatial fitting line from the point cloud data to be fitted by a preset fitting method.
[0062] The preset fitting method includes fitting with external points and / or least squares fitting. The parameters of the spatial fitting line include a first direction vector of the line, a first line position point, a first number of inliers, a first RMS, a first offset, and a first inlier index.
[0063] When the preset fitting method is fitting with outliers, such as Figure 3 As shown, the determination of the spatial fitting straight line includes the following steps:
[0064] S1021. Obtain a suboptimal straight line based on random iteration of RANSAC for the point cloud data to be fitted.
[0065] Based on the RANSAC (Random Sample Consensus) algorithm framework, the RANSAC algorithm calculates the mathematical model parameters of the data based on a set of sample data sets containing abnormal data to obtain an algorithm for valid sample data. Figure 4 As shown, first, based on the RANSAC principle, two points in the point cloud data 30 to be fitted are randomly selected to construct a straight line, and then the distances from all points to the straight line are calculated. The inliers and outliers are separated according to the preset distance threshold, and the above random process is repeated. When the iteration termination condition is met, the straight line with the largest number of inliers is obtained as the final result.
[0066] At each iteration, the total number of iterations K is obtained, and two points are randomly selected from the point cloud data to be fitted to fit the current line. Points whose distance to the current line is within the preset distance threshold are regarded as inliers, and the number of inliers of the current line is obtained. Due to the constraint of the preset distance threshold, the current line obtained at this time has greatly reduced the interference of outliers on its parameters. The maximum number of iterations is determined according to the proportion of inliers of the current line, which is obtained by the following formula:
[0067]
[0068] Where t is the ratio of inliers, M is the number of inliers of the current line, and N is the total number of points in the point cloud data to be fitted.
[0069] P=1-(1-t 2 ) k
[0070] Where P is the confidence level and k is the maximum number of iterations for the current inlier ratio. The above formula is transformed to obtain the maximum number of iterations k as follows:
[0071]
[0072] When k≥K, continue iterating;
[0073] When k < K, determine the suboptimal straight line, which is the straight line with the largest number of interior points during the iteration process, such as Figure 5 As shown, there are outer points 32, inner points 31, and suboptimal straight line 33.
[0074] In one embodiment, the point cloud data to be fitted can be sampled using index step sampling and / or random sampling to obtain sampled point cloud data. Because the RANSAC algorithm itself is random, using the sampled point cloud data only affects the number of iterations. Subsequent iterations to find the optimal line can still obtain accurate line parameters, thereby reducing the time complexity of the algorithm.
[0075] S1022: Determine a spatial fitting line and parameters of the spatial fitting line based on the suboptimal line.
[0076] The idea of iterative optimization is to obtain the inliers based on the fitted line and the preset distance threshold and then refit the line. The fitting method is least squares. The process is iterated continuously. When the number of inliers no longer increases, the result is the optimal line.
[0077] The basic iterative optimization is to obtain the inliers from the suboptimal line and the preset distance threshold, and then perform the least squares fitting on the inliers to obtain a straight line; the inliers are obtained again from the line and the preset distance threshold, and then fitted again, and the process is repeated. When the number of inliers no longer increases, the corresponding straight line is the optimal straight line, that is, the spatial fitting straight line, such as Figure 6 As shown, there are outer points 32, inner points 31, and a spatial fitting line 34. At this time, the number of inner points of the spatial fitting line is greater than or equal to the number of inner points of the suboptimal line, and therefore, it has higher accuracy.
[0078] The parameters of the spatial fitting line are determined according to the line's first direction vector, the line's first position point, the first number of inliers, the first RMS, the first offset, and the first inlier index; wherein the first offset is the maximum distance from the point cloud to the line.
[0079] like Figure 7 As shown in the example of the background technology, the present application obtains a fitting straight line 20 without the outliers by a fitting method with outliers, thereby overcoming the interference of outliers on the straight line fitting.
[0080] When the preset fitting method is least squares fitting, the spatial fitting straight line is determined by obtaining the spatial fitting straight line through the least squares method of the point cloud data to be fitted, and obtaining the first direction vector, first position point, first inner point index, first number of inner points, first RMS and first offset of the spatial fitting straight line.
[0081] S103 , projecting the spatial fitting line onto a preset plane to obtain a plane fitting line and parameters of the plane fitting line.
[0082] like Figure 8 As shown, the thick solid line is the space fitting line 41, and the dotted line is the plane fitting line 42 projected onto the projection plane 43. The construction plane 44 is obtained by the plane fitting line and the space fitting line, as shown in FIG. Figure 9 As shown, Figure 8 In this case, the RMS and offset of the point cloud to the construction plane are equivalent to the RMS and offset of the point cloud to the straight line. The second offset and second RMS of the plane fitting straight line are obtained by equivalent calculation, avoiding a large number of point cloud projection operations and reducing complexity.
[0083] As can be seen from the above technical solution, the present application provides a constraint-based three-dimensional straight line fitting method provided by the present application, including determining point cloud data to be fitted; determining a spatial fitting line and the parameters of the spatial fitting line by a preset fitting method for the point cloud data to be fitted, the preset fitting method including fitting with outliers and least squares fitting; projecting the spatial fitting line onto a preset plane to obtain a plane fitting line and the parameters of the plane fitting line, wherein the second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the spatial fitting line. The present application overcomes the interference of outliers on straight line fitting through the preset fitting method, improves the accuracy of straight line fitting, and reduces the complexity of point cloud projection operations.
[0084] The above content is only for explaining the technical idea of the present application and cannot be used to limit the protection scope of the present application. Any changes made on the basis of the technical solution in accordance with the technical idea proposed in the present application shall fall within the protection scope of the claims of the present application.
[0085] In addition, unless expressly stated in the claims, the order of the processing elements and sequences described in this application, the use of alphanumeric characters, or the use of other names are not intended to limit the order of the processes and methods of this application. Although the above disclosure discusses some embodiments currently considered useful through various examples, it should be understood that such details are only for illustrative purposes, and the attached claims are not limited to the disclosed embodiments. On the contrary, the claims are intended to cover all modifications and equivalent combinations that are consistent with the essence and scope of the embodiments of this application. For example, although the system components described above can be implemented by hardware devices, they can also be implemented only by software solutions, such as installing the described system on an existing server or mobile device.
[0086] Similarly, it should be noted that, in order to simplify the description of the present disclosure and thus facilitate understanding of one or more embodiments, the foregoing descriptions of the embodiments of the present disclosure sometimes combine multiple features into a single embodiment, figure, or description thereof. However, this disclosure method does not mean that the subject matter of the present disclosure requires more features than those recited in the claims. In fact, the features of an embodiment may be fewer than all the features of a single embodiment disclosed above.
[0087] Each patent, patent application, patent application disclosure, and other materials, such as articles, books, specifications, publications, documents, etc., cited in this application is hereby incorporated by reference in its entirety. This includes application history documents that are inconsistent with or conflict with the content of this application, as well as documents (currently or subsequently attached to this application) that limit the broadest scope of the claims of this application. It should be noted that if the descriptions, definitions, and / or use of terms in the accompanying materials of this application are inconsistent or conflicting with the content of this application, the descriptions, definitions, and / or use of terms in this application shall prevail.
Claims
1. A constraint-based three-dimensional straight line fitting method, characterized in that: include: Determine the point cloud data to be fitted; The point cloud data to be fitted is used to determine a spatial fitting line and parameters of the spatial fitting line by a preset fitting method, wherein the preset fitting method includes fitting with outliers and least squares fitting; The spatial fitting line is projected onto a preset plane to obtain a plane fitting line and parameters of the plane fitting line, wherein the second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the spatial fitting line; When the preset fitting method is fitting with outliers, determining the spatial fitting line includes: The point cloud data to be fitted is used to determine a suboptimal straight line based on random iteration of RANSAC; determining a spatial fitting straight line according to the suboptimal straight line; The determination of the spatial fitting straight line includes: determining a first inlier point according to the suboptimal straight line and a preset distance threshold; The first interior point is fitted with a middle straight line according to least squares, and the middle straight line and a preset distance are used to determine the second interior point; When the number of adjacent inner points no longer increases, the corresponding middle straight line is the spatial fitting straight line; The second offset and the second RMS in the parameters of the plane fitting line are determined by the parameters of the space fitting line, including: The plane fitting straight line and the space fitting straight line determine a construction plane; A second RMS and a second offset among the parameters of the plane fitting line are determined, where the second offset and the second RMS are equivalent to a third offset and a third RMS of the point cloud with respect to the construction plane.
2. A constraint-based three-dimensional straight line fitting method according to claim 1, characterized in that: The point cloud data to be fitted is extracted from the point cloud data of the object to be measured according to a preset index requirement. The point cloud data includes index information and data information. The preset index requirement is composed of the index information.
3. The constraint-based three-dimensional straight line fitting method according to claim 1, characterized in that: The point cloud data to be fitted is subjected to random iteration based on RANSAC to determine a suboptimal straight line, including: Get the total number of iterations; Obtain the current line and its number of inliers for each iteration, where the current line is fitted by randomly selecting two points from the point cloud data to be fitted, and the number of inliers is the number of points whose distance to the current line is within a preset distance threshold; Determining the maximum number of iterations for each iteration according to the inlier point ratio of the current straight line, wherein the inlier point ratio is the ratio of the number of inlier points to the total number of points in the point cloud data to be fitted; When the maximum number of iterations is less than the total number of iterations, the corresponding current straight line is determined to be a suboptimal straight line.
4. The constraint-based three-dimensional straight line fitting method according to claim 3, characterized in that: The determination of the maximum number of iterations for each iteration includes: Obtain the interior point ratio, which is calculated according to the following formula: Where t is the ratio of inliers, M is the number of inliers of the current line, and N is the total number of points in the point cloud data to be fitted; The confidence level is obtained by calculating the confidence level according to the following formula: P=1-(1-t 2 ) k Where P is the confidence level, k is the maximum number of iterations of the current inlier ratio; The above formula is transformed to obtain the maximum number of iterations:
5. A constraint-based three-dimensional straight line fitting method according to claim 3 or 4, characterized in that: The point cloud data to be fitted is used to determine a suboptimal straight line based on random iteration of RANSAC, further comprising: When the maximum number of iterations is not less than the total number of each iteration, continue iterating.
6. The constraint-based three-dimensional straight line fitting method according to claim 1, characterized in that: Determination of the suboptimal straight line includes: Sampling the point cloud data to be fitted according to index step sampling and / or random sampling to obtain sampled point cloud data; The sampling point cloud data is used to determine a suboptimal straight line based on random iteration of RANSAC.
7. The constraint-based three-dimensional straight line fitting method according to claim 1, wherein: The parameters of the spatial fitting line include a first direction vector, a first position point, a first inlier index, a first number of inliers, a first RMS, and a first offset; The parameters of the plane fitting line include a second direction vector, a second position point, a second inlier point index, a second inlier point number, a second RMS, and a second offset.
Citation Information
Patent Citations
Straight line fitting method and device based on big data
CN112085759A