Line detection methods and devices, chips, equipment, and storage media

By recording the step-by-step data of lines and the detection rules, the problem of insufficient accuracy in line feature detection is solved, the accuracy of line detection is improved, and the application performance in related fields is enhanced.

CN115713743BActive Publication Date: 2026-05-05伟光有限公司(CN)
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
伟光有限公司(CN)
Filing Date
2022-11-23
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

Existing line feature detection algorithms suffer from insufficient accuracy in the image domain, affecting their performance in applications such as autonomous driving, urban mapping, augmented reality, and computer vision.

Method used

By recording the step-by-step data of the lines, including the starting coordinates, the first direction marker, and the second direction marker, the line type and detection direction are determined, and the corresponding detection rules are used to detect the lines, thereby improving the detection accuracy.

Benefits of technology

It achieves more accurate line detection results, improving the performance of applications in fields such as autonomous driving, urban mapping, augmented reality, and computer vision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115713743B_ABST
    Figure CN115713743B_ABST
Patent Text Reader

Abstract

This application provides a line detection method, apparatus, chip, device, and storage medium. The method includes: determining that a step record exists between the current pixel and its preceding neighboring pixels in a different row; the current pixel and the preceding neighboring pixels with the step record are edge pixels, the step record including at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating that the line type is a first type, and the second direction marker indicating the current detection direction of the line; determining the target pixel of the line from the current pixel and the next row of pixels based on the step record and the positional relationship between the preceding neighboring pixels with the step record and the current pixel; the target pixel is an edge pixel; based on determining that the target pixel is the end point of the line, at least the starting coordinates and the end coordinates of the line are output; thus, a more accurate line detection result can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to image processing technology, including but not limited to line detection methods and apparatus, chips, devices, and storage media. Background Technology

[0002] Line feature detection algorithms are widely used in image processing. Detected line features (such as line segments) serve as underlying operators for subsequent algorithms and have potential applications in multiple fields. For example, line features are used for face distortion correction, line feature tracking and matching, or three-dimensional (3D) feature reconstruction. Compared to point features, line features possess stronger local invariance and scale robustness. In recent years, line feature extraction has become a crucial algorithmic direction in fields such as autonomous driving laser and visual navigation, urban mapping, augmented reality (AR) / virtual reality (VR), and computer vision (CV). Furthermore, more accurate line features are beneficial for improving application performance. Summary of the Invention

[0003] In view of this, the line detection method, apparatus, chip, device, and storage medium provided in this application can obtain more accurate line detection results, thereby improving the performance of application scenarios based on line features.

[0004] In a first aspect, embodiments of this application provide a line detection method, comprising: determining a target pixel to be added to the line from the current pixel and the next row of pixels, based on a step record of a preceding neighboring pixel not in the same row as the current pixel and the positional relationship between the preceding neighboring pixel having the step record and the current pixel; the target pixel being an edge pixel; and outputting at least the start coordinates and end coordinates of the line based on determining that the target pixel is the end point of the line; wherein the current pixel and the preceding neighboring pixel having the step record are edge pixels, and the step record includes at least the start coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating that the line type is a first type, and the second direction marker indicating the current detection direction of the line;

[0005] In this way, by recording the step sequence, it is possible to determine whether the line being detected is of the first type or the second type (i.e., the first direction marker); when performing line growth (i.e. line detection), it is determined whether to use the detection rule for the second type of line or the detection rule for the first type of line based on the first direction marker; thus, more accurate line detection results can be obtained, which is beneficial to improving the performance of application scenarios based on line features.

[0006] Secondly, embodiments of this application provide another line detection method, including: when the horizontal left neighbor and / or horizontal right neighbor of the current pixel are non-edge pixels, determining whether the current pixel should be added as the target pixel of the line based on the step record of the preceding neighbor pixel that is not in the same row as the current pixel and the positional relationship between the preceding neighbor pixel with the step record and the current pixel; based on the determination that the current pixel should be added as the target pixel and the line termination condition is met, taking the current pixel as the end point of the line, and outputting the starting point coordinates and ending point coordinates of the line; wherein the current pixel and the preceding neighbor pixel with the step record are edge pixels, and the step record includes at least the starting point coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a second type, and the second direction mark indicating the current detection direction of the line.

[0007] Thirdly, embodiments of this application provide yet another line detection method, comprising: performing a step in a method for detecting lines of the first type based on a first direction marker indicating that the line type of the line is a first type, based on a step record of a preceding neighboring pixel that is not in the same row as the current pixel; and performing a step in a method for detecting lines of the second type based on the first direction marker indicating that the line type of the line is a second type; wherein the current pixel and the preceding neighboring pixel having the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating the line type of the line, and the second direction marker indicating the current detection direction of the line.

[0008] Fourthly, embodiments of this application provide a line detection device, comprising: a first determining module configured to determine a target pixel to be added to the line from the current pixel and the next row of pixels based on a step record of a preceding neighboring pixel not in the same row as the current pixel, and the positional relationship between the preceding neighboring pixel having the step record and the current pixel; the target pixel is an edge pixel; wherein the current pixel and the preceding neighboring pixel having the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating that the line type is a first type, and the second direction marker indicating the current detection direction of the line; and a first output module configured to output at least the starting coordinates and the ending coordinates of the line based on determining that the target pixel is the ending point of the line.

[0009] Fifthly, embodiments of this application provide another line detection device, comprising: a second determining module configured to, when the horizontal left adjacent pixel and / or horizontal right adjacent pixel of the current pixel are non-edge pixels, determine whether the current pixel should be added as the target pixel of the line based on the step record of the preceding adjacent pixel not in the same row as the current pixel and the positional relationship between the preceding adjacent pixel having the step record and the current pixel; wherein the current pixel and the preceding adjacent pixel having the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a second type, and the second direction mark indicating the current detection direction of the line; and a second output module, based on determining that the current pixel should be added as the target pixel and satisfying the line termination condition, taking the current pixel as the end point of the line, and outputting the starting coordinates and end coordinates of the line.

[0010] Sixthly, embodiments of this application provide a chip, including a processor and a memory; wherein the processor is configured to execute the line detection method described in embodiments of this application; and the memory is configured to store input data and output data required by the processor during the execution of the line detection method.

[0011] In a seventh aspect, embodiments of this application provide an electronic device, including a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the program to implement the methods described in embodiments of this application.

[0012] Eighthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the methods described in embodiments of this application.

[0013] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0014] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application. Obviously, the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0015] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0016] Figure 1A A schematic diagram illustrating the implementation process of the line detection method provided in this application embodiment;

[0017] Figure 1B This is a conceptual diagram of an edge image;

[0018] Figure 2 A schematic diagram illustrating the positional relationship between the current pixel and the preceding adjacent pixels and the following adjacent pixels, provided in an embodiment of this application.

[0019] Figure 3 This is a schematic diagram of the pixel scene where the current pixel is located, provided in an embodiment of this application.

[0020] Figure 4 This is a schematic diagram illustrating the positional relationship between the current pixel and its preceding neighboring pixel with step records, provided in an embodiment of this application.

[0021] Figure 5 This is a partial implementation flowchart of the line detection method provided in the embodiments of this application;

[0022] Figure 6 This is a partial implementation flowchart of the line detection method provided in the embodiments of this application;

[0023] Figure 7 This is a schematic diagram of the pixel scene where the current pixel is located, provided in an embodiment of this application.

[0024] Figure 8 This is a partial implementation flowchart of the line detection method provided in the embodiments of this application;

[0025] Figure 9A schematic diagram illustrating the implementation process of the line detection method provided in this application embodiment;

[0026] Figure 10 A schematic diagram illustrating the generation rules of step records in horizontal line detection provided in an embodiment of this application;

[0027] Figure 11 A schematic diagram illustrating the surrounding pixels of the current pixel in horizontal line detection provided in an embodiment of this application;

[0028] Figure 12 This is an example diagram illustrating that the scene where the current pixel is located belongs to type A, as provided in the embodiments of this application.

[0029] Figure 13 This is another example diagram illustrating that the scene where the current pixel is located belongs to type A, as provided in the embodiments of this application.

[0030] Figure 14 This is another example of a scene belonging to type A, provided in an embodiment of this application.

[0031] Figure 15 This is another example of a scenario where the current pixel belongs to type A, as provided in the embodiments of this application.

[0032] Figure 16 A schematic diagram of growth rules for an example of a scene where the current pixel belongs to type B, provided in an embodiment of this application;

[0033] Figure 17 A schematic diagram of growth rules for an example of a scene where the current pixel belongs to type B, provided in an embodiment of this application;

[0034] Figure 18 A schematic diagram of growth rules for an example of a scene where the current pixel belongs to type B, provided in an embodiment of this application;

[0035] Figure 19 A schematic diagram of growth rules for an example of a scene where the current pixel belongs to type B, provided in an embodiment of this application;

[0036] Figure 20 A schematic diagram of growth rules for an example of a scene where the current pixel belongs to type B, provided in an embodiment of this application;

[0037] Figure 21 A schematic diagram illustrating the implementation process of the line detection method provided in this application embodiment;

[0038] Figure 22 A schematic diagram illustrating the implementation process of the line detection method provided in this application embodiment;

[0039] Figure 23A schematic diagram of a 3x3 window provided for an embodiment of this application;

[0040] Figure 24 A schematic diagram illustrating a vertical line generation rule in a given scenario, as provided in an embodiment of this application;

[0041] Figure 25 A schematic diagram of a portion of pixels in an edge image provided in an embodiment of this application;

[0042] Figure 26 A schematic diagram illustrating the vertical line generation rules in another scenario provided in this application embodiment;

[0043] Figure 27 A schematic diagram illustrating the vertical line generation rules in another scenario provided in this application embodiment;

[0044] Figure 28 A schematic diagram illustrating the overall implementation process of the vertical line detection method provided in this application embodiment;

[0045] Figure 29 Example schematic diagram of type B provided in the embodiments of this application;

[0046] Figure 30 Example schematic diagram of type D provided in the embodiments of this application;

[0047] Figure 31 This is a schematic diagram illustrating the overall implementation process of the horizontal line detection method provided in the embodiments of this application;

[0048] Figure 32 This is a schematic diagram of the structure of the line detection device provided in the embodiments of this application;

[0049] Figure 33 This is a schematic diagram of the structure of the line detection device provided in the embodiments of this application;

[0050] Figure 34 This is a schematic diagram of the chip structure provided in an embodiment of this application;

[0051] Figure 35 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;

[0052] Figure 36 This is a schematic diagram of the hardware entity of the electronic device according to an embodiment of this application. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.

[0054] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.

[0055] In the following description, references to "some embodiments," "this embodiment," "this application embodiment," and examples, etc., describe a subset of all possible embodiments. However, it is understood that "some embodiments" may be the same subset or different subset of all possible embodiments and may be combined with each other without conflict.

[0056] It should be noted that the terms "first, second, third, fourth," etc., used in the embodiments of this application are for distinguishing similar or different objects and do not represent a specific order of objects. It is understood that "first, second, third, fourth," etc., can be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0057] This application provides a line detection method applied to an electronic device. This electronic device can be of various types with information processing capabilities, such as mobile phones, tablets, personal computers, televisions, projectors, and cameras. The function implemented by this method can be achieved by a processor in the electronic device calling program code. The program code can be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.

