Straight line detection method and apparatus, terminal device, and storage medium
By introducing the false alarm value of the Helmholtz principle into line detection, and using the initial line segment in the edge detection image for pixel traversal expansion to calculate the false alarm value, the problems of false detection and slow speed in the existing technology are solved, and fast and accurate line detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHENZHEN SKYWORTH NEW WORLD TECH CO LTD
- Filing Date
- 2022-12-19
- Publication Date
- 2026-05-01
AI Technical Summary
Existing line detection algorithms rely on edge detection performance and accuracy parameters, which can easily lead to false detections and slow detection speed, making it difficult to quickly and accurately detect line information in images in different scenarios.
By introducing the false alarm value from the Helmholtz principle, the initial line segment in the edge detection image is used for pixel traversal expansion, the false alarm value of the expanded line segment is calculated, and the target line segment is determined when the false alarm value is less than a preset threshold.
It enables rapid and error-free detection of straight line information in images under different scenarios, improving the accuracy and speed of detection.
Smart Images

Figure CN115984315B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing technology, and particularly relates to a method, apparatus, terminal device, and computer-readable storage medium for line detection. Background Technology
[0002] With the rapid development of technology, line detection has become one of the core research contents in the field of computer vision, and it has been widely used in many fields.
[0003] Currently, many effective line detection algorithms exist in the field of image processing technology. However, most rely on prior edge detection results and precision parameters. Poor edge detection or unreasonable precision parameter settings can directly lead to line detection failure. Even with good edge detection input, false detections are prone to occur, introducing non-linear results. Most scenarios require real-time image processing, placing certain demands on the algorithm's processing speed. Existing gradient-based line detection methods typically select the largest gradient value from the gradient graph and grow the result along the gradient direction, ultimately selecting the result with a uniform gradient direction as the line. However, this method is slow and suffers from numerous false detections.
[0004] In summary, how to quickly and without introducing errors detect straight line information in images under different scenarios has become a pressing technical problem in the field of image processing technology. Summary of the Invention
[0005] The main objective of this invention is to provide a method, apparatus, terminal device, and computer-readable storage medium for line detection. It aims to achieve rapid and error-free detection of line information in images under different scenarios by introducing false alarm values based on the Helmholtz principle.
[0006] To achieve the above objectives, the present invention provides a line detection method, the line detection method comprising:
[0007] Edge detection processing is performed on the original image to obtain an edge-detected image;
[0008] The initial line segment in the edge detection image is determined, and the initial line segment is expanded by pixel traversal to obtain the expanded line segment;
[0009] Based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the false alarm value corresponding to the extended line segment is calculated, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range;
[0010] When the false alarm value is less than a preset threshold, the extended line segment is determined to be the target line segment.
[0011] Optionally, the step of determining the initial line segment in the edge detection image includes:
[0012] The edge detection image is fitted with a straight line using the least squares method to obtain a fitted line segment.
[0013] When the length of the fitted line segment is greater than or equal to a preset length, the fitted line segment is determined to be the initial line segment in the edge detection image.
[0014] Optionally, the step of performing pixel traversal expansion on the initial line segment to obtain an expanded line segment includes:
[0015] Multiple pixels on the initial line segment are identified as the first pixel.
[0016] Pixels that are less than a preset distance from the first pixel and are not on the initial line segment are designated as the second pixel.
[0017] The second pixel is connected to the initial line segment to obtain the extended line segment.
[0018] Optionally, before the step of calculating the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the method further includes:
[0019] Calculate the gradient intensity of each pixel point on the extended line segment;
[0020] Based on the multiple gradient intensities, the gradient direction corresponding to each of the multiple pixels on the extended line segment is calculated respectively.
[0021] Optionally, the step of calculating the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment includes:
[0022] Calculate the average gradient direction of the extended line segment based on the gradient directions of each pixel point on the extended line segment;
[0023] Based on the multiple gradient directions and the average gradient direction, normal pixels and abnormal pixels are determined among the multiple pixels on the extended line segment.
[0024] Based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment, the false alarm value corresponding to the extended line segment is calculated.
[0025] Optionally, the step of determining normal and abnormal pixels among multiple pixels on the extended line segment based on multiple gradient directions and the average gradient direction includes:
[0026] Calculate the angle difference between the gradient direction and the average gradient direction respectively;
[0027] When the angle difference is within the preset range, the pixel corresponding to the angle difference is determined to be the normal pixel.
[0028] When the angle difference is not within the preset range, the pixel corresponding to the angle difference is determined to be the abnormal pixel.
[0029] Optionally, after determining the extended line segment as the target line segment when the false alarm value is less than a preset threshold, the method further includes:
[0030] Output the target line segment, and generate a target image corresponding to the original image based on the target line segment.
[0031] Furthermore, to achieve the above objectives, the present invention also provides a line detection device, the line detection device comprising:
[0032] The edge detection module performs edge detection processing on the original image to obtain an edge-detected image;
[0033] The line segment extension module determines the initial line segment in the edge detection image and performs pixel traversal extension on the initial line segment to obtain the extended line segment;
[0034] The false alarm value module calculates the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range;
[0035] The target line segment module determines the extended line segment as the target line segment when the false alarm value is less than a preset threshold.
[0036] In addition, to achieve the above objectives, the present invention also provides a terminal device, the terminal device comprising: a memory, a processor, and a line detection program stored in the memory and executable on the processor, wherein the line detection program of the terminal device, when executed by the processor, implements the steps of the line detection method as described above.
[0037] In addition, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a line detection program, which, when executed by a processor, implements the steps of the line detection method as described above.
[0038] This invention provides a line detection method, apparatus, terminal device, and computer-readable storage medium. The method involves performing edge detection processing on an original image to obtain an edge detection image; determining an initial line segment in the edge detection image and performing pixel traversal expansion on the initial line segment to obtain an expanded line segment; calculating a false alarm value corresponding to the expanded line segment based on the gradient direction corresponding to each of multiple pixels on the expanded line segment, wherein the false alarm value is the expected value of pixels on the expanded line segment whose gradient direction is within a preset range; and determining the expanded line segment as the target line segment when the false alarm value is less than a preset threshold.
[0039] This invention employs an arbitrary edge detection method to process the original image, obtaining an edge-detected image. Then, an initial line segment is identified within the edge-detected image, and this initial line segment is expanded by pixel traversal, i.e., traversing pixels around the initial line segment to obtain an expanded line segment. Based on the gradient direction of each pixel on the expanded line segment, a false alarm value is calculated. The false alarm value is the expected value of pixels whose gradient direction on the expanded line segment is within a preset range. Furthermore, if the false alarm value is less than a preset threshold, the expanded line segment is determined to be the final target line segment. Thus, by introducing the false alarm value from the Helmholtz principle, this invention achieves rapid and error-free detection of straight-line information in images under different scenarios. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the device structure of the terminal device hardware operating environment involved in the embodiments of the present invention;
[0041] Figure 2 This is a schematic flowchart of the first embodiment of the line detection method of the present invention;
[0042] Figure 3 This is a schematic diagram of the original image involved in an embodiment of the line detection method of the present invention;
[0043] Figure 4 This is a schematic diagram of an edge detection image involved in an embodiment of the line detection method of the present invention;
[0044] Figure 5 This is a schematic diagram of an image after least squares line fitting, as described in an embodiment of the line detection method of the present invention.
[0045] Figure 6 This is a schematic diagram of the final output target image according to an embodiment of the line detection method of the present invention;
[0046] Figure 7 This is a functional module diagram of an embodiment of the line detection device of the present invention;
[0047] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0048] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
[0049] Reference Figure 1 , Figure 1 This is a schematic diagram of the hardware operating environment of the terminal device involved in the embodiment of the present invention.
[0050] The terminal device in this embodiment of the invention can be a terminal device applied in the field of image processing technology. Specifically, the terminal device can be a smartphone, PC (Personal Computer), tablet computer, portable computer, etc.
[0051] like Figure 1 As shown, the terminal device may include: a processor 1001, such as a CPU; a communication bus 1002; a user interface 1003; a network interface 1004; and a memory 1005. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard. Optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM or a non-volatile memory, such as a disk drive. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0052] Those skilled in the art will understand that Figure 1 The terminal device structure shown does not constitute a limitation on the terminal device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0053] like Figure 1 As shown, the memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and a line detection program.
[0054] exist Figure 1In the terminal shown, network interface 1004 is mainly used to connect to the backend server and communicate data with it; user interface 1003 is mainly used to connect to the client and communicate data with it; and processor 1001 can be used to call the line detection program stored in memory 1005 and perform the following operations:
[0055] Edge detection processing is performed on the original image to obtain an edge-detected image;
[0056] The initial line segment in the edge detection image is determined, and the initial line segment is expanded by pixel traversal to obtain the expanded line segment;
[0057] Based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the false alarm value corresponding to the extended line segment is calculated, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range;
[0058] When the false alarm value is less than a preset threshold, the extended line segment is determined to be the target line segment.
[0059] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005 and perform the following operations:
[0060] The edge detection image is fitted with a straight line using the least squares method to obtain a fitted line segment.
[0061] When the length of the fitted line segment is greater than or equal to a preset length, the fitted line segment is determined to be the initial line segment in the edge detection image.
[0062] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005 and perform the following operations:
[0063] Multiple pixels on the initial line segment are identified as the first pixel.
[0064] Pixels that are less than a preset distance from the first pixel and are not on the initial line segment are designated as the second pixel.
[0065] The second pixel is connected to the initial line segment to obtain the extended line segment.
[0066] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005, and before the step of calculating the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the following operation is also performed:
[0067] Calculate the gradient intensity of each pixel point on the extended line segment;
[0068] Based on the multiple gradient intensities, the gradient direction corresponding to each of the multiple pixels on the extended line segment is calculated respectively.
[0069] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005 and perform the following operations:
[0070] Calculate the average gradient direction of the extended line segment based on the gradient directions of each pixel point on the extended line segment;
[0071] Based on the multiple gradient directions and the average gradient direction, normal pixels and abnormal pixels are determined among the multiple pixels on the extended line segment.
[0072] Based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment, the false alarm value corresponding to the extended line segment is calculated.
[0073] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005 and perform the following operations:
[0074] Calculate the angle difference between the gradient direction and the average gradient direction respectively;
[0075] When the angle difference is within the preset range, the pixel corresponding to the angle difference is determined to be a normal pixel.
[0076] When the angle difference is not within the preset range, the pixel corresponding to the angle difference is determined to be the abnormal pixel.
[0077] Optionally, the processor 1001 can also be used to call a line detection program stored in the memory 1005, and after determining that the extended line segment is the target line segment when the false alarm value is less than a preset threshold, perform the following operations:
[0078] Output the target line segment, and generate a target image corresponding to the original image based on the target line segment.
[0079] Based on the aforementioned terminal devices, various embodiments of the line detection method of the present invention are proposed.
[0080] Currently, many effective line detection algorithms exist in the field of line detection technology. However, most rely on prior edge detection performance and precision parameters. Poor edge detection or unreasonable precision parameter settings can directly lead to line detection failure. Even with good edge detection input, false detections are prone to occur, introducing non-linear results. Most scenarios require real-time image processing, placing certain demands on the algorithm's processing speed. Existing gradient-based line detection methods typically select the largest gradient value from the gradient graph and grow along the gradient direction, ultimately selecting the result with a uniform gradient direction as the line. However, this method is slow and suffers from numerous false detections.
[0081] To address the aforementioned issues, this invention proposes a line detection method. This method performs edge detection processing on the original image using an arbitrary edge detection method to obtain an edge detection image. Then, it identifies an initial line segment within the edge detection image and expands this initial line segment by traversing pixels around it, thus obtaining an expanded line segment. Based on the gradient direction of each pixel on this expanded line segment, a false alarm value is calculated. This false alarm value is the expected value of pixels whose gradient direction falls within a preset range on the expanded line segment. Furthermore, if the false alarm value is less than a preset threshold, the expanded line segment is determined to be the final target line segment. Thus, by introducing the false alarm value from the Helmholtz principle, this invention achieves rapid and error-free detection of line information in images under different scenarios.
[0082] Please refer to Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the line detection method of the present invention. It should be noted that although the logical order is shown in the flowchart, in certain situations, the line detection method of the present invention may, of course, execute the steps shown or described in a different order than that shown here.
[0083] In a first embodiment of the line detection method of the present invention, the line detection method includes:
[0084] Step S10: Perform edge detection processing on the original image to obtain an edge-detected image;
[0085] In this embodiment, edge detection processing is performed on the original image data to obtain an edge-detected image.
[0086] For example, in application scenarios across various fields, any 2D image from the application scenario is acquired as the original image, such as... Figure 3 The image shown is the original image in this embodiment. The terminal device performs edge detection on the input original image using common arbitrary edge detection methods to obtain the image after edge detection processing, i.e., the edge-detected image. For details, please refer to the appendix. Figure 4 .
[0087] It should be noted that the edge detection method used in this invention can be OBE L, LAP LACIAN, CANNY, etc. It should be understood that, based on different design needs of actual applications, the edge detection method can be any available edge detection method in different feasible implementations. The line detection method of this invention is not limited to any edge detection method. That is to say, the line detection method of this invention is compatible with any edge detection method.
[0088] Step S20: Determine the initial line segment in the edge detection image, and perform pixel traversal expansion on the initial line segment to obtain the expanded line segment;
[0089] In this embodiment, the terminal device determines the initial line segment in the edge detection image and performs pixel traversal expansion on the initial line segment to obtain the expanded line segment, i.e., the expanded line segment.
[0090] Furthermore, in a feasible embodiment, step S20 above, the step of "determining the initial line segment in the edge detection image", includes:
[0091] Step S201: Perform line fitting processing on the edge detection image based on the least squares method to obtain the fitted line segment;
[0092] Step S202: When the length of the fitted line segment is greater than or equal to a preset length, the fitted line segment is determined to be the initial line segment in the edge detection image.
[0093] In this embodiment, the terminal device performs line fitting on the pixels in the edge detection image based on the least squares method to obtain the fitted line segment generated after line fitting in the edge detection image. When the length of the fitted line segment is greater than or equal to a preset length, the fitted line segment is determined to be the initial line segment.
[0094] For example, the terminal device performs least squares line fitting on the edge detection image using the least squares method to obtain multiple fitted line segments, i.e., fitted line segments, and uses the image generated at this time as a reference. Figure 5 The image shown is the result of extracting and fitting the line segments. Then, a line segment reaching a preset length is selected from multiple fitted line segments as the initial line segment, where the preset length is l. min Let N be the smaller of the width and height dimensions of the input image, and let the preset length be calculated using the formula: l min = 4log(N*8).
[0095] Furthermore, in a feasible embodiment, step S20 above, the step of "performing pixel traversal expansion of the initial line segment to obtain an expanded line segment" includes:
[0096] Step S203: Determine multiple pixels on the initial line segment as the first pixel;
[0097] Step S204: Pixels that are less than a preset distance from the first pixel and are not on the initial line segment are designated as second pixels;
[0098] Step S205: Connect the second pixel to the initial line segment to obtain the extended line segment.
[0099] In this embodiment, the terminal device determines multiple pixels on the initial line segment as first pixels, and identifies pixels that are less than a preset distance from the first pixels and are not on the initial line segment as second pixels. Finally, the second pixels are connected to the initial line segment to obtain the line segment after pixel traversal expansion, i.e., the expanded line segment.
[0100] For example, the terminal device iterates through pixels around an initial line segment. When a pixel in the surrounding area meets the distance requirement, it adds that pixel to the initial line segment. This process continues until the line segment encounters three pixels that do not meet the distance requirement, at which point the expansion of the initial line segment stops. The distance requirement is that the distance between the surrounding pixels and the pixels on the initial line segment is less than one pixel. When the expansion of each initial line segment stops, the device outputs the longest line segment that has been reached, i.e., the expanded line segment.
[0101] Step S30: Based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, calculate the false alarm value corresponding to the extended line segment, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range;
[0102] In this embodiment, the terminal device calculates the false alarm value corresponding to the extended line segment based on the gradient direction of each pixel on the extended line segment. The false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range.
[0103] For example, firstly, the gradient direction of each pixel on the extended line segment is calculated, and the false alarm value corresponding to the extended line segment is calculated based on each gradient direction. The false alarm value can also be called the false alarm value or NFA (Number of False Alarms). The NFA of an event is the expected number of times the event occurs.
[0104] It should be noted that the Helmholtz principle states that the expected randomness of the composition of meaningful and perceived structures in an image is very low. That is, if the detected line has multiple points that do not conform to the gradient strength and direction of the line, then it is a false detection and not a line. Specifically, a general variable applicable to many detection problems is introduced, namely the false alarm value (NFA). The line detection method of this invention is based on the Helmholtz principle to eliminate erroneous detection results.
[0105] Step S40: When the false alarm value is less than a preset threshold, the extended line segment is determined to be the target line segment.
[0106] In this embodiment, when the terminal device detects that the false alarm value corresponding to the extended line segment is less than a preset threshold, it determines that the extended line segment is the target line segment to be finally output.
[0107] For example, the terminal device detects the magnitude of false alarms based on the Helmholtz principle. When the false alarm value is less than 1, it is considered that the point conforming to the straight line law exceeds the naturally formed threshold, and the line segment is retained as the final output straight line, i.e., the target line segment. Otherwise, it is a falsely detected straight line.
[0108] Furthermore, in a feasible embodiment, after step S40 above, the line detection method of the present invention may further include:
[0109] Step A: Output the target line segment and generate a target image corresponding to the original image based on the target line segment.
[0110] In this embodiment, the terminal device outputs the finally determined target line segment and generates a target image corresponding to the original image based on the target line segment.
[0111] For example, such as Figure 6 As shown, the final image, i.e. the target image, is composed of the finally determined real line segments.
[0112] In this embodiment, the line detection method of the present invention performs edge detection processing on the original image data to obtain an edge detection image; the terminal device performs line fitting processing on the pixels in the edge detection image based on the least squares method to obtain a fitted line segment generated after line fitting in the edge detection image, and determines the fitted line segment as the initial line segment when the length of the fitted line segment is greater than or equal to a preset length; the terminal device determines multiple pixels on the initial line segment as first pixels, and pixels whose distance from the first pixels is less than a preset distance and are not on the initial line segment as second pixels; finally, the second pixels are connected to the initial line segment to obtain the line segment after pixel traversal expansion, i.e., the expanded line segment; the terminal device calculates the false alarm value corresponding to the expanded line segment based on the gradient direction of each pixel on the expanded line segment; when the terminal device detects that the false alarm value corresponding to the expanded line segment is less than a preset threshold, it determines that the expanded line segment is the final output target line segment; the terminal device outputs the finally determined target line segment and generates the target image corresponding to the original image based on the target line segment.
[0113] Thus, this embodiment of the invention performs edge detection processing on the original image using an arbitrary edge detection method to obtain an edge detection image. Then, an initial line segment in the edge detection image is determined, and this initial line segment is expanded by pixel traversal, that is, traversing pixels around the initial line segment to obtain an expanded line segment. Based on the gradient direction of each pixel on the expanded line segment, the false alarm value of the expanded line segment is calculated. The false alarm value is the expected value of pixels on the expanded line segment whose gradient direction is within a preset range. When the false alarm value is less than a preset threshold, the expanded line segment is determined to be the final target line segment to be retained. In this way, by introducing the false alarm value in the Helmholtz principle, this invention achieves fast and error-free detection of straight line information in images under different scenes.
[0114] Furthermore, based on the first embodiment of the line detection method of the present invention described above, a second embodiment of the line detection method of the present invention is proposed.
[0115] In this embodiment, before step S30, the line detection method of the present invention may further include:
[0116] Step B: Calculate the gradient intensity corresponding to each of the multiple pixels on the extended line segment;
[0117] Step C: Based on the multiple gradient intensities, calculate the gradient direction corresponding to each of the multiple pixels on the extended line segment.
[0118] In this embodiment, the terminal device calculates the gradient intensity of each pixel on the extended line segment, and then calculates the gradient direction of each pixel based on multiple gradient intensities.
[0119] For example, the terminal device calculates the gradient intensity and gradient direction corresponding to each pixel on each extended line segment:
[0120]
[0121]
[0122]
[0123] Where x and y represent the horizontal and vertical coordinates of the image, respectively, g(x,y) is the gradient intensity at the corresponding point, I(x,y) is the pixel value at the corresponding point, and angle(x,y) is the horizontal angle at the corresponding point.
[0124] Furthermore, in a feasible embodiment, step S30 above may include:
[0125] Step S301: Calculate the average gradient direction of the extended line segment based on the gradient directions corresponding to each of the multiple pixels on the extended line segment.
[0126] Step S302: Based on the multiple gradient directions and the average gradient direction, determine the normal pixels and abnormal pixels among the multiple pixels on the extended line segment;
[0127] Step S303: Calculate the false alarm value corresponding to the extended line segment based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment.
[0128] In this embodiment, firstly, the terminal device calculates the average gradient direction of the extended line segment based on the gradient directions corresponding to each of the multiple pixels on the extended line segment. Then, based on the gradient directions corresponding to each of the multiple pixels and the average gradient direction, it determines the normal pixels and abnormal pixels among the pixels on the extended line segment. Finally, based on the number of normal pixels and abnormal pixels and the length of the extended line segment, it calculates the false alarm value corresponding to the extended line segment.
[0129] For example, suppose each extended line segment of length N has n pixels, of which k pixels are aligned (normal pixels) and nk pixels are misaligned. Then the false alarm value of the extended line segment is calculated as follows:
[0130]
[0131] Here, p is a constant value, set to an empirical value of 0.125. It should be noted that the line detection method of this invention does not limit the magnitude of this probability value p. It can be understood that the smaller the false alarm value of the extended line segment, the higher the accuracy of the extended line segment.
[0132] Furthermore, in a feasible embodiment, step S302 above may include:
[0133] Step D: Calculate the angle difference between the gradient direction and the average gradient direction respectively;
[0134] Step E: When the angle difference is within the preset range, determine the pixel corresponding to the angle difference as the normal pixel.
[0135] Step F: When the angle difference is not within the preset range, determine the pixel corresponding to the angle difference as the abnormal pixel.
[0136] In this embodiment, the terminal device calculates the angle difference between the gradient direction and the average gradient direction of the pixel on the extended line segment, and determines whether the angle difference is within a preset range. When the angle difference is within the preset range, the pixel corresponding to the angle difference is determined to be a normal pixel. When the angle difference is not within the preset range, the pixel corresponding to the angle difference is determined to be an abnormal pixel.
[0137] For example, after obtaining the average gradient direction of each extended line segment, the terminal device traverses each pixel on the extended line segment. If the gradient angle difference between the gradient direction of a pixel and the average gradient direction is less than 22.5°, it is considered an aligned point, i.e., a normal pixel; otherwise, it is considered an abnormal point. The preset angle difference of 22.5° is an empirical value. It should be noted that the line detection method of this invention does not limit the magnitude of the preset angle difference.
[0138] In this embodiment, the line detection method of the present invention calculates the gradient intensity of each pixel on the extended line segment using a terminal device, and then calculates the gradient direction of each pixel based on multiple gradient intensities. The terminal device calculates the average gradient direction of the extended line segment based on the gradient directions of the pixels on the extended line segment, and determines the normal and abnormal pixels among the pixels on the extended line segment based on the gradient directions of the pixels on the extended line segment and the average gradient direction. Finally, based on the number of normal and abnormal pixels and the length of the extended line segment, the false alarm value corresponding to the extended line segment is calculated. The terminal device calculates the angle difference between the gradient direction and the average gradient direction of each pixel on the extended line segment, and determines whether the angle difference is within a preset range. If the angle difference is within the preset range, the pixel corresponding to the angle difference is determined to be a normal pixel; if the angle difference is not within the preset range, the pixel corresponding to the angle difference is determined to be an abnormal pixel.
[0139] In this way, by calculating the gradient direction of each pixel on each extended line segment, the false alarm value of each extended line segment is calculated, thereby filtering out erroneous detected lines and retaining the true lines based on the false alarm value.
[0140] In addition, embodiments of the present invention also provide a straight line detection device.
[0141] Please refer to Figure 7 , Figure 7 This is a functional module diagram of an embodiment of the line detection device of the present invention, as shown below. Figure 7 As shown, the linear detection device of the present invention includes:
[0142] Edge detection module 10 is used to perform edge detection processing on the original image to obtain an edge detection image;
[0143] The line segment extension module 20 is used to determine the initial line segment in the edge detection image and perform pixel traversal extension on the initial line segment to obtain the extended line segment;
[0144] The false alarm value module 30 is used to calculate the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range;
[0145] The target line segment module 40 is used to determine the extended line segment as the target line segment when the false value is less than a preset threshold.
[0146] Optionally, the line segment extension module 20 also includes:
[0147] The line fitting unit is used to perform line fitting processing on the edge detection image based on the least squares method to obtain the fitted line segment;
[0148] An initial line segment unit is used to determine the fitted line segment as the initial line segment in the edge detection image when the length of the fitted line segment is greater than or equal to a preset length.
[0149] Optionally, the line segment extension module 20 also includes:
[0150] The first pixel unit is used to determine multiple pixels on the initial line segment as the first pixel;
[0151] The second pixel unit is used to identify pixels that are less than a preset distance from the first pixel and are not on the initial line segment as second pixels.
[0152] An extended line segment unit is used to connect the second pixel point with the initial line segment to obtain the extended line segment.
[0153] Optionally, the line detection device of the present invention further includes:
[0154] The gradient intensity module is used to calculate the gradient intensity of each pixel point on the extended line segment.
[0155] The gradient direction module is used to calculate the gradient direction corresponding to each of the multiple pixels on the extended line segment based on the multiple gradient intensities.
[0156] Optionally, the false value module 30 includes:
[0157] The average gradient direction unit is used to calculate the average gradient direction of the extended line segment based on the gradient directions corresponding to each of the multiple pixels on the extended line segment.
[0158] A pixel determination unit is used to determine normal pixels and abnormal pixels among multiple pixels on the extended line segment based on multiple gradient directions and the average gradient direction.
[0159] The false alarm value unit is used to calculate the false alarm value corresponding to the extended line segment based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment.
[0160] Optionally, the pixel determination unit is further configured to calculate the angle difference between the gradient direction and the average gradient direction respectively; when the angle difference is within a preset range, determine the pixel corresponding to the angle difference as the normal pixel; when the angle difference is not within the preset range, determine the pixel corresponding to the angle difference as the abnormal pixel.
[0161] Optionally, the line detection device of the present invention further includes:
[0162] The target image module is used to output the target line segment and generate a target image corresponding to the original image based on the target line segment.
[0163] The present invention also provides a computer storage medium storing a line detection program, wherein when the line detection program is executed by a processor, it implements the steps of the line detection program method as described in any of the above embodiments.
[0164] The specific embodiments of the computer storage medium of the present invention are basically the same as the embodiments of the linear detection program method of the present invention described above, and will not be repeated here.
[0165] The present invention also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the line detection method of the present invention as described in any of the above embodiments, which will not be repeated here.
[0166] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system 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 system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0167] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0168] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (such as TWS earphones, etc.) to execute the methods described in the various embodiments of the present invention.
[0169] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.
Claims
1. A straight line detection method characterized by, The line detection method includes: Edge detection processing is performed on the original image to obtain an edge-detected image; An initial line segment is determined in the edge detection image, and multiple pixels on the initial line segment are determined as first pixels; Pixels that are less than a preset distance from the first pixel and are not on the initial line segment are designated as the second pixel. Connect the second pixel to the initial line segment to obtain the extended line segment; Based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the false alarm value corresponding to the extended line segment is calculated, wherein the false alarm value is the expected value of the pixels on the extended line segment whose gradient direction is within a preset range; When the false alarm value is less than a preset threshold, the extended line segment is determined to be the target line segment; The step of calculating the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment includes: Based on the gradient directions corresponding to each of the multiple pixels on the extended line segment, calculate the average gradient direction of the extended line segment; Based on the multiple gradient directions and the average gradient direction, normal pixels and abnormal pixels are determined among the multiple pixels on the extended line segment. Based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment, the false alarm value corresponding to the extended line segment is calculated.
2. The straight line detection method as described in claim 1, characterized in that, The step of determining the initial line segment in the edge detection image includes: The edge detection image is fitted with a straight line using the least squares method to obtain a fitted line segment. When the length of the fitted line segment is greater than or equal to a preset length, the fitted line segment is determined to be the initial line segment in the edge detection image.
3. The straightness detection method of claim 1, wherein Before the step of calculating the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, the method further includes: Calculate the gradient intensity of each pixel point on the extended line segment; Based on the multiple gradient intensities, the gradient direction corresponding to each of the multiple pixels on the extended line segment is calculated respectively.
4. The straightness detection method of claim 1, wherein The step of determining normal and abnormal pixels among multiple pixels on the extended line segment based on multiple gradient directions and the average gradient direction includes: Calculate the angle difference between the gradient direction and the average gradient direction respectively; When the angle difference is within the preset range, the pixel corresponding to the angle difference is determined to be the normal pixel. When the angle difference is not within the preset range, the pixel corresponding to the angle difference is determined to be the abnormal pixel.
5. The straight line detection method as described in claim 1, characterized in that, After determining the extended line segment as the target line segment when the false alarm value is less than a preset threshold, the method further includes: Output the target line segment, and generate a target image corresponding to the original image based on the target line segment.
6. A straightness detecting device characterized by comprising: The straight line detection device includes: The edge detection module performs edge detection processing on the original image to obtain an edge-detected image; The line segment extension module determines an initial line segment in the edge detection image and identifies multiple pixels on the initial line segment as first pixels; it identifies pixels whose distance from the first pixels is less than a preset distance and which are not on the initial line segment as second pixels; and it connects the second pixels to the initial line segment to obtain an extended line segment. The false alarm value module calculates the false alarm value corresponding to the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment, wherein the false alarm value is the expected value of pixels on the extended line segment whose gradient direction is within a preset range; calculates the average gradient direction of the extended line segment based on the gradient direction corresponding to each of the multiple pixels on the extended line segment; determines the normal pixels and abnormal pixels among the multiple pixels on the extended line segment based on the multiple gradient directions and the average gradient direction; and calculates the false alarm value corresponding to the extended line segment based on the number of normal pixels, the number of abnormal pixels, and the length of the extended line segment. The target line segment module determines the extended line segment as the target line segment when the false alarm value is less than a preset threshold.
7. A terminal device, characterized in that, The terminal device includes: a memory, a processor, and a line detection program stored in the memory and executable on the processor, wherein the line detection program, when executed by the processor, implements the steps of the line detection method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a line detection program, which, when executed by a processor, implements the steps of the line detection method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Rural road network matching technology based on extended line segment
CN109325156A
Image-based straight line detection method and device, and electronic equipment
CN111080661A