Straight line detection method, electronic equipment and storage medium

By constructing a voting accumulator and calculating the straight line normal and target straight line distance parameters, the existing straight line detection algorithm is solved, and more efficient straight line detection is achieved.

CN119693438APending Publication Date: 2025-03-25FAIR INNOVATION (SUZHOU) ROBOTIC SYSTEM CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411750057.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-02
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

Existing linear detection algorithms, such as RANSAC and voting algorithms, have problems of instability and low computational efficiency, especially when there are many points, the speed of detecting straight lines is slow.

Method used

By traversing the points on the plane to be detected, the first and second voting accumulators are constructed based on the normal vectors and coordinates of each point, the voting position of the maximum voting value is obtained, the straight line normal and target straight line distance parameters are calculated, and the straight line detection is performed.

Benefits of technology

It improves the detection efficiency of linear detection, reduces instability and calculation amount, and improves the overall performance of the algorithm.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119693438A_ABST
    Figure CN119693438A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a straight line detection method, electronic equipment and a storage medium, and relates to the field of straight line detection.The method comprises the steps that all points on a to-be-detected plane are traversed, a first voting accumulator is constructed based on normal vectors and coordinates of all the points, and when the first voting accumulator is not null, a second voting accumulator is constructed; a voting position of a first maximum voting value is obtained from the first voting accumulator, a first included angle is calculated based on the voting position of the first maximum voting value, a linear normal direction is calculated based on the first included angle, a target point cloud pointer of the voting position of the first maximum voting value is obtained, and a second voting accumulator is constructed based on the target point cloud pointer; when the second voting accumulator is not empty, the voting position of the second maximum voting value is obtained from the second voting accumulator, the target linear distance parameter is calculated based on the voting position of the second maximum voting value, linear detection is carried out based on the linear normal direction and the target linear distance parameter, and the detection efficiency of linear detection can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of straight line detection, and in particular to a straight line detection method, electronic equipment and storage medium. Background Art

[0002] There are two main methods for the existing line detection algorithms for points on a plane, one is the random sample consensus algorithm (RANSAC), and the other is the voting algorithm. The principle of the RANSAC algorithm is to randomly select two points from the existing points, calculate the line passing through these two points, and then calculate the distance from all other points to the line. Points with distances less than a certain threshold are considered to be inliers, and the number of inliers corresponding to the current line is counted. Then repeat the above process multiple times, take the line with the largest inlier as the detected line, delete the inliers, and repeat the above detection steps for the remaining points until all lines are detected. The principle of the voting algorithm is that for each point on the plane, by traversing the (k, b) space, every line passing through the current point is obtained, and then the extreme points of the (k, b) space are detected, and each extreme point corresponds to a line.

[0003] The RANSAC algorithm is a random algorithm. Since the process of selecting points each time is random, it cannot guarantee that the results of each operation are consistent. Therefore, for the same set of points, different line detection results may be obtained, which will interfere with the subsequent algorithms for other operations based on line detection, making the overall algorithm unstable. The disadvantage of the voting algorithm is that it needs to traverse each k value and b value in (k, b), which has a huge amount of calculation. When the number of points is large, the speed of detecting lines will be very slow, and the algorithm has low computational efficiency. Summary of the invention

[0004] The object of the present invention is to provide a straight line detection method, an electronic device and a storage medium, which can improve the detection efficiency of straight line detection.

[0005] In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:

[0006] In a first aspect, an embodiment of the present application provides a straight line detection method, the method comprising:

[0007] Traversing each point on the plane to be detected, and constructing a first voting accumulator based on the normal vector and coordinates of each point, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers, and the point cloud pointers store the coordinates of the points on the plane that vote to the voting position;

[0008] When the first voting accumulator is not empty, obtaining a voting position with a first maximum voting value from the first voting accumulator;

[0009] Calculating a first angle based on the voting position of the first maximum voting value;

[0010] Calculate the normal direction of the straight line based on the first angle;

[0011] Obtain a target point cloud pointer of the voting position of the first maximum voting value;

[0012] Constructing a second voting accumulator based on the target point cloud pointer;

[0013] When the second voting accumulator is not empty, obtaining the voting position of the second maximum voting value from the second voting accumulator;

[0014] Calculate the target straight-line distance parameter based on the voting position of the second maximum voting value;

[0015] Line detection is performed based on the line normal and the target line distance parameter.