[0058] This application provides two line detection methods: a first type of line (vertical lines) and a second type of line (horizontal lines). Of course, the vertical lines referred to in this application are not limited to lines strictly parallel to the vertical axis of the pixel coordinate system, but also include lines at an angle to the vertical axis; similarly, the horizontal lines are not limited to lines strictly parallel to the horizontal axis of the pixel coordinate system, but also include lines at an angle to the horizontal axis. It should be noted that the lines described in this application can be either straight lines or curves.

[0059] The detection method for the first type of line will be explained below. Figure 1A This is a schematic diagram illustrating the implementation process of the vertical line detection method provided in the embodiments of this application, as shown below. Figure 1A As shown, the method may include the following steps 101 to 103:

[0060] Step 101: Determine if there is a step record for the previous neighboring pixel that is not in the same row as the current pixel;

[0061] Wherein, the current pixel and the preceding neighboring pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark. The first direction mark indicates that the line type is a first type, and the second direction mark is used to indicate the current detection direction of the line. Wherein, the current detection direction of the line does not refer to the detection direction of the pixel, but is understood as the current growth direction of the line.

[0062] Step 102: Based on the step record and the positional relationship between the current pixel and the preceding adjacent pixel with the step record, determine the target pixel to be added to the line from the current pixel and the next row of pixels of the current pixel; the target pixel is an edge pixel; that is, the target pixel is the newly added pixel of the line, or it can be understood as the current line growing to the target pixel;

[0063] Step 103: Based on determining that the target pixel is the end point of the line, terminate the growth of the line, output at least the starting point coordinates and the ending point coordinates of the line, and continue line detection.

[0064] In this application embodiment, a line detection method is provided. In this method, the currently growing line is recorded by step recording as either a first type of line or a second type of line (i.e., a first direction marker). During growth / detection, the detection rule for the first type of line or the detection rule for the second type of line is determined based on the first direction marker. Based on this, more accurate line detection results can be obtained, thereby improving the performance of application scenarios based on line features.

[0065] The following describes further optional implementation methods and related terms for each step in the above-mentioned vertical line detection method / first type of line detection method.

[0066] In step 101, it is determined that there is a step record for the preceding neighboring pixel that is not in the same row as the current pixel; wherein, the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a first type, and the second direction mark indicating the current detection direction of the line; the current pixel and the preceding neighboring pixel with the step record are edge pixels.

[0067] It should be noted that the detected lines can also be described as lines that are currently growing. Understandably, the basic principle of line detection is to traverse and search the pixel values ​​in the edge image according to a certain search / detection rule, thereby determining the connected components of edge pixels that meet the line characteristics; these connected components are called lines. Based on this, the currently growing line is the connected component of the edge pixels that have been determined and whose search has not yet ended.

[0068] Understandingly, an edge image refers to the image obtained after edge extraction from the original image. An edge is typically defined as the boundary of a region in an image where grayscale changes drastically (edge ​​pixels are the pixels on this boundary), and the grayscale change can be reflected by the gradient of the image's grayscale distribution. For example, Figure 1B As shown, edge detection can be performed on the original image (i.e., the original image) 111 based on the Sobel vertical gradient of the image to obtain partial edge information of edge image 114 (i.e., white pixels in 112), and edge detection can be performed on the original image (i.e., the original image) 111 based on the Sobel horizontal gradient of the image to obtain another part of edge information of edge image 114 (i.e., white pixels in 113).

[0069] The second direction marker is used to indicate the current growth / detection direction of the line that is currently growing / expanding / detecting; the current growth direction may be the relative direction between the previous neighboring pixel with the step record and the previous edge pixel on the line; or, the current growth direction may also be the relative direction between the previous neighboring pixel with the step record and the starting point of the line.

[0070] In this embodiment, the preceding adjacent pixels are related to the amount of data read at one time by the module executing step 101. In some embodiments, the module acquires edge feature data of a first window size, the edge feature data including values ​​indicating whether the current pixel and its adjacent pixels are edge pixels; wherein, the adjacent pixels of the current pixel include preceding adjacent pixels and subsequent adjacent pixels.

[0071] Therefore, the preceding neighboring pixel that is not in the same row as the current pixel is a pixel within the first window. For example, such as Figure 2As shown, assuming that the edge image is scanned from top to bottom and from left to right during line detection, and the first window is 3*3 in size, where each smallest square represents a pixel, and pixel o is the current pixel; then, the preceding neighboring pixels not in the same row as the current pixel o include pixels a, b, and c; additionally, pixel d is also a preceding neighboring pixel of the current pixel o. In other words, the preceding neighboring pixels of the current pixel refer to pixels adjacent to the current pixel that have already been traversed / detected; "previous" can be understood as the time when the pixel was traversed / detected before the current pixel. Pixels e, f, g, and h are the following neighboring pixels of the current pixel o; that is, the following neighboring pixels of the current pixel refer to pixels adjacent to the current pixel that have not been traversed / detected; "following" can be understood as the time when the pixel was traversed / detected after the current pixel. Therefore, the neighboring pixels of the current pixel include pixels a to h.

[0072] Understandably, the so-called previous adjacent pixels refer to pixels that have already been traversed (i.e., pixels that have been used as the current pixel for line detection), while the so-called subsequent adjacent pixels refer to pixels that have not yet been traversed.

[0073] In this embodiment, there is no need to cache the entire frame of edge image data; steps 101 to 103 can be implemented based on the data within the first window. This reduces the resource cost of hardware implementation of the line detection method, as it eliminates the need for a large-capacity cache to cache the data required to implement steps 101 to 103. Furthermore, since line detection of the edge image can begin as soon as the data of the first window size is obtained, without waiting for the entire frame of the edge image to be cached, the efficiency of line detection is improved.

[0074] In step 102, based on the step record and the positional relationship between the current pixel and the preceding neighboring pixel with the step record, the target pixel to be added to the line is determined from the current pixel and the next row of pixels of the current pixel; the target pixel is an edge pixel.

[0075] Understandably, a target pixel is a pixel that can serve as the next growth point of a growing line, that is, a pixel that can be added to the line.

[0076] In some embodiments, step 102 can be implemented as follows: Based on the positional relationship and the first and second direction markers in the step record, candidate pixels are determined from the next row of pixels of the current pixel; different second direction markers and / or different positional relationships correspond to different candidate pixels; the target pixel is determined based on the edge feature data of the candidate pixels; wherein the edge feature data includes a value indicating whether the candidate pixel is an edge pixel; thus, since different second direction markers and / or different positional relationships correspond to different candidate pixels, instead of using a consistent candidate pixel, the overall speed of determining the target pixel is shortened, thereby improving line detection efficiency.

[0077] For example, such as Figure 3 As shown, the arrow indicates the current growth direction represented by the second direction marker. Indicates the current pixel, This refers to the preceding neighboring pixels with step records for the current pixel; for scenario one, the corresponding candidate pixels are P5 and P6; for scenario two, the corresponding candidate pixels are P4, P5, and P6; and for scenario three, the corresponding candidate pixels are P4 and P5. Of course, there are other scenarios, i.e., other positional relationships between the preceding neighboring pixels with the aforementioned step records and the current pixel, which will not be listed here. In summary, different second direction markers and / or different positional relationships correspond to different candidate pixels, and this technical feature is beneficial for improving the overall efficiency of line detection methods. Of course, this example assumes that the scanning order of the edge image is from left to right and from top to bottom; the algorithm principle is similar for scanning orders from right to left and from bottom to top, for example... Figure 3 Scenario 4 shown, for exist In the case directly below the current pixel, the corresponding candidate pixels are P5 and P6. In summary, among the subsequent adjacent pixels not in the same row as the current pixel, the pixel pointed to by the current growth direction is selected as the candidate pixel.

[0078] To obtain more accurate vertical lines, in this embodiment of the application, for and Different positional relationships define different growth rules. For example... Figure 4 As shown, and Positional relationships include: exist Directly above (i.e., scene 401), exist The upper left corner (i.e., scene 402) exist The upper right corner (i.e., scene 403). Based on this, different growth rules are used. Of course, Figure 4 The example shown assumes that the scanning order of the edge image is from left to right and from top to bottom; the same applies to scanning orders from right to left and from bottom to top, except... and The vertical positions are simply reversed, for example, in Figure 4 middle, exist Directly above, in the scanning order from right to left and bottom to top, exist Directly below; for example, in Figure 4 middle, exist In the upper left corner, and in the scanning order from right to left and bottom to top, exist The bottom right corner; the algorithm principle is the same.

[0079] for exist In some embodiments, such as, the case where the preceding neighboring pixel with the step record is directly above the current pixel, that is, the case where the previous neighboring pixel with the step record is directly above the current pixel. Figure 5 As shown, step 102 can be achieved through the following steps 1021a to 1026a:

[0080] Step 1021a: Based on the first direction marker and the second direction marker, determine candidate pixels from the next row of pixels of the current pixel.

[0081] Different second-direction markers correspond to different candidate pixels for vertical line detection. This is because, as mentioned earlier... Figure 3 Examples have already been provided, so they will not be repeated here.

[0082] Step 1022a: Determine whether at least one pixel among the candidate pixels is an edge pixel; if so, proceed to step 1023a; otherwise, proceed to step 1024a.

[0083] Understandably, when the preceding neighboring pixel with the step record is directly above the current pixel, steps 1021a and 1022a can be understood as first determining whether the line can grow downwards, that is, if there are edge pixels among the candidate pixels in the next row, then it will grow downwards first (i.e., execute step 1023a); in this way, the output vertical line is as parallel as possible to the vertical axis of the pixel coordinate system, that is, to obtain a vertical line feature with higher accuracy as much as possible.

[0084] Step 1023a: From the candidate pixels that are at least one edge pixel, determine a pixel as the target pixel.

[0085] When there are two or more candidate pixels for an edge pixel, any one of them can be selected as the target pixel; alternatively, the target pixel can be selected according to a predefined selection strategy.

[0086] For example, if the pixel directly below the current pixel (referring to the candidate pixel) is an edge pixel, the pixel is preferentially selected as the target pixel; if the pixels to the lower left and lower right of the current pixel (referring to the candidate pixels) are both edge pixels, the pixel in the opposite direction that is consistent with the current growth direction is preferentially selected as the target pixel; wherein, the opposite direction refers to the lower left or lower right.

[0087] Of course, if there is only one candidate pixel for the edge pixel, then that pixel is taken as the target pixel.

[0088] Step 1024a: Determine whether the horizontal right neighbor of the current pixel is an edge pixel; if yes, proceed to step 1025a; otherwise, proceed to step 1026a.

[0089] Step 1025a: Terminate the growth of the line, take the previous adjacent pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line.

[0090] Step 1026a: Terminate the growth of the line, and take the current pixel as the target pixel and the end point of the line.

[0091] Understandably, in this embodiment, it is first determined whether the current pixel can grow downwards; if it cannot grow downwards, it is determined whether the current pixel can grow to the right, that is, whether the horizontal right neighbor of the current pixel is an edge pixel; if it can grow to the right, the growth of the line is terminated, and the current pixel is not taken as the end point of the line, but the previous neighbor pixel with the step record is taken as the end point of the line; if it cannot grow to the right, the current pixel is taken as the end point of the line; in this way, the vertical line does not occupy the pixels of the horizontal line, and the vertical line obtained is more accurate.

