Cylindrical axis detection methods, devices, electronic equipment and storage media
By voting on the normals in the point cloud and constructing a fitted plane, the problems of high computational cost and low efficiency in existing cylinder axis detection are solved, and efficient and stable cylinder axis detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FAIR INNOVATION (SUZHOU) ROBOTIC SYSTEM CO LTD
- Filing Date
- 2024-12-27
- Publication Date
- 2026-07-31
AI Technical Summary
Existing cylinder axis detection algorithms require first detecting planes in the point cloud and removing points on those planes, which reduces the number of points on the cylinder surface. In addition, the voting process is complex and computationally intensive, resulting in low computational efficiency.
By traversing all points in the point cloud to be detected, voting is performed on the normal vectors of each point based on preset rules, a first voting list and array are constructed, a fitting plane is constructed and the normal vectors are updated, until the number of iterations is reached, and the latest cylindrical axis is obtained.
This reduces computational load, improves detection efficiency, avoids secondary voting, and ensures the stability of axial detection.
Smart Images

Figure CN119850567B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of point cloud processing technology, and more specifically, to a method, apparatus, electronic device, and storage medium for detecting the axis of a cylinder. Background Technology
[0002] The existing algorithm for detecting the axis of a cylinder in a point cloud works as follows: First, planes are detected in the point cloud. Then, points on the planes are removed, and axis voting is performed on the remaining points. The axis voting process is as follows: First, normal voting is performed, that is, each point in the point cloud is traversed to obtain the normal of that point. For each normal, an angle combination is calculated (…). θ , φ ),in θ Indicates normal direction xy Projection on a plane and x The included angle of the axis, φ Indicates normal and z The included angle of the axis. Voting is conducted in the first voting accumulator based on the angle combination; normals with the same angle combination correspond to the same voting position in the first voting accumulator. Then, the first voting accumulator is traversed, and for each normal, a rotation circle is calculated. The rotation circle is formed by... xy This is obtained by rotating a unit circle on a plane, where the normal vector of the rotated circle is the same as the current normal vector. Then, each point on the rotated circle is traversed and voted on again. Each point on the rotated circle is a unit vector, corresponding to an angle combination (...). θ , φ Alternatively, a vote is taken on this angle combination, and the voting results are recorded in the second voting accumulator. Then, the extreme point in the second voting accumulator is found, and the angle combination corresponding to this extreme point is the direction of the cylinder axis.
[0003] The existing cylindrical axis detection algorithms mainly have the following two problems. (1) Before performing cylindrical axis detection, it is necessary to detect the plane in the point cloud and then remove the points on the plane. For a point cloud with a cylinder, when performing plane detection, sometimes the points on the cylindrical surface are detected as points on the plane. If the points on the plane are removed, the points on the cylindrical surface will also be removed, resulting in a reduction in the number of points belonging to the cylindrical surface. (2) The voting process is complex and computationally intensive. From the above detection process, a total of two voting processes are required. The first is to vote on the normal of each point in the point cloud, and the second is to vote on the points on each rotating circle. Since each normal in the first voting accumulator corresponds to a rotating circle, and the rotating circle itself has 360 points, the second voting accumulator needs to perform 360 voting processes. n , nThis represents the number of voting positions in the first voting accumulator. Therefore, the second voting accumulator has a large number of votes, resulting in a long computation time and thus low computational efficiency for existing cylinder detection algorithms. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, electronic device and storage medium for detecting cylindrical shafts, which can improve the detection efficiency of cylindrical shafts.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a method for detecting the axis of a cylinder, the method comprising: Determine the point cloud to be detected, wherein the point cloud to be detected contains only one cylinder; Traverse each point in the point cloud to be detected, and vote on the normal of each point based on preset rules to obtain a first voting list, wherein the first voting list contains each voting position and the number of votes corresponding to each voting position; Based on each element in the first voting list, a first array is constructed, wherein the first array includes the normal and the number of votes for each element; Based on the number of votes, the first array is sorted to obtain the second array; Construct a first fitting plane based on the second array and determine the first plane vector of the first fitting plane; The first array is updated based on the first planar vector to obtain a new first array; Based on the new first array, construct a new first fitting plane and determine a new first plane vector for the new first fitting plane; When the new first plane vector is unstable, return to the step of updating the first array based on the first plane vector to obtain a new first array, and then constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the cylinder axis.
[0006] In an optional implementation, the step of traversing each point in the point cloud to be detected and voting on the normals of each point based on preset rules to obtain a first voting list includes: Traverse all points in the point cloud to be detected and determine the coordinates and normals of each point; The first included angle and the second included angle are calculated based on the normal, wherein the first included angle is the angle between the projection of the normal onto the xy plane and the x-axis, and the second included angle is the angle between the normal and the z-axis; Calculate the voting position of the point based on the first included angle and the second included angle; Determine whether the voting position for that point is included in the first voting list; If so, increment the number of votes for that voting position by one; If not, the voting position of that point is stored in the first voting list, and the number of votes for that voting position is set to 1.
[0007] In an optional implementation, the step of calculating the first included angle and the second included angle based on the normal includes: Determine the x-axis and z-axis components of the normal; Calculate the first included angle based on the x-axis component and the z-axis component; The second included angle is calculated based on the z-axis component.
[0008] In an optional implementation, the step of constructing a first array based on each element in the first voting list includes: Iterate through each element in the first voting list to determine the voting position of the element and the number of votes for that voting position; Based on the voting positions, calculate the third and fourth included angles; Based on the third included angle and the fourth included angle, the first normal of the voting position is obtained; A first array is constructed based on the number of votes and the first normal vector.
[0009] In an optional implementation, the step of constructing a first fitting plane based on the second array and determining a first plane vector of the first fitting plane includes: A first fitting plane is constructed by obtaining a preset number of target elements from the second array sorted first. Calculate the covariance matrix based on the target elements; Based on the covariance matrix, the eigenvector with the smallest eigenvalue is determined and used as the first plane vector of the first fitting plane.
[0010] In an optional implementation, the step of updating the first array based on the first planar vector to obtain a new first array includes: Calculate the distance between all normals in the first array and the first fitted plane; Based on the distances mentioned above, the first array is updated to obtain the third array; The third array is sorted in ascending order according to the distance to obtain a new first array.
[0011] In an optional implementation, the step of updating the first array based on the first plane vector when the new first plane vector is unstable, obtaining a new first array, and then constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and obtaining the latest first plane vector as the cylinder axis, includes: Determine the second plane vector after the previous iteration calculation; Calculate the fifth angle between the second plane vector and the new first plane vector; When the fifth included angle is greater than a preset threshold, the new first plane vector is determined to be unstable. Return to the step of updating the first array based on the first plane vector to obtain a new first array, and then constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the cylinder axis.
[0012] Secondly, embodiments of this application provide a cylindrical axis detection device, the device comprising: A determination module is used to determine the point cloud to be detected, wherein the point cloud to be detected contains only a cylinder; The voting module is used to traverse each point in the point cloud to be detected, vote on the normal of each point based on preset rules, and obtain a first voting list, wherein the first voting list contains each voting position and the number of votes corresponding to each voting position; A construction module is used to construct a first array based on each element in the first voting list, wherein the first array includes the normal and the number of votes for each element; The determining module is further configured to sort the first array based on the number of votes to obtain a second array; construct a first fitting plane based on the second array and determine a first plane vector of the first fitting plane; update the first array based on the first plane vector to obtain a new first array; construct a new first fitting plane based on the new first array and determine a new first plane vector of the new first fitting plane; if the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector to obtain a new first array and constructing a new first fitting plane based on the new first array and determining a new first plane vector of the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the axis of the cylinder.
[0013] Thirdly, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the cylindrical axis detection method.
[0014] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the cylindrical axis detection method.
[0015] This application has the following beneficial effects: This application determines a point cloud to be detected, traverses each point in the point cloud, and votes on the normals of each point based on preset rules to obtain a first voting list. Based on each element in the first voting list, a first array is constructed. Based on the number of votes, the first array is sorted to obtain a second array. A first fitting plane is constructed based on the second array, and a first plane vector of the first fitting plane is determined. The first array is updated based on the first plane vector to obtain a new first array. A new first fitting plane is constructed based on the new first array, and a new first plane vector of the new first fitting plane is determined. If the new first plane vector is unstable, the process returns to updating the first array based on the first plane vector, obtaining a new first array, and so on, until the required number of iterations is reached, and the latest first plane vector is obtained as the axis of the cylinder. This eliminates the need for secondary voting, reducing computational load and time, and ensuring stable axial detection. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A block diagram illustrating an electronic device provided in an embodiment of this application; Figure 2 This is one of the flowcharts illustrating a method for detecting the axis of a cylinder provided in this application. Figure 3 A second schematic flowchart illustrating a method for detecting the axis of a cylinder provided in this application embodiment; Figure 4 The third schematic flowchart of a method for detecting the axis of a cylinder provided in this application embodiment; Figure 5The fourth schematic flowchart of a method for detecting the axis of a cylinder provided in this application embodiment; Figure 6 Fifth schematic flowchart of a method for detecting the axis of a cylinder provided in this application embodiment; Figure 7 A schematic flowchart of a method for detecting the axis of a cylinder provided in this application is shown in Figure 6. Figure 8 This is a structural block diagram of a cylindrical axis detection device provided in an embodiment of this application. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0019] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0020] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0021] In the description of this application, it should be noted that if the terms "upper", "lower", "inner", "outer", etc. appear to indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings, or the orientation or positional relationship in which the product of the invention is usually placed when in use, they are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application.
[0022] Furthermore, the terms "first" and "second" are used only to distinguish descriptions and should not be interpreted as indicating or implying relative importance.
[0023] In the description of this application, it should also be noted that, unless otherwise expressly specified and limited, the terms "set up," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0024] The inventors discovered through extensive research that existing methods for determining the axis of a cylinder have low computational efficiency.
[0025] In view of the above-mentioned problems, this embodiment provides a method, apparatus, electronic device, and storage medium for detecting the axis of a cylinder. It can determine a point cloud to be detected, traverse all points in the point cloud, vote on the normals of each point based on preset rules to obtain a first voting list, construct a first array based on each element in the first voting list, sort the first array based on the number of votes to obtain a second array, construct a first fitting plane based on the second array and determine the first plane vector of the first fitting plane, update the first array based on the first plane vector to obtain a new first array, construct a new first fitting plane based on the new first array and determine a new first plane vector for the new first fitting plane, and if the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector to obtain a new first array, constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the required number of iterations is reached, and the latest first plane vector is obtained as the axis of the cylinder. This eliminates the need for secondary voting, reduces computational load and time, and provides stable axial detection. The solution provided in this embodiment will be described in detail below.
[0026] This embodiment provides an electronic device capable of detecting the axis of a cylinder. In one possible implementation, the electronic device can be a user terminal, such as, but not limited to, a server, smartphone, personal computer (PC), tablet computer, personal digital assistant (PDA), mobile internet device (MID), and image acquisition device.
[0027] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the structure of the electronic device 100 provided in the embodiments of this application. The electronic device 100 may further include... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0028] The electronic device 100 includes a cylindrical axis detection device 110, a memory 120, and a processor 130.
[0029] The components of the memory 120 and processor 130 are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The cylindrical axis detection device 110 includes at least one software function module that can be stored in the memory 120 in the form of software or firmware or embedded in the operating system (OS) of the electronic device 100. The processor 130 is used to execute the executable modules stored in the memory 120, such as the software function modules and computer programs included in the cylindrical axis detection device 110.
[0030] The memory 120 may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), etc. The memory 120 is used to store programs, and the processor 130 executes the programs after receiving execution instructions.
[0031] Please refer to Figure 2 , Figure 2 For application Figure 1 The flowchart below shows a method for detecting the cylindrical axis of an electronic device 100. The method includes a detailed description of each step.
[0032] S201: Determine the point cloud to be detected.
[0033] The point cloud to be detected contains only one cylinder.
[0034] S202: Traverse all points in the point cloud to be detected, and vote on the normal of each point based on preset rules to obtain the first voting list.
[0035] The first voting list includes each voting position and the number of votes for each voting position.
[0036] S203: Construct the first array based on each element in the first voting list.
[0037] The first array includes the normal and vote count of each element.
[0038] S204: Sort the first array based on the number of votes to obtain the second array.
[0039] S205: Construct a first fitting plane based on the second array and determine the first plane vector of the first fitting plane.
[0040] S206: Update the first array based on the first plane vector to obtain a new first array.
[0041] S207: Construct a new first fitting plane based on the new first array and determine the new first plane vector of the new first fitting plane.
[0042] S208: When the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector, obtaining a new first array, constructing a new first fitting plane based on the new first array, and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and obtain the latest first plane vector as the cylinder axis.
[0043] Traverse each point in the point cloud to be detected, determine the point cloud parameters of the point, and vote on the normal of the point based on the point cloud parameters. The point cloud parameters may include the coordinates of the point and the normal of the point.
[0044] For each element in the first voting list, construct a first array based on the parameters of each element, sort the elements in the first array according to the number of votes to obtain a second array, obtain a preset number of elements from the second array, construct a first fitting plane, and determine the first plane vector of the first fitting plane, which is the normal of the first fitting plane.
[0045] It should be noted that the first preset quantity can be set according to the actual situation, and this application embodiment does not impose specific restrictions on it.
[0046] Determine the distance between each normal vector in each first array and the first plane vector. Update the first array based on the distance between the normal vector and the first plane vector. Sort the updated first array based on the distance to obtain a new first array.
[0047] A predetermined number of elements are obtained from the new first array to construct a new first fitting plane. A new first plane vector is determined for the new fitting plane, and it is determined whether the new first plane vector is stable. If the new first plane vector is unstable, the distance between each normal in the new first array and the new first plane vector is calculated, and the new first array is updated again to obtain a third array. The third array is sorted based on the distance to obtain a new third array. A predetermined number of elements are obtained from the new third array to construct a second fitting plane, and a second plane vector for the second fitting plane is determined. The second plane vector is used as the new first plane vector. If the second plane vector is stable, it is used as the axis of the cylinder. If the second plane vector is unstable, the process of updating the first array based on the first plane vector is repeated to obtain a new first array. This process continues until the number of iterations is reached, and the latest first plane vector is used as the axis of the cylinder.
[0048] It should be noted that the number of iterations can be set according to the actual situation.
[0049] There are multiple ways to traverse all points in the point cloud to be detected and vote on the normals of each point based on preset rules to obtain the first voting list. In one implementation, such as... Figure 3 As shown, it includes the following steps: S301: Traverse all points in the point cloud to be detected and determine the coordinates and normals of each point.
[0050] S302: Calculate the first included angle and the second included angle based on the normal.
[0051] Wherein, the first included angle is the angle between the projection of the normal onto the xy plane and the x-axis, and the second included angle is the angle between the normal and the z-axis.
[0052] S303: Calculate the voting position of the point based on the first included angle and the second included angle.
[0053] S304: Determine whether the voting position for this point is included in the first voting list.
[0054] S305: If so, then increment the number of votes for that voting position by one.
[0055] S306: If not, store the voting position of that point in the first voting list and set the number of votes for that voting position to 1.
[0056] Use variable i to iterate through each point in the point cloud to be detected and determine the coordinates of point i. p i and legal direction n i,according to n i Calculate the first included angle θ i Second angle φ i First included angle θ i Indicates normal direction xy Projection on a plane and x The included angle of the axis, the second included angle φ i Indicates normal and z The included angle of the axis.
[0057] The first included angle is calculated using the x-axis and z-axis components of the normal vector. θ i The calculation formula is as follows: ,in, The x-axis component is the normal vector. n i, z The z-axis component is the normal direction.
[0058] The second included angle is calculated using the z-axis component of the normal direction. φ i The calculation formula is as follows: ,in, The z-axis component is the normal vector.
[0059] According to the first included angle θ i Second angle φ i Calculate the voting position normal_index_i. The voting position normal_index_i is obtained by combining the quantized first angle and the second angle. The voting position normal_index_i consists of a pair of integers, i.e. ( a i, 1 , a i, 2 ),in a i, 1 , a i, 2 All are integers. a i, 1 and a i, 2 Corresponding to the first included angle θ i Second angle φ i The result after quantification.
[0060] The process of quantizing an angle is as follows: Define an angle resolution, which represents the number of quantizations performed on an angle range of 180°. For example, the resolution can be set to 180, which means the quantization accuracy is 1°.
[0061] For the first angle θ i The quantification formula is: ,in l That is, angular resolution, for the second angle φ i The quantification formula is: .
[0062] Check if the first voting list contains the voting position at normal_index_i. If it does, cast a vote at the normal_index_i voting position, incrementing the vote count by 1, and setting the corresponding coordinates. p i Save the data. If the data is not included, create a voting position `normal_index_i` in the first voting list, set the number of votes to 1, and record the corresponding coordinates. p i Save the data and repeat the above process until all iterations of i are completed. The first voting list is then constructed.
[0063] There are multiple ways to construct the first array based on the elements in the first voting list. In one implementation, such as... Figure 4 As shown, it includes the following steps: S401: Iterate through each element in the first voting list to determine the voting position of the element and the number of votes for that position.
[0064] S402: Calculate the third and fourth included angles based on the voting positions.
[0065] S403: Based on the third and fourth included angles, obtain the first normal of the voting position.
[0066] S404: Construct the first array based on the number of votes and the first normal vector.
[0067] Iterate through the first voting list using variable i to obtain the i-th voting position normal_index_i and the corresponding number of votes count_i. Calculate the third angle based on the voting position normal_index_i. and the fourth angle Then, the first normal vector normal_i is calculated. The voting position normal_index_i contains two integers ( a i, 1 , a i, 2The formula for converting it into an angle is as follows: ; .
[0068] According to the third included angle b i and the fourth angle c i The formula for calculating the first normal vector normal_i is as follows: , , .
[0069] Combine the vote count_i and the first normal vector normal_i, and store them in the first array normals.
[0070] The first array, normals, contains the normal vector normal_i and the vote count count_i.
[0071] The first fitting plane is constructed based on the second array, and the first plane vector of the first fitting plane is determined.
[0072] Based on the first array, sort the elements in the first array (normals) in descending order of the number of votes (count) for each element to obtain the second array.
[0073] There are several ways to construct the first fitting plane based on the second array and determine the first plane vector of the first fitting plane. In one implementation, such as... Figure 5 As shown, it includes the following steps: S501: Obtain a preset number of target elements from the second array sorted first to construct the first fitting plane.
[0074] S502: Calculate the covariance matrix based on the target element.
[0075] S503: Based on the covariance matrix, determine the eigenvector with the smallest eigenvalue, and use it as the first plane vector of the first fitting plane.
[0076] In one example, the first 10% of the elements in the second array are taken as the target elements, and a plane fitting is performed based on the target elements to obtain the first fitted plane. Since this plane must pass through the origin, only the normal vector of this plane, i.e., the first plane vector, needs to be calculated during fitting.
[0077] The first plane vector of the first fitted plane can be calculated as follows: The covariance matrix is calculated based on the target elements, and the eigenvector of the smallest eigenvalue of the covariance matrix is determined as the first plane vector of the first fitting plane.
[0078] The formula for calculating the covariance matrix is as follows: ,in , m i express n i The number of votes, n i This represents the i-th normal in the target element. Let represent the covariance matrix.
[0079] The covariance matrix is a symmetric matrix, therefore it can be diagonalized. The eigenvalues and eigenvectors of the covariance matrix can be found by solving the following eigenvalue problem: Σ v = λv in, λ Let v be the eigenvalue and v' be the corresponding eigenvector. Arrange all eigenvalues in ascending order and find the smallest eigenvalue. λ The eigenvector corresponding to the minimum eigenvalue is the eigenvector of the first fitted plane, which is the first plane vector of the first fitted plane.
[0080] There are several ways to update the first array based on the first plane vector to obtain a new first array. In one implementation, such as... Figure 6 As shown, it includes the following steps: S601: Calculate the distance between all normals in the first array and the first fitted plane.
[0081] S602: Update the first array based on each distance to obtain the third array.
[0082] S603: Sort the third array in ascending order of distance to obtain a new first array.
[0083] Use i to traverse the first array normals to obtain the normal vector. n i Calculate the distance from the normal vector to the first fitted plane: d i = | n i t c |, among which t c It is the current cylindrical axis, i.e., the first planar vector. d i is the distance from the normal vector to the first fitted plane.
[0084] Will d iAssign each normal to the first array to obtain the third array. Sort the third array in ascending order of distance to obtain the new first array.
[0085] There are multiple ways to determine whether a new first plane vector is stable. In one implementation, such as... Figure 7 As shown, it includes the following steps: S701: Determine the second plane vector after the previous iteration.
[0086] S702: Calculate the fifth angle between the second plane vector and the new first plane vector.
[0087] S703: When the fifth included angle is greater than the preset threshold, the new first plane vector is determined to be unstable.
[0088] When the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector, obtaining a new first array, constructing a new first fitting plane based on the new first array, and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and obtain the latest first plane vector as the axis of the cylinder.
[0089] S704: When the fifth included angle is less than or equal to the preset threshold, the new first plane vector is determined to be stable.
[0090] It should be noted that the preset threshold can be determined according to the actual situation, and this application embodiment does not impose specific restrictions on it.
[0091] When the fifth included angle is less than or equal to the preset threshold, the new first plane vector is taken as the axis of the cylinder.
[0092] Please refer to Figure 8 This application embodiment also provides an application for Figure 1 The cylindrical axis detection device 110 of the electronic device 100 includes: The determining module 111 is used to determine the point cloud to be detected, wherein the point cloud to be detected contains only one cylinder; Voting module 112 is used to traverse each point in the point cloud to be detected, vote on the normal of each point based on preset rules, and obtain a first voting list, wherein the first voting list includes each voting position and the number of votes corresponding to each voting position; The construction module 113 is used to construct a first array based on each element in the first voting list, wherein the first array includes the normal and the number of votes for each element; The determining module 111 is further configured to sort the first array based on the number of votes to obtain a second array; construct a first fitting plane based on the second array and determine a first plane vector of the first fitting plane; update the first array based on the first plane vector to obtain a new first array; construct a new first fitting plane based on the new first array and determine a new first plane vector of the new first fitting plane; when the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector to obtain a new first array and constructing a new first fitting plane based on the new first array and determining a new first plane vector of the new first fitting plane, until the number of iterations is reached and the latest first plane vector is obtained as the axis of the cylinder.
[0093] This application also provides an electronic device 100, which includes a processor 130 and a memory 120. The memory 120 stores computer-executable instructions, which, when executed by the processor 130, implement the cylindrical axis detection method.
[0094] This application embodiment also provides a computer-readable storage medium storing a computer program, which, when executed by a processor 130, implements the cylindrical axis detection method.
[0095] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0096] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. If the function is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes: USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, optical disks, and other media capable of storing program code.
[0097] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0098] The above descriptions are merely various embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method of detecting a cylinder axis, characterized by, The method includes: Determine the point cloud to be detected, wherein the point cloud to be detected contains only one cylinder; Traverse each point in the point cloud to be detected, and vote on the normal of each point based on preset rules to obtain a first voting list, wherein the first voting list contains each voting position and the number of votes corresponding to each voting position; Based on each element in the first voting list, a first array is constructed, wherein the first array includes the normal and the number of votes for each element; Based on the number of votes, the first array is sorted to obtain the second array; Construct a first fitting plane based on the second array and determine the first plane vector of the first fitting plane; The first array is updated based on the first planar vector to obtain a new first array; Based on the new first array, construct a new first fitting plane and determine a new first plane vector for the new first fitting plane; When the new first plane vector is unstable, return to the step of updating the first array based on the first plane vector to obtain a new first array, and then constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the cylinder axis. The step of traversing each point in the point cloud to be detected and voting on the normal of each point based on preset rules to obtain a first voting list includes: Traverse all points in the point cloud to be detected and determine the coordinates and normals of each point; The first included angle and the second included angle are calculated based on the normal, wherein the first included angle is the angle between the projection of the normal onto the xy plane and the x-axis, and the second included angle is the angle between the normal and the z-axis; Calculate the voting position of the point based on the first included angle and the second included angle; Determine whether the voting position for that point is included in the first voting list; If so, increment the number of votes for that voting position by one; If not, the voting position of that point is stored in the first voting list, and the number of votes for that voting position is set to 1; The step of constructing the first array based on each element in the first voting list includes: Iterate through each element in the first voting list to determine the voting position of the element and the number of votes for that voting position; Based on the voting position, the third included angle and the fourth included angle are calculated, wherein the third included angle is calculated by the first included angle and the voting position, and the fourth included angle is calculated by the second included angle and the voting position; Based on the third included angle and the fourth included angle, the first normal of the voting position is obtained; Construct a first array based on the number of votes and the first normal vector; The steps of constructing a first fitting plane based on the second array and determining a first plane vector of the first fitting plane include: A first fitting plane is constructed by obtaining a preset number of target elements from the second array sorted first. Calculate the covariance matrix based on the target elements; Based on the covariance matrix, the eigenvector with the smallest eigenvalue is determined and used as the first plane vector of the first fitting plane. The step of updating the first array based on the first plane vector to obtain a new first array includes: Calculate the distance between all normals in the first array and the first fitted plane; Based on the distances mentioned above, the first array is updated to obtain the third array; The third array is sorted in ascending order according to the distance to obtain a new first array.
2. The method of claim 1, wherein, The step of calculating the first included angle and the second included angle based on the normal includes: Determine the x-axis and z-axis components of the normal; Calculate the first included angle based on the x-axis component and the z-axis component; The second included angle is calculated based on the z-axis component.
3. The method according to claim 1, characterized in that, When the new first plane vector is unstable, the process of updating the first array based on the first plane vector to obtain a new first array, and then constructing a new first fitting plane based on the new first array and determining the new first plane vector of the new first fitting plane, continues until the number of iterations is reached. The step of obtaining the latest first plane vector as the cylinder axis includes: Determine the second plane vector after the previous iteration calculation; Calculate the fifth angle between the second plane vector and the new first plane vector; When the fifth included angle is greater than a preset threshold, the new first plane vector is determined to be unstable. Return to the step of updating the first array based on the first plane vector to obtain a new first array, and then constructing a new first fitting plane based on the new first array and determining a new first plane vector for the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the cylinder axis.
4. A cylindrical axis detection device, characterized in that, The device includes: A determination module is used to determine the point cloud to be detected, wherein the point cloud to be detected contains only a cylinder; The voting module is used to traverse all points in the point cloud to be detected, and vote on the normal of each point based on preset rules to obtain a first voting list. The first voting list includes each voting position and the number of votes corresponding to each voting position; A construction module is used to construct a first array based on each element in the first voting list, wherein the first array includes the normal and the number of votes for each element; The determining module is further configured to: sort the first array based on the number of votes to obtain a second array; construct a first fitting plane based on the second array and determine a first plane vector of the first fitting plane; update the first array based on the first plane vector to obtain a new first array; construct a new first fitting plane based on the new first array and determine a new first plane vector of the new first fitting plane; if the new first plane vector is unstable, return to the steps of updating the first array based on the first plane vector to obtain a new first array and constructing a new first fitting plane based on the new first array and determining a new first plane vector of the new first fitting plane, until the number of iterations is reached, and the latest first plane vector is obtained as the axis of the cylinder; The voting module is specifically used to: traverse each point in the point cloud to be detected and determine the coordinates and normal of the point; The first included angle and the second included angle are calculated based on the normal, wherein the first included angle is the angle between the projection of the normal onto the xy plane and the x-axis, and the second included angle is the angle between the normal and the z-axis; Calculate the voting position of the point based on the first included angle and the second included angle; Determine whether the voting position for that point is included in the first voting list; If so, increment the number of votes for that voting position by one; If not, the voting position of that point is stored in the first voting list, and the number of votes for that voting position is set to 1; The determining module is specifically used for: Iterate through each element in the first voting list to determine the voting position of the element and the number of votes for that voting position; Based on the voting position, the third included angle and the fourth included angle are calculated, wherein the third included angle is calculated by the first included angle and the voting position, and the fourth included angle is calculated by the second included angle and the voting position; Based on the third included angle and the fourth included angle, the first normal of the voting position is obtained; Construct a first array based on the number of votes and the first normal vector; A first fitting plane is constructed by obtaining a preset number of target elements from the second array sorted first. Calculate the covariance matrix based on the target elements; Based on the covariance matrix, the eigenvector with the smallest eigenvalue is determined and used as the first plane vector of the first fitting plane. Calculate the distance between all normals in the first array and the first fitted plane; Based on the distances mentioned above, the first array is updated to obtain the third array; The third array is sorted in ascending order according to the distance to obtain a new first array.
5. An electronic device, characterized in that, It includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the method according to any one of claims 1-3.
6. A storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method described in any one of claims 1-3.