[0016] In an optional implementation, the step of traversing each point on the plane to be detected and constructing a first voting accumulator based on the normal vector and coordinates of each point includes:

[0017] Traversing each point on the plane to be detected, and determining the normal and coordinates of the point;

[0018] Determining the y-direction component of the normal;

[0019] When the y-direction component is less than zero, reversing the normal direction;

[0020] determining an x-direction component of the normal;

[0021] Determine the angle between the normal and the positive direction of the x-axis based on the x-direction component;

[0022] quantizing the angle between the normal and the positive direction of the x-axis to obtain a quantized value of the angle;

[0023] When the first voting accumulator does not contain the angle quantization value, constructing a voting position based on the angle quantization value and setting the voting value of the voting position to 1, and storing the coordinates of the point in the point cloud pointer corresponding to the voting position;

[0024] When the angle quantization value is included in the first voting accumulator, the voting value of the voting position corresponding to the angle quantization value is increased by one, and the coordinates of the point are stored in the point cloud pointer of the corresponding voting position.

[0025] In an optional implementation, the step of determining the angle between the normal and the positive direction of the x-axis based on the x-direction component includes:

[0026] When the x-direction component is greater than cos1°, determining that the angle between the normal and the positive direction of the x-axis is zero;

[0027] When the x-direction component is less than cos179°, the angle between the normal and the positive direction of the x-axis is determined to be 180°;

[0028] When the x-direction component is greater than or equal to cos179°, the angle between the normal and the positive x-axis is determined to be acos(n i ,x), where n i is the normal direction, and x is the x-axis coordinate of the point.

[0029] In an optional implementation, the step of calculating the first angle by calculating the voting position of the first maximum voting value by the following formula includes:

[0030] α=max_alpha_index / α_num×180, where α is the first angle, max_alpha_index is the voting position of the first maximum voting value, and α_num ​​is the quantization resolution.

[0031] In an optional embodiment, the straight line normal is calculated by the following formula:

[0032] n l,x = cos(α), where n l,x is the x-axis component of the normal to the straight line, and α is the first angle;

[0033] n l,y = sin(α), where n l,y is the y-axis component of the line normal.

[0034] In an optional implementation, the step of constructing a second voting accumulator based on the target point cloud pointer includes:

[0035] Traversing each target point in the target point cloud pointer;

[0036] determining the coordinates of the target point;

[0037] Calculate the product of the coordinates of the target point and the normal of the straight line as the inner product of the target point;

[0038] Based on the inner product, calculating the voting position of the target point;

[0039] A second voting accumulator is constructed based on the voting position of each target point and the inner product.

[0040] In an optional embodiment, the target straight-line distance parameter is calculated by the following formula:

[0041] Target straight-line distance parameter = max_b_index*b_size, where max_b_index is the voting position of the second largest voting value, and b_size is the quantization step size.

[0042] In an optional implementation, the step of performing straight line detection based on the straight line normal and the target straight line distance parameter includes:

[0043] Constructing a straight line to be detected based on the target straight line distance parameter and the straight line normal;

[0044] Traversing the points on the plane to be detected, and calculating the distance between the points and the straight line to be detected;

[0045] Comparing the distance between the point and the straight line to be detected with a preset distance threshold;

[0046] When the distance between the point and the straight line to be detected is less than the preset distance threshold, storing the label corresponding to the point in the first list;

[0047] Determine the number of points contained in the first list;

[0048] When the number is greater than a preset number, it is determined that the straight line to be detected is a straight line.

[0049] In a second aspect, an embodiment of the present application provides a straight line detection device, the device comprising:

[0050] A first construction module is used to traverse each point on the plane to be detected, and construct a first voting accumulator based on the normal vector and coordinates of each point, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers, and the point cloud pointers store the coordinates of the points on the plane that vote to the voting position;

[0051] an acquisition module, configured to acquire a voting position with a first maximum voting value from the first voting accumulator when the first voting accumulator is not empty;

[0052] A calculation module, configured to calculate a first angle based on the voting position of the first maximum voting value; and calculate a normal direction of a straight line based on the first angle;

[0053] The acquisition module is further used to acquire a target point cloud pointer of a voting position of the first maximum voting value;

[0054] A second construction module, used to construct a second voting accumulator based on the target point cloud pointer;

[0055] The acquisition module is further configured to acquire the voting position of the second maximum voting value from the second voting accumulator when the second voting accumulator is not empty;