[0092] for exist The case of the upper left of the current pixel, that is, the case where the previous neighboring pixel with the step record is to the upper left of the current pixel, in some embodiments, such as Figure 6 As shown, step 102 can be achieved through the following steps 1021b to 1026b:

[0093] Step 1021b: Based on the first direction marker and the second direction marker, determine candidate pixels from the next row of pixels of the current pixel.

[0094] For example, such as Figure 7 As shown, the arrow indicates the current growth direction represented by the second direction marker. Indicates the current pixel, This represents the previous neighboring pixel with a step record for the current pixel; for scenario five, the corresponding candidate pixels are P5 and P6; for scenario six,

[0095] The corresponding candidate pixels are P4, P5, and P6. exist The difference is that the situation in scenario seven is not considered here.

[0096] Step 1022b: Determine whether at least one pixel among the candidate pixels is an edge pixel; if so, proceed to step 1023b; otherwise, proceed to step 1024b.

[0097] Step 1023b: From the candidate pixels that are at least one edge pixel, determine a pixel as the target pixel.

[0098] Understandably, when the preceding neighboring pixel with the step record is to the upper left of the current pixel, steps 1021b and 1022b also first determine whether the line can grow downwards. That is, if there are edge pixels among the candidate pixels in the next row, the line will grow downwards first (i.e., step 1023b will be executed). In this way, the angle between the output vertical line and the vertical axis of the pixel coordinate system is made as small as possible, that is, the output vertical line is made as close as possible to the horizontal axis of the pixel coordinate system, resulting in a more accurate vertical line feature.

[0099] Step 1024b: Determine whether the current pixel can be used as a target pixel; if yes, proceed to step 1025b; otherwise, proceed to step 1026b.

[0100] Step 1025b: Terminate the growth of the line and take the target pixel as the endpoint of the line;

[0101] Step 1026b: Terminate the growth of the line, take the previous adjacent pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line.

[0102] for exist The case of the upper right of the current pixel, that is, the case where the previous neighboring pixel with the step record is to the upper right of the current pixel, in some embodiments, such as Figure 8 As shown, step 102 can be achieved through the following steps 1021c to 1020c:

[0103] Step 1021c: Determine whether the horizontal right neighbor of the current pixel is a non-edge pixel; if yes, proceed to step 1022c; otherwise, proceed to step 1028c.

[0104] Step 1022c: Based on the first direction marker and the second direction marker, determine candidate pixels from the next row of pixels of the current pixel;

[0105] Step 1023c: Determine whether at least one pixel among the candidate pixels is an edge pixel; if so, proceed to step 1024c; otherwise, proceed to step 1025c.

[0106] That is, based on the determination that the horizontal right neighbor of the current pixel and the next row of pixels of the current pixel are both non-edge pixels, step 1025c is executed.

[0107] Step 1024c: From the candidate pixels that are at least one edge pixel, determine a pixel as the target pixel.

[0108] In the embodiments of this application, for exist In the case of the upper right corner, first determine whether the current pixel can grow to the right. If it cannot grow to the right (i.e., the horizontal right neighbor of the current pixel is a non-edge pixel), then determine whether the current pixel can grow downward (i.e., steps 1022c to 1023c). Since the premise of growing downward is that the current pixel cannot grow to the right, the angle between the detected vertical line and the vertical axis of the pixel coordinate system can be minimized, thereby improving the detection accuracy of the vertical line.

[0109] Step 1025c: Determine whether the current pixel can be used as a target pixel; if yes, proceed to step 1026c; otherwise, proceed to step 1027c.

[0110] That is, based on the fact that the right horizontal neighbor of the current pixel and the next row of pixels of the current pixel are both non-edge pixels, and that the current pixel can be used as a target pixel, step 1026c is executed;

[0111] Based on the determination that the horizontal right neighbor of the current pixel and the next row of pixels of the current pixel are both non-edge pixels, and that the current pixel cannot be used as a target pixel, step 1027c is executed.

[0112] Step 1026c: Terminate the growth of the line and take the target pixel as the endpoint of the line;

[0113] Step 1027c: Terminate the growth of the line, take the previous adjacent pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line.

[0114] Step 1028c: Determine whether there is at least one edge pixel in the next row of pixels of the current pixel; if so, proceed to step 1027c; otherwise, proceed to step 1020c.

[0115] That is, based on the determination that any pixel in the next row of pixels of the current pixel and the horizontal right neighbor of the current pixel are both edge pixels, step 1029c is executed;

[0116] Based on the determination that the rightmost horizontal neighbor of the current pixel is an edge pixel and that the pixels in the next row of the current pixel are all non-edge pixels, step 1020c is executed.

[0117] Step 1029c: Terminate the growth of the line, take the previous adjacent pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line.

[0118] Step 1020c: Terminate the growth of the line, take the previous adjacent pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line.

[0119] for and Different positional relationships define the above three growth rules. In some embodiments, when the number of preceding neighboring pixels with the step record is greater than 1, the target pixels of the corresponding lines can be determined in parallel for different preceding neighboring pixels with step records; thus, the overall implementation efficiency of the line detection method can be improved.

[0120] In step 103, based on determining that the target pixel is the end point of the line, the growth of the line is terminated, and at least the starting point coordinates and the ending point coordinates of the line are output.

[0121] In this embodiment, the conditions for terminating line growth are not limited and can be varied. The conditions for terminating line growth can be that the number of edge pixels on the line is equal to a preset threshold, or it can be the aforementioned condition of taking the target pixel as the end point of the line.

[0122] In some embodiments, the method further includes: generating a step record of the target pixel based on determining that the target pixel cannot be the end point of the line; and determining the next target pixel of the line until the end point of the line is determined.

[0123] In some embodiments, for lines of the first type, during line detection, a step record needs to be generated for each edge pixel constituting the line, including the start and end points of the line; thus, each edge pixel constituting the detected line has a corresponding step record / step information. The step record for the start point of the line can be set to an initial value. It can be understood that when determining the next target pixel of the line (i.e., at the current moment), the target pixel detected at the previous moment becomes the preceding neighbor pixel of the current pixel, and the step record of that pixel at least records the start point coordinates of the line, a first direction marker, and a second direction marker representing the current detection direction / current generation direction of the line.

[0124] The following explains the method for detecting horizontal lines. Figure 9 This is a schematic diagram illustrating the implementation process of the horizontal line detection method provided in the embodiments of this application, as shown below. Figure 9 As shown, the method may include the following steps 901 to 903:

[0125] Step 901: Determine if there is a step record for the previous neighboring pixel that is not in the same row as the current pixel;

[0126] Wherein, the current pixel and the previous neighboring pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a horizontal line, and the second direction mark indicating the current growth direction of the line;

[0127] Step 902: If the horizontal left neighbor and / or horizontal right neighbor of the current pixel are non-edge pixels, determine whether the current pixel should be added as the target pixel of the line based on the step record and the positional relationship between the current pixel and the previous neighbor pixel with the step record; if yes, proceed to step 903; otherwise, end the growth process, take the previous neighbor pixel with the step record as the end point of the line, and output the start point coordinates and end point coordinates of the line.

[0128] Step 903: Based on the determination that the current pixel is increased to the target pixel and the line termination condition is met, the growth of the line is terminated, the current pixel is taken as the end point of the line, and the starting point coordinates and ending point coordinates of the line are output.

[0129] In this application embodiment, a line detection method is provided. In this method, the current line being grown is recorded by step recording as either a first type of line or a second type of line (i.e., a first direction marker). During growth, the detection rule for the first type of line or the detection rule for the second type of line is determined based on the first direction marker. Based on this, more accurate line detection results can be obtained, thereby improving the performance of application scenarios based on line features.

[0130] The following describes further optional implementation methods and related terms for each step in the above-mentioned horizontal line detection method / second type of line detection method.

[0131] In step 901, it is determined that there is a step record for the previous adjacent pixel that is not in the same row as the current pixel.

[0132] It should be noted that for the vertical lines mentioned above, each pixel on the line has a step record. However, for the horizontal lines, not every pixel on the line corresponds to a step record. For example... Figure 10 As shown, for multiple consecutive edge pixels in the same row, a step record can be set only at the end along the growth direction. Figure 10 middle This represents edge pixels with step records. This indicates that the pixel is an edge pixel, and the arrow indicates the direction of the horizontal line's growth. For example... Figure 10 As shown, in scene 101, the horizontal lines grow diagonally from left to right; in scene 102, the horizontal lines grow diagonally from right to left; and in scene 103, the horizontal lines grow horizontally from right to left.

[0133] In some embodiments, the method further includes: acquiring edge feature data of a second window size, the edge feature data including values ​​indicating whether the current pixel and its neighboring pixels are edge pixels; wherein the neighboring pixels of the current pixel include previous-level neighboring pixels and subsequent-level neighboring pixels. The description of the second window can be understood by referring to the description of the first window above.

[0134] In step 902, if the horizontal left neighbor and / or horizontal right neighbor of the current pixel are non-edge pixels, it is determined whether the current pixel should be added as the target pixel of the line based on the step record and the positional relationship between the current pixel and the previous neighbor pixel with the step record.

[0135] The growth rules for horizontal lines are as follows:

[0136] First priority: prioritize growth along the horizontal direction until no more growth is possible; Second priority: top left has priority over top right; where the first priority is higher than the second priority.

[0137] Horizontal line detection methods are more complex than vertical line detection methods. Based on the surrounding pixels of the current pixel (where the current pixel is an edge pixel), they include four types, such as... Figure 11 As shown, these represent types A to B. To improve readability, in Figure 11 middle, Represented as non-edge pixels, This represents the current pixel and is an edge pixel. The pixels are represented as edge pixels. In type A, the horizontal left and right adjacent pixels of the current pixel are both non-edge pixels. In type B, the horizontal left adjacent pixel of the current pixel is a non-edge pixel, and the horizontal right adjacent pixel of the current pixel is an edge pixel. In type C, the horizontal left and right adjacent pixels of the current pixel are both edge pixels. In type D, the horizontal left adjacent pixel of the current pixel is an edge pixel, and the horizontal right adjacent pixel of the current pixel is a non-edge pixel.

[0138] For type A (the horizontal left and right adjacent pixels of the current pixel are both non-edge pixels), if there is a step record for the previous adjacent pixel that is not in the same row as the current pixel, then based on the step record and the positional relationship between the previous adjacent pixel with the step record and the current pixel, it is determined whether the current pixel should be added as the target pixel of the line.

[0139] Specifically, such as Figure 12 As shown, based on the fact that the current pixel has a step record in the upper left of its previous neighboring pixel, the other previous neighboring pixels in different rows are non-edge pixels, and the first direction mark of the step record indicates that the corresponding detected line is a horizontal line and the second direction mark indicates that the current growth direction is horizontal (i.e., a horizontally pointing arrow) or horizontally to the left (i.e., a diagonally downward pointing arrow), it is determined that the current pixel can be added as the target pixel of the corresponding detected line.