[0056] The calculation module is further used to calculate a target straight-line distance parameter based on the voting position of the second maximum voting value;

[0057] The straight line detection module is used to perform straight line detection based on the straight line normal and the target straight line distance parameter.

[0058] In a third aspect, an embodiment of the present application provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the straight line detection method when executing the computer program.

[0059] In a fourth aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon, which implements the steps of the straight line detection method when executed by a processor.

[0060] This application has the following beneficial effects:

[0061] The present application traverses each point on the plane to be detected, and constructs a first voting accumulator based on the normal vector and coordinates of each point, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers, and the point cloud pointer stores the coordinates of the points on the plane that vote to the voting position. When the first voting accumulator is not empty, the voting position of the first maximum voting value is obtained from the first voting accumulator, the first angle is calculated based on the voting position of the first maximum voting value, the straight line normal is calculated based on the first angle, the target point cloud pointer of the voting position of the first maximum voting value is obtained, and a second voting accumulator is constructed based on the target point cloud pointer. When the second voting accumulator is not empty, the voting position of the second maximum voting value is obtained from the second voting accumulator, and the target straight line distance parameter is calculated based on the voting position of the second maximum voting value. Straight line detection is performed based on the straight line normal and the target straight line distance parameter, which can improve the detection efficiency of straight line detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0063] Figure 1 A block diagram of an electronic device provided by an embodiment of the present invention;

[0064] Figure 2 One of the flow charts of a straight line detection method provided by an embodiment of the present invention;

[0065] Figure 3 A second flow chart of a straight line detection method provided by an embodiment of the present invention;

[0066] Figure 4 A schematic diagram of the normal direction of a point provided by an embodiment of the present invention;

[0067] Figure 5 A third flow chart of a straight line detection method provided by an embodiment of the present invention;

[0068] Figure 6 A fourth flow chart of a straight line detection method provided by an embodiment of the present invention;

[0069] Figure 7 A structural block diagram of a straight line detection device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0070] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0071] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0072] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0073] In the description of the present invention, it should be noted that if the terms "upper", "lower", "inside", "outside", etc. appear to indicate an orientation or position relationship, they are based on the orientation or position relationship shown in the accompanying drawings, or are the orientation or position relationship in which the product of the invention is usually placed when used. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.

[0074] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.

[0075] In the description of this application, it should also be noted that, unless otherwise clearly specified and limited, the terms "set", "install", "connect", and "connect" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0076] After extensive research, the inventors found that the existing straight line detection algorithm for points on a plane has poor detection efficiency.

[0077] In view of the discovery of the above problems, the present embodiment provides a straight line detection method, an electronic device, and a storage medium, which can construct a first voting accumulator based on the normal vector and coordinates of each point by traversing each point on the plane to be detected, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers. The point cloud pointer stores the coordinates of the points on the plane that vote to the voting position. When the first voting accumulator is not empty, the voting position of the first maximum voting value is obtained from the first voting accumulator, the first angle is calculated based on the voting position of the first maximum voting value, the straight line normal is calculated based on the first angle, the target point cloud pointer of the voting position of the first maximum voting value is obtained, and a second voting accumulator is constructed based on the target point cloud pointer. When the second voting accumulator is not empty, the voting position of the second maximum voting value is obtained from the second voting accumulator, and the target straight line distance parameter is calculated based on the voting position of the second maximum voting value. The straight line detection is performed based on the straight line normal and the target straight line distance parameter, which can improve the detection efficiency of the straight line detection. The scheme provided by the present embodiment is described in detail below.

[0078] This embodiment provides an electronic device that can detect a straight line. In a possible implementation, the electronic device can be a user terminal, for example, the electronic device can be, but is not limited to, a server, a smart phone, a personal computer (PC), a tablet computer, a personal digital assistant (PDA), a mobile Internet device (MID), and an image acquisition device.

[0079] Please refer to Figure 1 , Figure 1 1 is a schematic diagram of the structure of the electronic device 100 provided in the embodiment of the present application. The electronic device 100 may also include Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown. Figure 1 Each component shown in the figure can be implemented by hardware, software or a combination thereof.

[0080] The electronic device 100 includes a straight line detection device 110 , a memory 120 , and a processor 130 .

[0081] The memory 120 and the processor 130 are electrically connected to each other 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 straight line 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 fixed 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 straight line detection device 110.