[0140] For example Figure 13 As shown, based on the determination that there is a step record in the upper right neighboring pixel of the current pixel, the other neighboring pixels in different rows are non-edge pixels, and the horizontal line detection recorded by the step record and the current growth direction is horizontal (i.e., horizontal pointing arrow) or horizontal right (i.e., downward pointing arrow), it is determined that the current pixel can be added as the target pixel of the corresponding detection line.

[0141] For example Figure 14As shown, based on the determination that the current pixel has two preceding neighboring pixels with the step record, and these pixels are located diagonally opposite to the current pixel (i.e., one is above the left of the current pixel, and the other is above the right of the current pixel), it is determined that the current pixel can be added as a target pixel of the line. Furthermore, a step record for the current pixel is generated based on the step records of the preceding neighboring pixels that are read first. For example, if the data is read from memory in the order of left to right, the step record for the current pixel is generated based on the step record of the preceding neighboring pixel above the left of the current pixel; conversely, if the data is read from memory in the order of right to left, the step record for the current pixel is generated based on the step record of the preceding neighboring pixel above the right of the current pixel.

[0142] For example, based on the determination that the preceding neighbor pixel with the step record of the current pixel is located in the vertical direction of the current pixel, the growth of the line is terminated, and the preceding neighbor pixel with the step record is taken as the end point of the line, and the start coordinates and end coordinates of the line are output. If the order of reading data from the memory is from top to bottom, such as Figure 15 As shown, the preceding neighboring pixel with the step record in the vertical direction is located directly above the current pixel. In this scenario, growth is not supported. That is, the preceding neighboring pixel with the step record is used as the end point of the line, and the starting point coordinates and ending point coordinates of the line are output.

[0143] For type B (the horizontal left neighbor of the current pixel is a non-edge pixel, and the horizontal right neighbor of the current pixel is an edge pixel) or type D (the horizontal left neighbor of the current pixel is an edge pixel, and the horizontal right neighbor of the current pixel is a non-edge pixel), if there is a step record for the preceding neighbor pixel that is not in the same row as the current pixel, the current pixel can be added as the target pixel. Based on the step record and the positional relationship between the preceding neighbor pixel with the step record and the current pixel, a step record for the current pixel is generated.

[0144] Furthermore, in some embodiments, based on the determination that the line termination condition is not currently met and the target pixel is the first endpoint pixel of the row, a second endpoint pixel is searched in the horizontal direction pointed to by the current growth direction from the first endpoint pixel; wherein, the pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels;

[0145] When a preceding neighboring pixel on a different row from the second endpoint pixel has a step record, the step record of the current pixel is generated based on the step record of the preceding neighboring pixel of the second endpoint pixel, and the step record of the second endpoint pixel is generated based on the step record of the preceding neighboring pixel of the current pixel; thus, it can be seen that the line detection method provided in this application embodiment supports the detection of intersecting lines, which is beneficial to improving the performance of application scenarios.

[0146] For example Figure 16 In the scenario shown, if the order of reading data from memory (i.e., the scanning direction) is from left to right, then the first endpoint pixel can be understood as the left endpoint, i.e., in Type(B)-Case(1) or Type(B)-Case(2). The second endpoint pixel can be understood as the right endpoint, i.e., in Type(D)-Case(1) or Type(D)-Case(2). If the order of reading data from memory (i.e., the scanning direction) is from right to left, then the second endpoint pixel can be understood as the left endpoint, i.e., in Type(B)-Case(1) or Type(B)-Case(2). The first endpoint pixel can be understood as the right endpoint, i.e., in Type(D)-Case(1) or Type(D)-Case(2).

[0147] Figure 16 The arrow in the image indicates the current growth direction. Assuming the scanning direction is from left to right, then: the current growth direction points horizontally to the right; D inherits the step record from the upper left (i.e., the second endpoint pixel inherits the step record of the upper left preceding neighbor pixel of the first endpoint pixel); B inherits the step record from the upper right (i.e., the first endpoint pixel inherits the step record of the upper right preceding neighbor pixel of the second endpoint pixel).

[0148] In some embodiments, when the preceding neighboring pixel not in the same row as the second endpoint pixel does not have a step record, a step record for the second endpoint pixel is generated based on the step record of the preceding neighboring pixel of the current pixel; and when the preceding neighboring pixel not in the same row as the second endpoint pixel does not have a step record, and the subsequent neighboring pixel not in the same row as the current pixel is an edge pixel, the second endpoint pixel is used as the starting point of a new line to generate a step record for the current pixel, which is used to record the information of the new line; wherein the subsequent neighboring pixel of the edge pixel is in the same column as the preceding neighboring pixel of the current pixel that has the step record. In this embodiment, a detection method supporting another case of intersecting lines is provided.

[0149] For example Figure 17For the scenario shown, the understanding of the first endpoint pixel and the second endpoint pixel should refer to the... Figure 16 The explanation of the left and right endpoints in the text is used for understanding. Figure 17 The arrow in the image indicates the current growth direction. Assuming the scanning direction is from left to right, then: the horizontal direction pointed to by the current growth direction is horizontal to the right; for the scene where the left endpoint is located as shown in Type(B)-Case(1) and the scene where the right endpoint is located as shown in Type(D)-Case(3) or Type(D)-Case(4), D inherits the step record of the upper left (that is, the second endpoint pixel inherits the step record of the upper left neighboring pixel of the first endpoint pixel), and no processing is done on B (that is, the first endpoint pixel); for the scene where the left endpoint is located as shown in Type(B)-Case(2) and the scene where the right endpoint is located as shown in Type(D)-Case(3) or Type(D)-Case(4), D inherits the step record of the upper left, and D is used as the starting point of the new line to generate the step record of B, which is used to record the information of the new line.

[0150] In some embodiments, when the preceding neighboring pixel in a different row from the current pixel does not have a step record, the current pixel is taken as the first endpoint pixel of its row, and a second endpoint pixel is searched in the horizontal direction pointed to by the line detection direction from the first endpoint pixel; wherein, pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels; when the preceding neighboring pixel in a different row from the current pixel does not have a step record, and the preceding neighboring pixel in a different row from the second endpoint pixel has a step record, and the subsequent neighboring pixel in a different row from the second endpoint pixel is an edge pixel, a step record of the current pixel is generated based on the step record of the preceding neighboring pixel in a different row from the second endpoint pixel; and the current pixel is taken as the starting point of a new line, and a step record of the second endpoint pixel is generated to record the information of the new line; wherein, the subsequent neighboring pixel of the edge pixel and the preceding neighboring pixel of the second endpoint pixel with the step record are in the same column. In this embodiment, a detection method supporting another type of intersecting line case is provided.

[0151] For example, such as Figure 18 For the scenario shown, the understanding of the first endpoint pixel and the second endpoint pixel should refer to the... Figure 16The left and right endpoints are explained in the text. Assuming the scanning direction is from left to right, then: for the scene where the left endpoint is located, which is shown in Type(B)-Case(3) or Type(B)-Case(4), and the scene where the right endpoint is located, which is shown in Type(D)-Case(2), B inherits the step record of the upper right (the left endpoint inherits the step record of the upper right adjacent pixel of the right endpoint); B (left endpoint) serves as the starting point of the new line and generates the step record of D (right endpoint) to record the information of the new line.

[0152] In some embodiments, when a preceding neighbor pixel not in the same row as the first endpoint pixel does not have a step record, a preceding neighbor pixel not in the same row as the second endpoint pixel has a step record, and a subsequent neighbor pixel not in the same row as the second endpoint pixel is a non-edge pixel, a step record for the current pixel is generated based on the step record of the preceding neighbor pixel not in the same row as the second endpoint pixel; wherein the subsequent neighbor pixel that is a non-edge pixel is in the same column as the preceding neighbor pixel of the second endpoint pixel that has the step record.

[0153] For example Figure 19 For the scenario shown, the understanding of the first endpoint pixel and the second endpoint pixel should refer to the... Figure 16 The left and right endpoints are explained in the diagram. Assuming the scanning direction is from left to right, then: B (left endpoint) inherits the step record from the upper right, that is, the left endpoint inherits the step record of the upper right adjacent pixel of the right endpoint.

[0154] In some embodiments, when neither the preceding neighboring pixel on the same row as the first endpoint pixel has a step record, nor the preceding neighboring pixel on the same row as the second endpoint pixel has a step record, the second endpoint pixel is used as the starting point of a new line to generate a step record for the current pixel, which is used to record the information of the new line. When neither the preceding neighboring pixel on the same row as the first endpoint pixel has a step record, nor the preceding neighboring pixel on the same row as the second endpoint pixel has a step record, and the subsequent neighboring pixel on the same row as the second endpoint pixel is an edge pixel, the current pixel is used as the starting point of a new line to generate a step record for the second endpoint pixel, which is used to record the information of the new line. The angle between the direction from the second endpoint pixel to the subsequent neighboring pixel (which is an edge pixel) and the direction from the current pixel to the second endpoint pixel is less than 90 degrees.

[0155] For example Figure 20 For the scenario shown, the understanding of the first endpoint pixel and the second endpoint pixel should refer to the... Figure 16The explanation of the left and right endpoints is used for understanding. For scenarios where the left endpoint is in Type(B)-Case(3) or Type(B)-Case(4) and the right endpoint is in Type(D)-Case(3), B is used as the starting point of the new line, and a step record of D is generated to record the information of the new line. For scenarios where the left endpoint is in Type(B)-Case(4) and the right endpoint is in Type(D)-Case(3) or Type(D)-Case(4), D is used as the starting point of the new line, and a step record of B is generated to record the information of the new line.

[0156] For type C (where the horizontal left and right adjacent pixels of the current pixel are both edge pixels), the first priority for horizontal line growth is horizontal growth. Therefore, when the horizontal left and right adjacent pixels of an edge pixel are both edge pixels, it can only grow horizontally to the left or horizontally to the right. Step records do not need to be generated, and the three adjacent pixels above that may have step records can be ignored.

[0157] In step 903, based on the determination that the current pixel has been increased to the target pixel and the termination condition is met, the growth of the line is terminated, the current pixel is taken as the end point of the line, and the starting point coordinates and the ending point coordinates of the line are output.

[0158] Based on this, if the edge image has not been completely traversed, the next pixel is traversed in the scanning order until all edge pixels in the edge image have been traversed.

[0159] The following describes an exemplary application of the embodiments of this application in a real-world application scenario.

[0160] 1. The overall process of the line detection algorithm is described as follows:

[0161] Figure 21 This is a schematic diagram illustrating the overall implementation of the line detection algorithm, as follows: Figure 21 As shown, the steps include 2101 to 2107 as follows:

[0162] Step 2101: Perform histogram equalization (Histogram Statistic and Normalization) on the current frame image based on the previous frame image to ensure a uniform grayscale distribution. This step is an optional preprocessing step, mainly for highlight or shadow environments. The goal is to enhance image contrast and increase the gradient of edge regions compared to the original image, making them easier for edge detection algorithms to identify.

[0163] Step 2102: Apply a low-pass filter to the output image from step 2101. The low-pass filter can use a Gaussian kernel to reduce high-frequency noise in the image and make the edge regions smoother, reducing edge jaggedness.