[0082] The memory 120 may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable read-only memory (EEPROM), etc. The memory 120 is used to store a program, and the processor 130 executes the program after receiving an execution instruction.

[0083] Please refer to Figure 2 , Figure 2 For application Figure 1 A flow chart of a straight line detection method of an electronic device 100 is shown, and the method including various steps is described in detail below.

[0084] S201: traverse each point on the plane to be detected, and construct a first voting accumulator based on the normal vector and coordinates of each point.

[0085] Among them, the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected. The first voting accumulator contains multiple voting positions. Different voting positions correspond to voting values ​​and point cloud pointers. The point cloud pointer saves the coordinates of the points on the plane that vote to the voting position.

[0086] S202: When the first voting accumulator is not empty, obtaining the voting position of the first maximum voting value from the first voting accumulator.

[0087] S203: Calculate a first angle based on the voting position of the first maximum voting value.

[0088] S204: Calculate the normal direction of the straight line based on the first angle.

[0089] S205: Obtain a target point cloud pointer of the voting position with the first maximum voting value.

[0090] S206: Construct a second voting accumulator based on the target point cloud pointer.

[0091] S207: When the second voting accumulator is not empty, obtain the voting position of the second maximum voting value from the second voting accumulator.

[0092] S208: Calculate the target straight-line distance parameter based on the voting position of the second maximum voting value.

[0093] S209: Perform straight line detection based on the straight line normal and the target straight line distance parameters.

[0094] Construct the first voting accumulator acc_alpha. The first voting accumulator has a series of voting positions. Each voting position will store the following two quantities: voting value and point cloud pointer. The voting value indicates how many times the voting position has voted in total. The point cloud pointer stores the coordinates of the points on the plane that voted to the voting position. The voting position is an integer. The function of the first voting accumulator acc_alpha is to record the voting status of the normal of the points on the plane.

[0095] When the first voting accumulator is empty, the entire algorithm ends.

[0096] When the first voting accumulator is not empty, each voting position of the first voting accumulator acc_alpha is traversed to obtain the voting position with the maximum voting value, that is, the voting position with the first maximum voting value. The voting position with the first maximum voting value is represented as max_alpha_index. The target point cloud pointer of the voting position with the first maximum voting value is taken out from the first voting accumulator. The corresponding first angle α is calculated according to the max_alpha_index of the voting position with the first maximum voting value. The normal of the straight line is calculated according to the first angle α.

[0097] The first angle can be calculated based on the voting position of the first maximum voting value by the following formula:

[0098] α=max_alpha_index / α_num×180, max_alpha_index is the voting position of the first maximum voting value, and α_num ​​is the resolution of quantization. The larger α_num ​​is, the finer the quantization is. For example, when α_num ​​is equal to 180, it means that α is quantized by 1°.

[0099] The normal to the line is calculated using the following formula:

[0100] n l,x = cos(α), where n l,x is the x-axis component of the normal to the straight line, and α is the first angle;

[0101] n l,y = sin(α), where n l,y is the y-axis component of the line normal.

[0102] For all points in the target point cloud pointer, the inner product of each point and the quantized value corresponding to the inner product are determined, and a second voting accumulator is constructed based on the inner product of each point and the quantized value corresponding to the inner product.

[0103] The second voting accumulator has a series of voting positions, each of which stores a value: voting value. The voting value indicates how many times the voting position has voted. The voting position is an integer. The second voting accumulator acc_b is used to record the voting situation of point b on the plane. b is a parameter of the line, indicating the distance from the origin of the coordinate system to the line. The equation of the line is n x ·x+n y y = b, where n x ,n y Represents the normal direction of the line.

[0104] When the first voting accumulator is not empty, the voting position of the first maximum voting value is obtained from the first voting accumulator. After the corresponding information is obtained based on the voting position of the first maximum voting value, the voting position of the first maximum voting value is deleted from the first voting accumulator. When the second voting accumulator is empty, return to determine whether the first voting accumulator is empty after deleting the voting position of the first maximum voting value. If it is not empty, obtain the new voting position of the first maximum voting value.

[0105] When the second voting accumulator is not empty, the voting position of the second maximum voting value is obtained from the second voting accumulator, and the target straight line distance parameter is calculated based on the voting position of the second maximum voting value. The straight line detection is performed based on the straight line normal obtained from the first voting accumulated value and the target straight line distance parameter obtained from the second voting accumulated value.

[0106] There are many ways to traverse each point on the plane to be detected and construct the first voting accumulator based on the normal vector and coordinates of the point. In one implementation, for example, Figure 3 As shown, the following steps are included:

[0107] S301: Traverse each point on the plane to be detected and determine the normal and coordinates of the point.

[0108] S302: Determine the y-direction component of the normal.

[0109] S303: When the y-direction component is less than zero, the normal direction is reversed.

[0110] S304: Determine the x-direction component of the normal.

[0111] S305: Determine the angle between the normal direction and the positive direction of the x-axis based on the x-direction component.

[0112] S306: quantizing the angle between the normal and the positive direction of the x-axis to obtain a quantized value of the angle.

[0113] S307: When the first voting accumulator does not contain the angle quantization value, a voting position is constructed based on the angle quantization value and the voting value of the voting position is set to 1, and the coordinates of the point are stored in the point cloud pointer corresponding to the voting position.

[0114] S308: When the first voting accumulator contains the angle quantization value, the voting value of the voting position corresponding to the angle quantization value is increased by one, and the coordinates of the point are stored in the point cloud pointer of the corresponding voting position.

[0115] For a point on the plane to be detected, assume that there are some points around it, and a curve can be drawn through these points. For the neighborhood very close to the point, the curve can be approximated as a straight line, and the direction perpendicular to the straight line is the normal of the point. Figure 4 As shown, it is a schematic diagram of the normal direction of a point. Figure 4 A black dot is used to represent a point on the plane, a straight line is used to represent the straight line in its neighborhood, and an arrow is used to represent the normal direction of the point.

[0116] Use i to traverse each point on the plane to be detected and get the normal n of point i i and coordinates p i For the normal direction, its opposite direction also represents the normal direction of the point. To avoid such ambiguity when voting for the normal direction, when the normal direction of a point is obtained, its direction will be adjusted to ensure that its y component is greater than 0.

[0117] Therefore, we need to determine whether the following conditions are met: whether the y-direction component of the normal is less than zero, n i,y <0, if yes, reverse the normal direction.

[0118] Determine the x-direction component n of the normal i,x Is it greater than cos(1°)? If so, the angle between the normal and the positive x-axis = 0. If not, determine the x-direction component n of the normal. i,x Is it less than cos(179°)? If so, the angle between the normal and the positive x-axis is 180°. If not, the angle between the normal and the positive x-axis is acos(n i ,x), where x is the x-axis coordinate of the point.

[0119] Quantize the angle between the normal and the positive direction of the x-axis. The quantization formula is: angle quantization value = int(α / 180*α_num+0.5). The angle quantization value is an integer. α_num ​​represents the resolution of quantization. The larger α_num ​​is, the finer the quantization is. For example, when α_num ​​is equal to 180, it means that α is quantized by 1°.

[0120] Determine whether the first voting accumulator acc_alpha contains the voting position quantized by the angle. If the first voting accumulator acc_alpha does not contain the voting position quantized by the angle, construct the voting position based on the angle quantization value and set the voting value of the voting position to 1, and store the coordinates of the point in the point cloud pointer corresponding to the voting position.

[0121] If the first voting accumulator acc_alpha contains a voting position quantized by angle, the voting value of the voting position corresponding to the angle quantization value is increased by one, and the coordinates of the point are stored in the point cloud pointer of the corresponding voting position until all points on the plane to be detected are traversed to obtain the first voting accumulator.

[0122] There are many ways to implement the second voting accumulator based on the target point cloud pointer. In one implementation, Figure 5 As shown, the following steps are included:

[0123] S401: traverse each target point in the target point cloud pointer.

[0124] Different target point cloud pointers contain multiple target points.

[0125] S402: Determine the coordinates of the target point.

[0126] S403: Calculate the product of the coordinates of the target point and the normal of the line as the inner product of the target point.

[0127] S404: Calculate the voting position of the target point based on the inner product.

[0128] S405: Construct a second voting accumulator based on the voting position and inner product of each target point.

[0129] Use variable j to traverse each target point in the target point cloud pointer cloud and get the coordinates p of point j j , calculate the line normal n l With p j The inner product of l ·p j .

[0130] The voting position b_index of the target point is calculated according to the inner product b, and the calculation formula is as follows: b_index=int(b / b_size+0.5), where b_size represents the quantization step size for quantizing b. The smaller the quantization step size, the finer the quantization.

[0131] Based on the voting position and inner product of each target point, a second voting accumulator is constructed.