[0164] Step 2103: Perform gradient calculation on the output image of step 2102. A Sobel filter can be used to perform gradient calculation on the image. Essentially, this is gradient filtering, which consists of two steps: horizontal gradient filtering and vertical gradient filtering. The final gradient value of each pixel is determined by the sum of the horizontal gradient and the vertical gradient or the Euclidean distance.

[0165] Step 2104: Perform non-maximum suppression on the output of step 2103 to achieve edge thinning. This can be achieved using an NMS filter. The working principle of this filter is: for each pixel, determine whether it is a maximum value relative to its upper, lower, left, and right adjacent pixels, and remove edge pixels with non-maximum values, so that the edge pixel width of the image gradient gradient region is maintained at a single pixel. This has a certain optimization effect on the subsequent line detection effect.

[0166] Step 2105: Perform dual threshold filtering on the output of step 2104 and set an edge threshold (EdgeThreshold), including a high gradient threshold G2 and a low gradient threshold G1. When the gradient value of a pixel is greater than G2, the pixel is retained as an edge pixel. When the gradient value of a pixel is less than G1, the pixel is not considered as an edge pixel. When the gradient value of a pixel is between G1 and G2, if there are surrounding pixels that have already been filtered as edge pixels, or if there are unjudged pixels with a gradient value greater than G1, then the pixel is considered to be an edge.

[0167] Step 2106: Perform Step-Length line segmentation algorithm based on the result obtained in Step 2105. This algorithm will be described in detail below. The edge image obtained after image edge detection (i.e., the result obtained in Step 2105) is the input of this algorithm. The output of this algorithm includes the coordinates of the detected line start point, the coordinates of the line end point, and the average intensity of the line.

[0168] Step 2107: Perform duplicate line removal on the line segmentation result output in step 2106. That is, iterate through the lines output in step 2106. When there are completely identical lines or lines with swapped beginnings and ends, only a single line should be retained. When it is determined that two lines have sufficiently close endpoints and the directional deviation is less than a threshold, the two lines should be merged and the merged line should be retained.

[0169] 2. Detailed description of the Step-Length core algorithm:

[0170] For the Step-Length core algorithm, such as Figure 22 As shown, within the 3x3 window 221, region 222 dynamically records step information, which is stored in FIFO 223. This step information includes: the x-coordinate and y-coordinate of the starting point, the ori direction marker (horizontal, vertical, or undefined, an example of the first direction marker), the pdir parent node direction marker (left, right, or undefined, an example of the second direction marker), length (i.e., the slope of the line), cstep (the cumulative number of consecutive growths in the vertical direction), confidence sum (the accumulated gradient value), pixelnum (the number of pixels), x-index (recording the x-coordinate corresponding to a record), and line coordinates sum (the centroid representation of the line). The input edge feature map is the result after processing in step 2105. Line info is the output of the line growth algorithm, including: the coordinates of the starting and ending points and the average line strength (confidence). The edge feature map is scanned from left to right and from top to bottom. Once an edge pixel is found and a step_record can be formed, it will be dynamically recorded. At the same time, the growth algorithm of horizontal lines (i.e., the second type of lines) and vertical lines (i.e., the first type of lines) is promoted. When the line_end condition is met, it will enter the Line info buffer and be written to DDR through the AXI interface.

[0171] Before describing the growth algorithms for vertical and horizontal lines, the following diagram will be provided for clarity. Represents a non-edge pixel. Represents an edge pixel. This represents a "not care pixel," which can also be understood as a non-edge pixel. It is used to identify the current pixel and to identify edge pixels with step records.

[0172] 3. The detailed description of the growth algorithm for vertical lines is as follows:

[0173] The basic rules for the growth algorithms of vertical and horizontal lines are described in sections 1) to 4) below:

[0174] 1) For each pixel, a maximum of one horizontal step-record and one vertical step-record are allowed. Undefined step-records are also included in the vertical step-record before it is determined whether it is a horizontal or vertical line detection.

[0175] 2) If two vertical lines intersect at a point, only one can be allowed to continue growing, and the other will inevitably be broken.

[0176] 3) A vertical line and a horizontal line intersect and can grow without interfering with each other;

[0177] 4) When two horizontal lines intersect, if the left and right directions are the same, one of the lines will inevitably be broken; if the left and right directions are different, it is necessary to determine whether both can grow based on the actual situation. Please refer to the description of the growth algorithm of horizontal lines below for details.

[0178] For example, the structure of a 3x3 window is as follows: Figure 23 As shown, P[i,j] is the current pixel, R[i-1], R[i], R[i+1] and P[i-1,j] are the previous neighboring pixels (PRs) of P[i,j], and R[i-1] and R[i] are edge pixels; P[i+1,j], P[i-1,j+1], P[i,j+1] and P[i+1,j+1] are the subsequent neighboring pixels (SPs) of P[i,j], and P[i+1,j], P[i,j+1] and P[i+1,j+1] are edge pixels.

[0179] For edge images, the scanning sequence progresses from left to right and from top to bottom. The step record is compared with the previous PRs to determine whether it needs to be refreshed, and compared with the subsequent SPs to determine whether the growth of the line should be terminated.

[0180] In the hardware implementation, the step record needs to be refreshed in the following scenarios: To speed up the process, three paths are processed in parallel, and the results of the three paths are obtained simultaneously. There are a total of 6 growth scenarios (cases). Their growth priorities are A1>B1>C1>A2>B2>C2.

[0181] like Figure 24 As shown, for a scene where the preceding neighboring pixel with the step record is directly above the current pixel, the steps 241 to 244 are as follows:

[0182] Step 241: Determine whether the current pixel can grow downwards; if yes, proceed to step 242; otherwise, proceed to step 243.

[0183] Step 242: Based on the step records of the adjacent pixels directly above the current pixel, generate the step records in the next row of the current pixel that can serve as target pixels; for example... Figure 24 The A1 scene shown; as Figure 25 As shown, assuming the read feature data includes data from pixel P1 to pixel P6, where P2 is the current pixel, the logic for determining the target pixel is as follows (1):

[0184] A1=(((pdir==undef)&(p4|p5|p6))||((pdir==left)&(p5|p6))||((pdir==right)&(p5|p4))) (1);

[0185] Where pdir == undef indicates that the current growth direction is vertically downwards, that is... Figure 3 Scenario 2 shown; pdir == left indicates that the current growth direction is bottom left, that is Figure 3 The scenario shown is one where pdir == right indicates that the current growth direction is the lower right. Figure 3 Scenario 3 is shown.

[0186] Step 243: Determine if the pixel can grow horizontally to the right; if so, do not grow (e.g., ...). Figure 24 In the non-growing scenario shown, the adjacent pixel directly above it is taken as the endpoint of the growing line; otherwise, step 244 is executed.

[0187] Step 244: Using the current pixel as the target pixel, generate a step record for the current pixel based on the step records of its directly above neighboring pixels. For example... Figure 24 The A2 scene shown is still based on Figure 25 For example, in scene A2, the logic for determining the target pixel is shown in equation (2) below:

[0188] A2=(((pdir==undef)&~(p4|p5|p6)&~p3)||((pdir==left)&~(p5|p6)&~p3)||((pdir==right)&~(p5|p4))) (2);

[0189] like Figure 26 As shown, for a scene where the previous neighboring pixel with the step record is to the upper left of the current pixel, the steps 261 to 263 are as follows:

[0190] Step 261: Determine whether the current pixel can grow downwards; if so, proceed to step 262; otherwise, proceed to step 263.

[0191] Step 262: Based on the step records of the adjacent pixels to the upper left of the current pixel, generate the step records in the next row of the current pixel that can be used as target pixels; for example... Figure 26 The B1 scene shown is still based on Figure 25 For example, in scene B1, the logic for determining the target pixel is shown in equation (3):

[0192] B1=(((pdir==undef)&(p4|p5|p6))||((pdir==left)&(p5|p6))) (3);

[0193] Step 263: Determine if the current pixel can be used as the target pixel; if yes, proceed to step 264; otherwise, do not grow (e.g., Figure 26 In the non-growing scenario shown, the adjacent pixel to the upper left of the current pixel will be used as the endpoint of the growing line;

[0194] Step 264: Generate the step record for the current pixel based on the step records of its upper-left adjacent pixels; for example... Figure 26 The B2 scenario shown is still based on Figure 25 For example, in the B2 scene, the logic for determining the target pixel is as shown in equation (4):

[0195] B2=(((pdir==undef)&~(p4|p5|p6))||((pdir==left)&~(p5|p6)))(4);

[0196] like Figure 27 As shown, for a scene where the preceding neighboring pixel with the step record is to the upper right of the current pixel, the steps 271 to 276 are as follows:

[0197] Step 271: Determine if the pixel can grow horizontally to the right; if so, do not grow (e.g., ...). Figure 27In the non-growing scenario shown, the preceding adjacent pixel with the step record is taken as the endpoint of the corresponding line; otherwise, step 272 is executed.

[0198] Step 272: Determine whether the current pixel can grow downwards; if yes, proceed to step 273; otherwise, proceed to step 274.

[0199] Step 273: Based on the step records of the adjacent pixels to the upper right of the current pixel, generate the step records in the next row of the current pixel that can serve as target pixels; for example... Figure 27 The C1 scenario shown is still based on Figure 25 For example, in scene C1, the logic for determining the target pixel is shown in equation (5):

[0200] C1=(((pdir==undef)&(p4|p5|p6)&~(p3&(p5|p6)))||((pdir==right)&(p4|p5)&~(p3&(p5|p6)))) (5);

[0201] Step 274: Determine whether to grow horizontally to the right from the current pixel's horizontal right neighbor; if possible, do not grow (e.g., ...). Figure 27 (As shown in the corresponding scenario), take the upper right adjacent pixel of the current pixel as the endpoint of the corresponding line; otherwise, proceed to step 275.

[0202] Step 275: Determine if the current pixel can be used as the target pixel; if yes, proceed to step 276; otherwise, do not grow, and take the upper right adjacent pixel of the current pixel as the endpoint of the corresponding line.

[0203] Step 276: Generate a step record for the current pixel based on the step records of its upper-right adjacent pixels; for example... Figure 27 The corresponding scenario C2 shown is still based on Figure 25 For example, in the C2 scene, the logic for determining the target pixel is as shown in equation (6):

[0204] C2=(((pdir==right)&~(p4|p5)&~(p3&(p5|p6))) (6);

[0205] The overall implementation process of the vertical line detection algorithm is as follows: Figure 28 As shown, steps 281 to 284 are included:

[0206] Step 281: Determine whether the current pixel is an edge pixel; if so, proceed to step 282; otherwise, end the growth of the corresponding line and continue traversing the next pixel.

[0207] Step 282: Determine whether it can grow into at least one of A1 to C2; if so, proceed to step 283;

[0208] Step 283: Inherit the information of the previous adjacent pixels (i.e., the step record); then proceed to step 284;

[0209] Step 284: Compare with the adjacent pixels in the next level to determine whether to terminate the growth of the corresponding line; if yes, terminate the growth of the line and output the relevant information of the line; otherwise, continue to traverse the next pixel.

[0210] 4. The detailed description of the horizontal line growth algorithm is as follows:

[0211] The step record for horizontal lines includes... Figure 10 The diagram illustrates three scenarios. For vertical lines, each pixel on the line generates a step record. However, for horizontal lines, not every pixel on the line generates a step record. For several consecutive edge pixels on the same horizontal line, only one step record is generated at the end of the line. The so-called end of the line... Figure 10 As shown, this refers to the last pixel along the growth direction / detection direction among several consecutive pixels on the same horizontal line.

[0212] It is understandable that for the second type of line, namely horizontal lines, during the line detection process, for several consecutive pixels on the same horizontal line of the detected line, only the step record of the first or last pixel (i.e., the beginning or end of the line) can be generated. It is also understood that in the horizontal line detection method, the preceding adjacent pixel was also a detected target pixel at a previous moment. Therefore, the method for generating the step record of this preceding adjacent pixel is the same as the method for generating the step record of the target pixel, although the second direction marker recorded in the step record may be different.

[0213] In the case of a horizontal right or undefined horizontal line, since the image is transmitted from left to right, the growth direction is opposite to that of the line. When encountering the leftmost edge pixel of a horizontal edge pixel, it's unknown what will happen if growth continues to the right. At this point, a step record is generated. First, a position is reserved in the FIFO of the step record to record the SRAM address. This step record can be modified later. It may inherit from a horizontal right or undefined step record, it may be the left end of a new undefined horizontal line, or it may be discarded.

[0214] The growth rules for horizontal lines are as follows:

[0215] 1. First priority: Grow primarily in the horizontal direction until no further growth is possible;

[0216] 2. Second priority: top left takes precedence over top right.

[0217] The situation is more complex horizontally. First, based on the current pixel configuration, such as... Figure 11 As shown, we will discuss them in four categories. Types A and C have been described in detail above, so they will not be described here again.

[0218] For type B, such as Figure 29 As shown, there are four cases, for example: case(1a), case(1b), case(2a), and case(2b). In these four cases, the adjacent pixel at the top left corner or directly above the current pixel has a step record, and the current growth direction recorded is horizontal left (i.e., a downward-sloping arrow) or horizontal-undefined (i.e., a horizontally pointing arrow). Then:

[0219] 1) These two rows can grow, and the two step records in the upper left corner are called previous step records. Referring to the step record positions of the horizontal line above, the current pixel will not directly inherit the previous step record, so it is necessary to temporarily save the previous step record.

[0220] 2) Generate a temporary step-record, record the index, mark it as invalid, put it into FIFO, and save a copy in a register. If the rightmost end of this horizontal edge can inherit a step-record from the previous row, or if a new row needs to be created from right to left, then this temporary step-record needs to be refreshed; otherwise, the time step record (the invalid label) does not need to be updated.