[0132] The second voting accumulator has a series of voting positions, each of which stores a value: voting value. The voting value indicates how many times the voting position has voted. The voting position is an integer. The second voting accumulator acc_b is used to record the voting situation of point b on the plane. b is a parameter of the line, indicating the distance from the origin of the coordinate system to the line. The equation of the line is n x ·x+n y y = b, where n x ,ny Represents the normal direction of the line.

[0133] If the second voting accumulator acc_b is not empty, it is necessary to traverse each voting position in the second voting accumulator acc_b to obtain the voting position with the maximum voting value, that is, the voting position with the second maximum voting value. Use max_b_index to represent the voting position with the second maximum voting value. Calculate the corresponding target straight-line distance parameter based on max_b_index. The calculation formula is as follows: target straight-line distance parameter = max_b_index*b_size, max_b_index is the voting position with the second maximum voting value, and b_size is the quantization step size.

[0134] Delete the value at position max_b_index from the second voting accumulator acc_b.

[0135] There are many ways to implement line detection based on line normal and target line distance parameters. In one implementation, Figure 6 As shown, the following steps are included:

[0136] S501: Constructing a straight line to be detected based on the target straight line distance parameter and the straight line normal.

[0137] S502: Traverse the points on the plane to be detected, and calculate the distance between the points and the straight line to be detected.

[0138] S503: Compare the distance between the point and the line to be detected with a preset distance threshold.

[0139] S504: When the distance between the point and the straight line to be detected is less than a preset distance threshold, the label corresponding to the point is stored in the first list.

[0140] S505: Determine the number of points included in the first list.

[0141] S506: When the number is greater than the preset number, it is determined that the straight line to be detected is a straight line.

[0142] Construct the line to be detected based on the target straight line distance parameter and the line normal, traverse each point on the plane to be detected, calculate the distance from each point to the line to be detected, compare the distance from the point on the plane to be detected to the line to be detected with the preset distance threshold, if the distance is less than the preset distance threshold, store the number of the point in the first list line_point_index. Determine whether the number of points in the first list line_point_index is greater than the preset number, if so, determine that the line is detected, and fill the target straight line distance parameter and the line normal as the line parameters into the line list.

[0143] Traverse the first list line_point_index and delete the corresponding points on the plane to be detected according to their labels.

[0144] If the number of points in the first list line_point_index is less than or equal to the preset number, it is determined that no straight line is detected, and the process returns to the step of determining whether the second voting accumulator acc_b is empty.

[0145] Through the above steps, a straight line formed by points on the plane to be detected can be detected, and by adjusting the preset number to a smaller value, a straight line with a small number of points on the plane to be detected can be detected.

[0146] Please refer to Figure 7 The present application embodiment also provides a method for applying Figure 1 The straight line detection device 110 of the electronic device 100 includes:

[0147] A first construction module 111 is used to traverse each point on the plane to be detected, and construct a first voting accumulator based on the normal vector and coordinates of each point, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers, and the point cloud pointers store the coordinates of the points on the plane that vote to the voting position;

[0148] An acquisition module 112, configured to acquire a voting position with a first maximum voting value from the first voting accumulator when the first voting accumulator is not empty;

[0149] A calculation module 113 is used to calculate a first angle based on the voting position of the first maximum voting value; and calculate a normal direction of a straight line based on the first angle;

[0150] The acquisition module 112 is further used to acquire a target point cloud pointer of a voting position of the first maximum voting value;

[0151] A second construction module 114, configured to construct a second voting accumulator based on the target point cloud pointer;

[0152] The acquisition module 112 is further configured to acquire the voting position of the second maximum voting value from the second voting accumulator when the second voting accumulator is not empty;

[0153] The calculation module 113 is further used to calculate a target straight-line distance parameter based on the voting position of the second maximum voting value;

[0154] The line detection module 115 is used to perform line detection based on the line normal and the target line distance parameter.

[0155] The present application also provides an electronic device 100, which includes a processor 130 and a memory 120. The memory 120 stores computer executable instructions, and when the computer executable instructions are executed by the processor 130, the straight line detection method is implemented.

[0156] The embodiment of the present application further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and when the computer program is executed by the processor 130, the straight line detection method is implemented.

[0157] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0158] In addition, each functional module in each embodiment of the present application can be integrated together to form an independent part, or each module can exist separately, or two or more modules can be integrated to form an independent part. If the function is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk.