[0221] For type D, such as Figure 30 As shown, there are six cases, for example, case(1a), case(1b), case(2a), case(2b), case(3), and case(4).

[0222] The overall implementation process of the horizontal line detection algorithm is as follows: Figure 31 As shown, steps 311 to 313 are included below:

[0223] Step 311: Determine whether the current pixel is an edge pixel; if so, proceed to step 312; otherwise, end the growth of the corresponding line and continue traversing the next pixel.

[0224] Step 312: If the surrounding pixels of the current pixel are of type A, grow according to the growth rules of type A; if the surrounding pixels of the current pixel are of type B, grow according to the growth rules of type B; if the surrounding pixels of the current pixel are of type C, grow according to the growth rules of type C; if the surrounding pixels of the current pixel are of type D, grow according to the growth rules of type D.

[0225] Step 313: Compare with the adjacent pixels in the next level to determine whether to terminate the growth of the corresponding line; if yes, terminate the growth of the line and output the relevant information of the line; otherwise, continue to traverse the next pixel.

[0226] The line detection algorithm described above can be implemented in hardware on a chip, reducing the processing time for one frame of image to 10ms, which can meet the matching requirements of high frame rate videos.

[0227] The above line detection algorithm supports most intersecting line scenarios, and the algorithm's robustness to intersecting lines is greatly improved.

[0228] In this application embodiment, a complete growth algorithm for horizontal and vertical lines is provided, as well as two optimization algorithms for horizontal and vertical intersections; wherein, when scanning to the left of a horizontal line, an empty step-record is first inserted, and the parameters are filled in at the end of the horizontal line; the detection of horizontal and vertical lines is processed separately and does not interfere with each other, and can support intersections.

[0229] This application embodiment further provides a line detection method, including: determining that a step record exists in a preceding neighboring pixel that is not in the same row as the current pixel; wherein the current pixel and the preceding neighboring pixel having the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating the line type of the line, and the second direction marker indicating the current growth direction of the line; based on determining that the first direction marker indicates that the line type of the line is a vertical line, performing the steps in the vertical line detection method described in the foregoing embodiment; based on determining that the first direction marker indicates that the line type of the line is a horizontal line, performing the steps in the horizontal line detection method described in the foregoing embodiment.

[0230] It should be noted that in this application, the term "growth" vividly describes the line detection process, that is, by detecting / traversing the pixel values ​​of search pixels, a process is gradually expanded / grown from an edge pixel into a connected region / line of a certain length.

[0231] It should be noted that although the steps of the method in this application are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps; or steps from different embodiments may be combined into a new technical solution.

[0232] Based on the foregoing embodiments, this application provides a line detection device, which includes various modules and units included in each module, and can be implemented by a processor; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be an AI acceleration engine (such as NPU), GPU, central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.

[0233] Figure 32 This is a schematic diagram of the line detection device provided in the embodiments of this application, as shown below. Figure 32 As shown, the line detection device 320 includes:

[0234] The third determining module 321 is configured to determine that there is a step record in the preceding adjacent pixel that is not in the same row as the current pixel; wherein the current pixel and the preceding adjacent pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a first type, and the second direction mark indicating the current detection direction of the line;

[0235] The first determining module 322 is configured to determine the target pixel of the line from the current pixel and the next row of pixels of the current pixel based on the step record and the positional relationship between the previous adjacent pixel with the step record and the current pixel; the target pixel is an edge pixel;

[0236] The first output module 323 is configured to output at least the start coordinates and end coordinates of the line based on determining that the target pixel is the end point of the line.

[0237] In some embodiments, the first determining module 322 is configured to determine candidate pixels from the next row of pixels of the current pixel based on the positional relationship and the first and second direction markers in the step record; different second direction markers and / or different positional relationships correspond to different candidate pixels; and determine the target pixel based on the edge feature data of the candidate pixels; wherein the edge feature data includes a value indicating whether the candidate pixel is an edge pixel.

[0238] In some embodiments, the first determining module 322 is configured to, when the positional relationship is such that the preceding neighboring pixel with the step record is directly above the current pixel, determine a candidate pixel from the next row of pixels of the current pixel according to the first direction mark and the second direction mark; and when at least one of the candidate pixels is an edge pixel, determine a pixel as the target pixel from the at least one candidate pixel that is an edge pixel.

[0239] In some embodiments, the first determining module 322 is configured to determine whether the horizontal right neighbor of the current pixel is an edge pixel when each of the candidate pixels is a non-edge pixel; based on the determination that the horizontal right neighbor of the current pixel is an edge pixel, take the previous neighbor pixel with the step record as the end point of the line, and output at least the start point coordinates and end point coordinates of the line through the first output module 323; based on the determination that the horizontal right neighbor of the current pixel is a non-edge pixel, take the current pixel as the target pixel and as the end point of the line.

[0240] In some embodiments, the first determining module 322 is configured to, when the positional relationship is such that the preceding neighboring pixel with the step record is to the upper left of the current pixel, determine a candidate pixel from the next row of pixels of the current pixel according to the first direction mark and the second direction mark; and when at least one of the candidate pixels is an edge pixel, determine a pixel as the target pixel from the at least one candidate pixel that is an edge pixel.

[0241] In some embodiments, the first determining module 322 is configured to determine whether the current pixel can be used as a target pixel when each of the candidate pixels is a non-edge pixel; based on the determination that the current pixel can be used as the target pixel, to use the target pixel as the end point of the line; based on the determination that the current pixel cannot be used as the target pixel, to use the previous neighboring pixel with the step record as the end point of the line, and to output at least the start point coordinates and end point coordinates of the line through the first output module 323.

[0242] In some embodiments, the first determining module 322 is configured to, when the positional relationship is such that the preceding neighboring pixel with the step record is to the upper right of the current pixel, determine candidate pixels from the next row of pixels of the current pixel based on determining that the horizontal right neighboring pixel of the current pixel is a non-edge pixel, according to the first direction mark and the second direction mark; and when at least one of the candidate pixels is an edge pixel, determine a pixel as the target pixel from the at least one candidate pixel that is an edge pixel.

[0243] In some embodiments, the first determining module 322 is configured to determine that any pixel in the next row of pixels of the current pixel and the horizontal right neighbor of the current pixel are both edge pixels, and to take the previous neighbor pixel with the step record as the end point of the line, and to output at least the start point coordinates and end point coordinates of the line through the first output module 323.

[0244] In some embodiments, the first determining module 322 is configured to, based on determining that the horizontal right neighbor of the current pixel is an edge pixel and that all pixels in the next row of the current pixel are non-edge pixels, take the preceding neighbor pixel with the step record as the endpoint of the line, and output at least the start coordinates and end coordinates of the line through the first output module 323; based on determining that the horizontal right neighbor of the current pixel and the pixels in the next row of the current pixel are non-edge pixels, and that the current pixel can be used as a target pixel, take the target pixel as the endpoint of the line; based on determining that the horizontal right neighbor of the current pixel and the pixels in the next row of the current pixel are non-edge pixels, and that the current pixel cannot be used as a target pixel, take the preceding neighbor pixel with the step record as the endpoint of the line, and output at least the start coordinates and end coordinates of the line through the first output module 323.

[0245] In some embodiments, the first determining module 322 is configured to generate a step record of the target pixel based on determining that the target pixel cannot be used as the end point of the line; and to determine the next target pixel of the line until the end point of the line is determined.

[0246] In some embodiments, the line detection device 320 further includes a data acquisition module configured to: acquire edge feature data of a first window size, the edge feature data including values ​​indicating whether the current pixel and its neighboring pixels are edge pixels; wherein the neighboring pixels of the current pixel include previous-level neighboring pixels and subsequent-level neighboring pixels.

[0247] In some embodiments, the first determining module 322 is configured to determine the target pixel of the corresponding line in parallel for different preceding adjacent pixels with step records when the number of preceding adjacent pixels with the step record is greater than 1.

[0248] The description of the above device embodiments is similar to the description of the above method embodiments for vertical line detection, and has similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the description of the method embodiments for vertical line detection in this application for understanding.

[0249] This application embodiment further provides a line detection device. Figure 33 This is a schematic diagram of the line detection device provided in the embodiments of this application, as shown below. Figure 33 As shown, the line detection device 330 includes:

[0250] The fourth determining module 331 is configured to determine that there is a step record in the preceding adjacent pixel that is not in the same row as the current pixel; wherein the current pixel and the preceding adjacent pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction mark and a second direction mark, the first direction mark indicating that the line type is a second type, and the second direction mark indicating the current detection direction of the line;