[0159] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0160] The above are only various implementations of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A straight line detection method, characterized in that: The method comprises: Traversing each point on the plane to be detected, and constructing a first voting accumulator based on the normal vector and coordinates of each point, wherein the first voting accumulator indicates the voting status of the normal of each point on the plane to be detected, and the first voting accumulator includes multiple voting positions, and different voting positions correspond to voting values ​​and point cloud pointers, and the point cloud pointers store the coordinates of the points on the plane that vote to the voting position; When the first voting accumulator is not empty, obtaining a voting position with a first maximum voting value from the first voting accumulator; Calculating a first angle based on the voting position of the first maximum voting value; Calculate the normal direction of the straight line based on the first angle; Obtain a target point cloud pointer of the voting position of the first maximum voting value; Constructing a second voting accumulator based on the target point cloud pointer; When the second voting accumulator is not empty, obtaining the voting position of the second maximum voting value from the second voting accumulator; Calculate the target straight-line distance parameter based on the voting position of the second maximum voting value; Line detection is performed based on the line normal and the target line distance parameter.

2. The method according to claim 1, characterized in that The step of traversing each point on the plane to be detected and constructing a first voting accumulator based on the normal vector and coordinates of each point includes: Traversing each point on the plane to be detected, and determining the normal and coordinates of the point; determining a y-direction component of the normal; When the y-direction component is less than zero, reversing the normal direction; determining an x-direction component of the normal; Determine the angle between the normal and the positive direction of the x-axis based on the x-direction component; quantizing the angle between the normal and the positive direction of the x-axis to obtain a quantized value of the angle; When the first voting accumulator does not contain the angle quantization value, constructing a voting position based on the angle quantization value and setting the voting value of the voting position to 1, and storing the coordinates of the point in the point cloud pointer corresponding to the voting position; When the angle quantization value is included in the first voting accumulator, the voting value of the voting position corresponding to the angle quantization value is increased by one, and the coordinates of the point are stored in the point cloud pointer of the corresponding voting position.

3. The method according to claim 2, characterized in that The step of determining the angle between the normal and the positive direction of the x-axis based on the x-direction component comprises: When the x-direction component is greater than cos1°, determining that the angle between the normal and the positive direction of the x-axis is zero; When the x-direction component is less than cos179°, the angle between the normal and the positive direction of the x-axis is determined to be 180°; When the x-direction component is greater than or equal to cos179°, the angle between the normal and the positive x-axis is determined to be acos(n i ,x), where n i is the normal direction, and x is the x-axis coordinate of the point.

4. The method according to claim 1, characterized in that: The step of calculating the first angle by calculating the voting position of the first maximum voting value by the following formula includes: α=max_alpha_index / α_num×180, where α is the first angle, max_alpha_index is the voting position of the first maximum voting value, and α_num ​​is the quantization resolution.

5. The method according to claim 1, characterized in that The normal direction of the line is calculated by the following formula: n l,x = cos(α), where n l,x is the x-axis component of the normal to the straight line, and α is the first angle; n l,y = sin(α), where n l,y is the y-axis component of the line normal.

6. The method according to claim 1, characterized in that The step of constructing a second voting accumulator based on the target point cloud pointer comprises: Traversing each target point in the target point cloud pointer; determining the coordinates of the target point; Calculate the product of the coordinates of the target point and the normal of the straight line as the inner product of the target point; Based on the inner product, calculating the voting position of the target point; A second voting accumulator is constructed based on the voting position of each target point and the inner product.

7. The method according to claim 6, characterized in that The target straight-line distance parameter is calculated using the following formula: Target straight-line distance parameter = max_b_index*b_size, where max_b_index is the voting position of the second largest voting value, and b_size is the quantization step size.

8. The method according to claim 1, characterized in that: The step of performing straight line detection based on the straight line normal and the target straight line distance parameter comprises: Constructing a straight line to be detected based on the target straight line distance parameter and the straight line normal; Traversing the points on the plane to be detected, and calculating the distance between the points and the straight line to be detected; Comparing the distance between the point and the straight line to be detected with a preset distance threshold; When the distance between the point and the straight line to be detected is less than the preset distance threshold, storing the label corresponding to the point in the first list; Determine the number of points contained in the first list; When the number is greater than a preset number, it is determined that the straight line to be detected is a straight line.

9. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method according to any one of claims 1 to 8 when executing the computer program.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.