[0251] The second determining module 332 is configured to determine whether the current pixel should be added as the target pixel of the line when the horizontal left neighbor pixel and / or the horizontal right neighbor pixel of the current pixel are non-edge pixels, based on the step record and the positional relationship between the current pixel and the previous neighbor pixel with the step record.

[0252] The second output module 333, based on the determination that the current pixel is increased to the target pixel and the line termination condition is met, takes the current pixel as the end point of the line and outputs the start point coordinates and end point coordinates of the line.

[0253] In some embodiments, the second determining module 332 is configured to: based on the determination that the line termination condition is not met and the target pixel is the first endpoint pixel of the row, search for a second endpoint pixel in the horizontal direction pointed to by the current detection direction from the first endpoint pixel; wherein, pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels; if a step record is available for a preceding neighbor pixel that is not in the same row as the second endpoint pixel, generate a step record for the current pixel based on the step record of the preceding neighbor pixel of the second endpoint pixel, and generate a step record for the second endpoint pixel based on the step record of the preceding neighbor pixel of the current pixel.

[0254] In some embodiments, the second determining module 332 is configured to: generate a step record for the second endpoint pixel based on the step record of the previous neighbor pixel of the current pixel when the previous neighbor pixel of the second endpoint pixel does not have a step record; and generate a step record for the current pixel by taking the second endpoint pixel as the starting point of a new line when the previous neighbor pixel of the second endpoint pixel does not have a step record and the subsequent neighbor pixel of the current pixel of the same row is an edge pixel, so as to record the information of the new line; wherein the subsequent neighbor pixel of the edge pixel is in the same column as the previous neighbor pixel of the current pixel that has the step record.

[0255] In some embodiments, the second determining module 332 is configured to: when the preceding neighboring pixel in a different row from the current pixel does not have a step record, take the current pixel as the first endpoint pixel of the row, and search for a second endpoint pixel in the horizontal direction pointed to by the line detection direction from the first endpoint pixel; wherein, pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels; when the preceding neighboring pixel in a different row from the current pixel does not have a step record, and the preceding neighboring pixel in a different row from the second endpoint pixel has a step record, and the subsequent neighboring pixel in a different row from the second endpoint pixel is an edge pixel, generate a step record for the current pixel based on the step record of the preceding neighboring pixel in a different row from the second endpoint pixel; and take the current pixel as the starting point of a new line, generate a step record for the second endpoint pixel to record the information of the new line; wherein, the subsequent neighboring pixel of the edge pixel and the preceding neighboring pixel of the second endpoint pixel that has the step record are in the same column.

[0256] In some embodiments, the second determining module 332 is configured to: generate a step record for the current pixel based on the step record of the preceding neighbor pixel that is not in the same row as the first endpoint pixel, and a preceding neighbor pixel that is not in the same row as the second endpoint pixel that has a step record, and a subsequent neighbor pixel that is not in the same row as the second endpoint pixel that is a non-edge pixel; wherein the subsequent neighbor pixel that is a non-edge pixel is in the same column as the preceding neighbor pixel of the second endpoint pixel that has the step record.

[0257] In some embodiments, the second determining module 332 is configured to: when there is no step record for the preceding neighboring pixel that is not in the same row as the first endpoint pixel, and no step record for the preceding neighboring pixel that is not in the same row as the second endpoint pixel, take the second endpoint pixel as the starting point of the new line and generate a step record for the current pixel to record the information of the new line.

[0258] In some embodiments, the second determining module 332 is configured to: when the preceding adjacent pixel not in the same row as the first endpoint pixel does not have a step record, and the preceding adjacent pixel not in the same row as the second endpoint pixel does not have a step record, and the subsequent adjacent pixel not in the same row as the second endpoint pixel is an edge pixel, take the current pixel as the starting point of a new line and generate a step record for the second endpoint pixel to record the information of the new line; wherein the angle between the direction from the second endpoint pixel to the subsequent adjacent pixel that is an edge pixel and the direction from the current pixel to the second endpoint pixel is less than 90 degrees.

[0259] In some embodiments, the lines are preferentially updated / grown in the horizontal direction until they can no longer be updated / grown.

[0260] In some embodiments, the second determining module 332 is configured to: when the horizontal left neighbor pixel and the horizontal right neighbor pixel of the current pixel are non-edge pixels, based on determining that the previous neighbor pixel with the step record of the current pixel is located in the vertical direction of the current pixel, take the previous neighbor pixel with the step record as the end point of the line, and output the starting point coordinates and ending point coordinates of the line through the second output module 333.

[0261] In some embodiments, the second determining module 332 is configured to: when the horizontal left neighbor and horizontal right neighbor of the current pixel are non-edge pixels, determine that the current pixel can be added as a target pixel of the line based on the determination that the current pixel has two preceding neighbor pixels with the step record, and that they are located in two diagonal directions of the current pixel respectively; and generate a step record of the current pixel based on the step record of the preceding neighbor pixels read first.

[0262] In some embodiments, the line detection device 330 further includes an acquisition module configured to acquire edge feature data of a second window size, the edge feature data including values ​​indicating whether the current pixel and its neighboring pixels are edge pixels; wherein the neighboring pixels of the current pixel include previous neighboring pixels and subsequent neighboring pixels.

[0263] The above description of the embodiment of device 330 is similar to the description of the method embodiment for detecting horizontal lines described above, and has similar beneficial effects as the method embodiment. For technical details not disclosed in the device embodiments of this application, please refer to the description of the method embodiment for detecting horizontal lines of this application for understanding.

[0264] It should be noted that the line detection device 320 and line detection device 330 provided in this application embodiment can be the same device or different devices; when they are the same device, the first determining module 321 and the fourth determining module 331 are the same module, the first determining module 322 and the second determining module 332 are the same module, and the first output module 323 and the second output module 333 are the same module; when they are different devices, each module is independent of each other, and the two devices can operate in parallel.

[0265] In the embodiments of this application, the module division of the line detection device is illustrative and represents only one logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, exist as separate physical units, or have two or more units integrated into one unit. The integrated units can be implemented in hardware, as software functional units, or a combination of software and hardware.

[0266] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.

[0267] This application provides a chip, Figure 34 This is a schematic diagram of the chip structure provided in the embodiments of this application, such as... Figure 34 As shown, chip 340 includes processor 341 and memory 342; wherein, processor 341 is configured to execute the line detection method described in the embodiments of this application; memory 342 is configured to store input data and output data required by the processor in the process of executing the line detection method.

[0268] This application provides an electronic device. Figure 35 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application, such as... Figure 35 As shown, the electronic device 350 includes a chip 340 and a power module 341; wherein, the power module 341 is used to supply power to the chip 340.

[0269] This application provides an electronic device. Figure 36 This is a schematic diagram of the hardware entity of the electronic device according to an embodiment of this application, such as... Figure 36 As shown, the electronic device 360 ​​includes a memory 361 and a processor 362. The memory 361 stores a computer program that can run on the processor 362. When the processor 362 executes the program, it implements the steps in the method provided in the above embodiments.

[0270] It should be noted that the memory 361 is configured to store instructions and applications executable by the processor 362, and can also cache data to be processed or already processed (e.g., image data, audio data, voice communication data and video communication data) in the various modules of the processor 362 and the electronic device 360, which can be implemented by flash memory or random access memory (RAM).

[0271] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in the above embodiments.

[0272] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the method provided in the above-described method embodiments.

[0273] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0274] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" mentioned throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.

[0275] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.

[0276] 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 apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. 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 apparatus that includes that element.

[0277] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or modules can be electrical, mechanical, or other forms.

[0278] The modules described above as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.

[0279] In addition, each functional module in the various embodiments of this application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the integrated modules can be implemented in hardware or in the form of hardware plus software functional units.

[0280] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.

[0281] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0282] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.

[0283] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.

[0284] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.

[0285] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A line detection method, characterized in that, The method includes: Based on the step records of the preceding neighboring pixels that are not in the same row as the current pixel, and the positional relationship between the preceding neighboring pixels with the step records and the current pixel, a target pixel to be added to the line is determined from the current pixel and the pixels in the next row of the current pixel; the target pixel is an edge pixel; wherein, the current pixel and the preceding neighboring pixels with the step records are edge pixels, and the step records include at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating that the line type is a first type, the first type being a vertical line, and the second direction marker indicating the current detection direction of the line; Based on the determination that the target pixel is the end point of the line, at least the start point coordinates and end point coordinates of the line are output; Specifically, determining the target pixel of the line from the current pixel and the next row of pixels based on the step record and the positional relationship between the current pixel and the preceding neighboring pixel with the step record includes: Based on the positional relationship and the first and second direction markers in the step record, candidate pixels are determined from the next row of pixels of the current pixel; different second direction markers and / or different positional relationships correspond to different candidate pixels; The target pixel is determined based on the edge feature data of the candidate pixels; wherein the edge feature data includes a value indicating whether the candidate pixel is an edge pixel.

2. The method according to claim 1, characterized in that, When the positional relationship is such that the preceding neighboring pixel with the step record is directly above the current pixel, candidate pixels are determined from the next row of pixels of the current pixel based on the first direction marker and the second direction marker. If at least one of the candidate pixels is an edge pixel, a pixel is determined from the at least one candidate pixel that is an edge pixel as the target pixel.

3. The method according to claim 2, characterized in that, The method further includes: If each of the candidate pixels is a non-edge pixel, determine whether the horizontal right neighbor of the current pixel is an edge pixel; Based on the determination that the horizontal right neighbor of the current pixel is an edge pixel, the previous neighbor pixel with the step record is taken as the end point of the line, and at least the start point coordinates and end point coordinates of the line are output. Based on the determination that the horizontal right neighbor of the current pixel is a non-edge pixel, the current pixel is taken as the target pixel and as the endpoint of the line.

4. The method according to claim 1, characterized in that, When the positional relationship is such that the preceding neighboring pixel with the step record is to the upper left of the current pixel, a candidate pixel is determined from the next row of pixels of the current pixel according to the first direction mark and the second direction mark; If at least one of the candidate pixels is an edge pixel, a pixel is determined from the at least one candidate pixel that is an edge pixel as the target pixel.

5. The method according to claim 4, characterized in that, The method further includes: If each of the candidate pixels is a non-edge pixel, determine whether the current pixel can be used as the target pixel; Based on the determination that the current pixel can be used as the target pixel, the target pixel is used as the endpoint of the line; Based on the determination that the current pixel cannot be used as the target pixel, the preceding neighboring pixel with the step record is used as the end point of the line, and at least the starting point coordinates and the ending point coordinates of the line are output.

6. The method according to claim 1, characterized in that, When the positional relationship is such that the preceding neighboring pixel with the step record is to the upper right of the current pixel, based on determining that the horizontal right neighboring pixel of the current pixel is a non-edge pixel, candidate pixels are determined from the next row of pixels of the current pixel according to the first direction mark and the second direction mark; If at least one of the candidate pixels is an edge pixel, a pixel is determined from the at least one candidate pixel that is an edge pixel as the target pixel.

7. The method according to claim 6, characterized in that, The method further includes: Based on the determination that any pixel in the next row of pixels of the current pixel and the horizontal right neighbor of the current pixel are both edge pixels, the previous neighbor pixel with the step record is taken as the end point of the line, and at least the starting point coordinates and the ending point coordinates of the line are output.

8. The method according to claim 6, characterized in that, The method further includes: Based on the determination that the right horizontal neighbor of the current pixel is an edge pixel and that the next row of pixels of the current pixel are all non-edge pixels, the previous neighbor pixel with the step record is taken as the end point of the line, and at least the starting point coordinates and the ending point coordinates of the line are output. Based on the fact that the rightmost pixel of the current pixel and the next row of pixels of the current pixel are both non-edge pixels, and that the current pixel can be used as a target pixel, the target pixel is used as the endpoint of the line; Based on the fact that the rightmost pixel of the current pixel and the next row of pixels of the current pixel are both non-edge pixels, and that the current pixel cannot be used as a target pixel, the preceding neighbor pixel with the step record is taken as the end point of the line, and at least the starting point coordinates and the ending point coordinates of the line are output.

9. The method according to any one of claims 1 to 8, characterized in that, The method further includes: Based on the determination that the target pixel cannot be the end point of the line, a step record of the target pixel is generated; and the next target pixel to be added to the line is determined until the end point of the line is determined.

10. The method according to any one of claims 1 to 8, characterized in that, The method further includes: Obtain edge feature data of a first window size, the edge feature data including values ​​indicating whether the current pixel and its neighboring pixels are edge pixels; wherein, the neighboring pixels of the current pixel include the previous neighboring pixels and the subsequent neighboring pixels.

11. The method according to any one of claims 1 to 8, characterized in that, If the number of preceding neighboring pixels with the step record is greater than 1, the target pixels to be added to the corresponding lines are determined in parallel for different preceding neighboring pixels with step records.

12. A line detection method, characterized in that, The method includes: If the horizontal left neighbor and / or horizontal right neighbor of the current pixel are non-edge pixels, the current pixel is determined to be added as the target pixel of the line based on the step record of the preceding neighbor pixel in a different row from the current pixel and the positional relationship between the preceding neighbor pixel with the step record and the current pixel; wherein the current pixel and the preceding neighbor pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker and a second direction marker, the first direction marker indicating that the line type is a second type, the second type is a horizontal line, and the second direction marker indicating the current detection direction of the line; wherein, for multiple consecutive edge pixels in the same row, a step record is set at the end along the growth direction; the growth rules of the line include a first priority and a second priority, the first priority being higher than the second priority, the first priority including preferential growth along the horizontal direction until no further growth is possible; the second priority including upper left priority over upper right priority; Based on the determination that the current pixel is increased to the target pixel and the line termination condition is met, the current pixel is taken as the end point of the line, and the starting point coordinates and ending point coordinates of the line are output.

13. The method according to claim 12, characterized in that, The method further includes: When it is determined that the line termination condition is not met and the target pixel is the first endpoint pixel of the row, the second endpoint pixel in the horizontal direction is searched from the first endpoint pixel according to the horizontal direction pointed to by the current detection direction; wherein, the pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels; If a preceding neighboring pixel that is not in the same row as the second endpoint pixel has a step record, the step record of the current pixel is generated based on the step record of the preceding neighboring pixel of the second endpoint pixel, and the step record of the second endpoint pixel is generated based on the step record of the preceding neighboring pixel of the current pixel.

14. The method according to claim 13, characterized in that, The method further includes: If the preceding neighboring pixel on a different row from the second endpoint pixel does not have a step record, a step record for the second endpoint pixel is generated based on the step records of the preceding neighboring pixels of the current pixel; and If the preceding neighboring pixel that is not in the same row as the second endpoint pixel does not have a step record, and the following neighboring pixel that is not in the same row as the current pixel is an edge pixel, the second endpoint pixel is used as the starting point of a new line to generate a step record for the current pixel to record the information of the new line; wherein, the following neighboring pixel that is an edge pixel is in the same column as the preceding neighboring pixel of the current pixel that has the step record.

15. The method according to claim 12, characterized in that, The method further includes: If there is no step record between the preceding adjacent pixels in a different row from the current pixel, the current pixel is taken as the first endpoint pixel of the row, and the second endpoint pixel in the horizontal direction is searched from the first endpoint pixel according to the horizontal direction pointed by the line detection direction; wherein, the pixels on the horizontal line connecting the first endpoint pixel and the second endpoint pixel are all edge pixels. In the case where the preceding neighboring pixel not in the same row as the current pixel does not have a step record, and the preceding neighboring pixel not in the same row as the second endpoint pixel has a step record, and the subsequent neighboring pixel not in the same row as the second endpoint pixel is an edge pixel, a step record for the current pixel is generated based on the step record of the preceding neighboring pixel not in the same row as the second endpoint pixel; and the current pixel is used as the starting point of a new line to generate a step record for the second endpoint pixel, in order to record the information of the new line; Wherein, the subsequent neighboring pixel of the edge pixel and the preceding neighboring pixel of the second endpoint pixel having the step record are in the same column.

16. The method according to claim 15, characterized in that, The method further includes: In the case where the preceding neighboring pixel not in the same row as the first endpoint pixel does not have a step record, and the preceding neighboring pixel not in the same row as the second endpoint pixel has a step record, and the subsequent neighboring pixel not in the same row as the second endpoint pixel is a non-edge pixel, the step record of the current pixel is generated based on the step record of the preceding neighboring pixel not in the same row as the second endpoint pixel. Wherein, the subsequent neighboring pixel of a non-edge pixel is in the same column as the preceding neighboring pixel of the second endpoint pixel that has the step record.

17. The method according to claim 15, characterized in that, The method further includes: If there is no step record for the preceding neighboring pixel that is not in the same row as the first endpoint pixel, and there is no step record for the preceding neighboring pixel that is not in the same row as the second endpoint pixel, the second endpoint pixel is used as the starting point of the new line to generate the step record of the current pixel, so as to record the information of the new line.

18. The method according to claim 15, characterized in that, The method further includes: In the case where the preceding neighboring pixel that is not in the same row as the first endpoint pixel does not have a step record, and the preceding neighboring pixel that is not in the same row as the second endpoint pixel does not have a step record, and the subsequent neighboring pixel that is not in the same row as the second endpoint pixel is an edge pixel, the current pixel is used as the starting point of the new line, and a step record of the second endpoint pixel is generated to record the information of the new line. Wherein, the angle between the direction from the second endpoint pixel to the next adjacent pixel that is an edge pixel and the direction from the current pixel to the second endpoint pixel is less than 90 degrees.

19. The method according to claim 12, characterized in that, The lines are updated primarily along the horizontal direction until no further updates are possible.

20. The method according to claim 12, characterized in that, If the horizontal left and right adjacent pixels of the current pixel are non-edge pixels, based on the determination that the previous adjacent pixel with the step record of the current pixel is located in the vertical direction of the current pixel, the previous adjacent pixel with the step record is taken as the end point of the line, and the starting point coordinates and ending point coordinates of the line are output.

21. The method according to claim 12, characterized in that, If the horizontal left and right adjacent pixels of the current pixel are non-edge pixels, based on the determination that the current pixel has two preceding adjacent pixels with the step record, and that they are located in the two diagonal directions of the current pixel, it is determined that the current pixel can be added as the target pixel of the line, and the step record of the current pixel is generated according to the step record of the preceding adjacent pixels read first.

22. The method according to any one of claims 12 to 21, characterized in that, The method further includes: Obtain edge feature data of a second window size, the edge feature data including values ​​indicating whether the current pixel and its neighboring pixels are edge pixels; wherein, the neighboring pixels of the current pixel include the previous neighboring pixels and the subsequent neighboring pixels.

23. A line detection method, characterized in that, The method includes: Based on the first direction marker of the step record of the preceding neighboring pixel that is not in the same row as the current pixel, indicating that the line type of the line is a first type, the steps of the line detection method as described in any one of claims 1 to 11 are performed; wherein the current pixel and the preceding neighboring pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, the first direction marker and the second direction marker, the first direction marker indicating the line type of the line, and the second direction marker indicating the current detection direction of the line; Based on determining that the line type represented by the first direction mark is the second type, the steps in the line detection method as described in any one of claims 12 to 22 are performed.

24. A line detection device, characterized in that, include: The first determining module is configured to determine, based on the step record of the preceding neighboring pixel not in the same row as the current pixel, and the positional relationship between the preceding neighboring pixel with the step record and the current pixel, a target pixel to be added to the line from the current pixel and the next row of pixels of the current pixel; the target pixel is an edge pixel; wherein, the current pixel and the preceding neighboring pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker and a second direction marker, the first direction marker indicating that the line type is a first type, the first type being a vertical line, and the second direction marker indicating the current detection direction of the line; The first output module is configured to output at least the start coordinates and end coordinates of the line based on determining that the target pixel is the end point of the line; The first determining module is further configured to determine candidate pixels from the next row of pixels of the current pixel based on the positional relationship and the first and second direction markers in the step record; different second direction markers and / or different positional relationships correspond to different candidate pixels; and determine the target pixel based on the edge feature data of the candidate pixels; wherein the edge feature data includes a value indicating whether the candidate pixel is an edge pixel.

25. A line detection device, characterized in that, include: The second determining module is configured to, when the horizontal left-adjacent pixel and / or horizontal right-adjacent pixel of the current pixel are non-edge pixels, determine whether the current pixel should be added as a target pixel of the line based on the step record of the preceding neighboring pixel in a different row from the current pixel and the positional relationship between the preceding neighboring pixel with the step record and the current pixel; wherein the current pixel and the preceding neighboring pixel with the step record are edge pixels, and the step record includes at least the starting coordinates of the corresponding detected line, a first direction marker, and a second direction marker, the first direction marker indicating that the line type is a second type, the second type being a horizontal line, and the second direction marker indicating the current detection direction of the line; wherein, for multiple consecutive edge pixels in the same row, a step record is set at the end along the growth direction; the growth rules of the line include a first priority and a second priority, the first priority being higher than the second priority, the first priority including preferential growth along the horizontal direction until no further growth is possible; the second priority including upper left priority over upper right priority; The second output module, based on the determination that the current pixel is increased to the target pixel and the line termination condition is met, terminates the growth of the line, takes the current pixel as the end point of the line, and outputs the start point coordinates and end point coordinates of the line.

26. A chip, characterized in that, include: Processor and memory; among which, The processor is configured to perform the method according to any one of claims 1 to 11, and / or perform the method according to any one of claims 12 to 22; The memory is configured to store input and output data required by the processor in the process of performing the method according to any one of claims 1 to 11 and the method according to any one of claims 12 to 22.

27. An electronic device, characterized in that, It includes a power module and a chip as described in claim 26; wherein the power module is used to supply power to the chip.

28. An electronic device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the method according to any one of claims 1 to 11, and / or, when the processor executes the program, it implements the method according to any one of claims 12 to 22.

29. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the method as claimed in any one of claims 1 to 11 and / or the method as claimed in any one of claims 12 to 22.

Citation Information

Patent Citations

  • Lane line identification method, device and equipment and storage medium

    CN109583280A

  • Image processing method, display device, electronic equipment and storage medium

    CN113139921A