A straight line detection method, device, apparatus and storage medium

By determining the angle information of the detection path and the scanning direction to obtain sub-pixel edge points for linear fitting, the problem of poor robustness of line detection in the existing technology is solved, and more accurate line detection is achieved.

CN116309660BActive Publication Date: 2026-04-28ZHONGKE HUIYUAN VISUAL TECHNOLOGY (LUOYANG) CO LTD +1
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ZHONGKE HUIYUAN VISUAL TECHNOLOGY (LUOYANG) CO LTD
Filing Date
2023-04-04
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

Existing line detection methods are not robust enough when dealing with images in noisy environments, and it is difficult to accurately detect target lines when the target object is of poor quality or the background is cluttered.

Method used

By determining the angle information of the detection path, the first edge point of the target edge is calculated, the second edge point is obtained using the scanning direction, and the sub-pixel edge point is calculated based on the re-judgment direction. Finally, linear fitting is performed to obtain more accurate straight line detection results.

Benefits of technology

It improves the accuracy of line detection at the sub-pixel level, reduces noise interference, and enhances the ability to detect lines in complex environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116309660B_ABST
    Figure CN116309660B_ABST
Patent Text Reader

Abstract

The present disclosure provides a straight line detection method and device, equipment and storage medium, which relates to the technical field of image processing. The method mainly comprises: determining the angle information corresponding to the detection path of the to-be-detected region according to the target position information of the to-be-detected region in the to-be-detected image, and the target position information comprises a target starting point of the to-be-detected region; calculating a first edge point of a target edge in the to-be-detected region according to the angle information and the target starting point; scanning the to-be-detected region according to the scanning direction of the to-be-detected region and the first edge point, and obtaining a second edge point of the target edge; calculating a sub-pixel edge point corresponding to the target edge according to the re-judgment direction and the second edge point; and performing linear fitting on the sub-pixel edge point to obtain a straight line detection result corresponding to the target edge.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of image processing technology, and in particular to a method, apparatus, device and storage medium for line detection. Background Technology

[0002] When processing images using computer vision, it is often necessary to detect the precise location of specific lines in the image for operations such as establishing coordinate systems or accurately locating target objects. Existing line detection methods typically first obtain edge points from the target contour, and then use the least squares method to fit the edge points to obtain the target line.

[0003] However, existing line detection methods are not robust to noise when dealing with images with complex environmental noise. The line detection results are easily affected by noise. When the quality of the target object itself is poor, it is impossible to accurately detect the target line. In addition, if the background of the image is cluttered and there are multiple lines of the target object, existing line detection methods also have difficulty detecting the target line accurately. Summary of the Invention

[0004] This disclosure provides a method, apparatus, device, and storage medium for linear detection, to at least solve the above-mentioned technical problems existing in the prior art.

[0005] According to a first aspect of this disclosure, a line detection method is provided, the method comprising: determining angle information corresponding to a detection path of a region to be detected based on target position information of a region to be detected in an image to be detected, wherein the target position information includes a target starting point of the region to be detected; calculating a first edge point of a target edge in the region to be detected based on the angle information and the target starting point; scanning the region to be detected based on the scanning direction of the region to be detected and the first edge point to obtain a second edge point of the target edge; calculating a sub-pixel edge point corresponding to the target edge based on the re-judgment direction and the second edge point; and performing linear fitting on the sub-pixel edge points to obtain a line detection result corresponding to the target edge.

[0006] According to a second aspect of this disclosure, a line detection apparatus is provided, comprising: a determining module, configured to determine angle information corresponding to a detection path of a region to be detected based on target position information of a region to be detected in an image to be detected, wherein the target position information includes a target starting point of the region to be detected; a first calculation module, configured to calculate a first edge point of a target edge in the region to be detected based on the angle information and the target starting point; a scanning module, configured to scan the region to be detected based on a scanning direction of the region to be detected and the first edge point to obtain a second edge point of the target edge; a second calculation module, configured to calculate a sub-pixel edge point corresponding to the target edge based on a re-judgment direction and the second edge point; and a linear fitting module, configured to perform linear fitting on the sub-pixel edge points to obtain a line detection result corresponding to the target edge.

[0007] According to a third aspect of this disclosure, an electronic device is provided, comprising:

[0008] At least one processor; and

[0009] A memory communicatively connected to the at least one processor; wherein,

[0010] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the methods described in this disclosure.

[0011] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to perform the methods described in this disclosure.

[0012] The present invention discloses a line detection method, apparatus, device, and storage medium. First, a first edge point of the target edge is determined based on the detection direction, and a second edge point of the target edge is determined based on the scanning direction and the first edge point, thereby obtaining more accurate edge points. Then, based on the re-judgment direction of the second edge point, the sub-pixel edge point corresponding to the target edge is determined, and linear fitting is performed based on the sub-pixel edge point to obtain the line detection result corresponding to the target edge. Thus, fitting the target edge at the sub-pixel level can obtain a more accurate line detection result.

[0013] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0014] The above and other objects, features, and advantages of this disclosure will become readily apparent from the following detailed description of exemplary embodiments, taken in conjunction with the accompanying drawings. Several embodiments of this disclosure are illustrated in the drawings by way of example and not limitation, in which:

[0015] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts.

[0016] Figure 1 A flowchart illustrating a line detection method according to a first embodiment of this disclosure is shown.

[0017] Figure 2 A schematic diagram of a first scenario of a line detection method according to a first embodiment of the present disclosure is shown;

[0018] Figure 3 A second scene schematic diagram of a line detection method according to the first embodiment of this disclosure is shown;

[0019] Figure 4 A flowchart illustrating a line detection method according to a second embodiment of the present disclosure is shown;

[0020] Figure 5 A flowchart illustrating a line detection method according to a third embodiment of this disclosure is shown;

[0021] Figure 6 A schematic diagram of a scenario for a line detection method according to the fourth embodiment of this disclosure is shown;

[0022] Figure 7 A flowchart illustrating a line detection method according to a fifth embodiment of this disclosure is shown;

[0023] Figure 8 A schematic diagram of a scenario for a line detection method according to the sixth embodiment of this disclosure is shown;

[0024] Figure 9 A schematic flowchart of a line detection method according to the tenth embodiment of this disclosure is shown;

[0025] Figure 10 A schematic diagram of the structure of a line detection device according to the eleventh embodiment of this disclosure is shown;

[0026] Figure 11 A schematic diagram of the composition structure of an electronic device according to an embodiment of the present disclosure is shown. Detailed Implementation

[0027] To make the objectives, features, and advantages of this disclosure more apparent and understandable, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.

[0028] Figure 1 A schematic flowchart of a line detection method according to a first embodiment of this disclosure is shown, as follows: Figure 1 As shown, the method mainly includes:

[0029] Step S101: Determine the angle information corresponding to the detection path of the region to be detected based on the target position information of the region to be detected in the image to be detected.

[0030] In this embodiment, firstly, based on the target position information of the region to be detected in the image to be detected, the angle information corresponding to the detection path of the region to be detected is determined. The target position information refers to the position of the region to be detected in the image to be detected, including the scanning width of the region, the target start point, and the target end point. The detection path is a straight line path from the target start point to the target end point, and the angle information corresponding to the detection path is the angle of the line connecting the target start point and the target end point. Specifically, the angle of the line connecting the target start point and the target end point can be calculated using trigonometric functions, and this angle is determined as the angle information corresponding to the detection path. This angle can be the angle between the line connecting the target start point and the target end point and the vertical axis, or it can be the angle between the line connecting the target start point and the target end point and the horizontal axis. It should be emphasized that the angle information mentioned below in this disclosure refers to the angle between the line connecting the target start point and the target end point and the vertical axis.

[0031] Figure 2 A schematic diagram of a first scene of a line detection method according to a first embodiment of the present disclosure is shown, as follows: Figure 2 As shown, if the right edge of the target object in the image to be detected is the target edge, then the target start point and target end point are input based on the right edge of the target object, and the scan width of the area to be detected is also input to determine the area to be detected. The straight line path between the target start point and the target end point is the detection path, and the detection path is roughly located on the right edge of the target object. Specifically, the target start point and target end point can be input by clicking on the right edge of the target object with the mouse, and the scan width of the area to be detected can be determined by dragging the mouse.

[0032] Step S102: Calculate the first edge point of the target edge in the area to be detected based on the angle information and the target starting point.

[0033] In this embodiment, the first edge point of the target edge in the area to be detected can be calculated based on the angle information of the detection path and the target starting point of the area to be detected. That is, the coordinates of the pixels on the detection path can be calculated. Since the detection path is roughly located on the target edge, the pixels on the detection path can be regarded as the first edge point on the target edge. Specifically, the direction from the target starting point to the target ending point can be used as the detection direction, and the coordinates of the pixels on the detection path can be calculated along the detection direction.

[0034] Step S103: Scan the area to be detected according to the scanning direction of the area to be detected and the first edge point to obtain the second edge point of the target edge.

[0035] In this embodiment, the region to be detected can be scanned according to the scanning direction and the first edge point to obtain the second edge point of the target edge. The scanning direction is the direction in which the region to be detected is scanned, and the scanning direction is perpendicular to the detection direction. Specifically, the path in the region to be detected along the scanning direction and passing through the first edge point can be determined as the scanning path, and the scanning path is scanned along the scanning direction to obtain the second edge point of the target edge. The second edge point is a pixel whose grayscale difference between its two adjacent pixels along the scanning direction meets a preset threshold. The preset threshold can be set according to actual conditions.

[0036] Step S104: Calculate the sub-pixel edge points corresponding to the target edge based on the re-judgment direction and the second edge point.

[0037] In this embodiment, the sub-pixel edge point corresponding to the target edge can be calculated based on the re-judgment direction and the second edge point. The re-judgment direction is the neighborhood direction corresponding to the second edge point. Parabolic fitting can be performed on the gray values ​​of two adjacent pixels of the second edge point and the second edge point along the re-judgment direction, and the extreme point of the parabolic fitting result is determined as the sub-pixel edge point.

[0038] Figure 3 A second scene schematic diagram of a line detection method according to the first embodiment of this disclosure is shown, as follows: Figure 3 As shown in Figure a, if the neighborhood property of a pixel is 8-neighborhood, then based on the 8-neighborhood, there are as follows: Figure 3 b and Figure 3 The eight directions shown in c can be used to determine the neighborhood direction of the second edge point based on the angle information of the detection path. For example, if the angle information of the detection path is 90 degrees, that is, the detection path is perpendicular to the vertical axis, then the neighborhood direction corresponding to the detection path can be initially determined to be the left-right direction. Furthermore, if the x-coordinate of the target's starting point is less than the x-coordinate of the target's ending point, then the neighborhood direction corresponding to the detection path can be considered to be from left to right, that is, the re-determined direction is... Figure 3The direction indicated by the horizontal right-pointing arrow in b; it can be understood that if the difference between the angle information of the detection path and 90 degrees is less than the preset angle, then the neighborhood direction corresponding to the detection path can be preliminarily determined to be the left and right direction. The preset angle can be set according to the actual situation.

[0039] Step S105: Perform linear fitting on the sub-pixel edge points to obtain the line detection result corresponding to the target edge.

[0040] In this embodiment, after obtaining the sub-pixel edge points corresponding to the target edge, the sub-pixel edge points can be linearly fitted according to the least squares method to obtain the line detection result corresponding to the target edge.

[0041] In the first embodiment of this disclosure, a first edge point of the target edge is first determined based on the detection direction, and a second edge point of the target edge is determined based on the scanning direction and the first edge point, thereby obtaining more accurate edge points; then, based on the re-judgment direction of the second edge point, the sub-pixel edge point corresponding to the target edge is determined, and linear fitting is performed based on the sub-pixel edge point to obtain the line detection result corresponding to the target edge. Thus, fitting the target edge at the sub-pixel level can obtain a more accurate line detection result.

[0042] Figure 4 A flowchart illustrating a line detection method according to a second embodiment of this disclosure is shown, as follows: Figure 4 As shown, the target location information of the region to be detected in the image to be detected in step S101 can be obtained according to the following method:

[0043] Step S201: Obtain the first scan width of the original detection region in the original image.

[0044] In this embodiment, the first scanning width of the original detection region in the original image is first obtained. Specifically, after inputting the original detection region based on the target edge in the original image, the width of the original detection region can be obtained as the first scanning width.

[0045] It should be emphasized that, in addition to inputting the original detection area, this disclosure can also input the limiting conditions for line detection, such as whether to convert the image coordinates to world coordinates; whether to perform binarization processing on the detection image; and the edge attributes of the detection image, including all edge points of the detection image, background-to-foreground edge points, and foreground-to-background edge points, etc.

[0046] Step S202: Determine the area to be detected based on the first scan width and the original detection area.

[0047] In this embodiment, the region to be detected can be determined based on the first scan width and the original detection area. Specifically, if the first scan width is greater than a first preset threshold, the original detection area is adjusted to obtain the region to be detected; if the first scan width is not greater than the first preset threshold, the original detection area is determined as the region to be detected.

[0048] Step S203: Based on the minimum bounding rectangle of the region to be detected, the original image is cropped to obtain the image to be detected.

[0049] In this embodiment, the original image can be cropped based on the minimum bounding rectangle of the region to be detected, that is, only the image enclosed by the minimum bounding rectangle is retained, thereby obtaining the image to be detected.

[0050] In one embodiment, the minimum bounding rectangle of the region to be detected can be obtained as follows: Based on the initial position information of the region to be detected, the coordinates of the pixels within the region to be detected are obtained to form a coordinate set; the x-coordinates in the coordinate set are compared to obtain the maximum and minimum x-coordinates, and the y-coordinates in the coordinate set are compared to obtain the maximum and minimum y-coordinates; based on the maximum, minimum, maximum, and minimum y-coordinates, the minimum bounding rectangle of the region to be detected is determined. Specifically, the four vertices of the minimum bounding rectangle can be determined based on the maximum, minimum, maximum, and minimum y-coordinates, thereby determining the minimum bounding rectangle.

[0051] In one possible implementation, after obtaining the image to be detected, the image to be detected can be binarized according to a binarization threshold to obtain a binarized image to be detected. Accordingly, the binarized image to be detected can be determined as the final image to be detected, and thus used for line detection. The binarization threshold can be set according to the actual situation.

[0052] Step S204: Based on the coordinate transformation relationship between the image to be detected and the original image, the initial position information of the region to be detected is converted into the target position information.

[0053] In this embodiment, it is also necessary to convert the initial position information of the region to be detected into target position information based on the coordinate transformation relationship between the image to be detected and the original image. The initial position information of the region to be detected is its position information within the original image. Therefore, after cropping the original image to obtain the image to be detected, the initial position information needs to be mapped onto the image to obtain the target position information of the region to be detected within the image. Specifically, the initial position information can be converted into target position information using a coordinate remapping function or similar method.

[0054] Figure 5A flowchart illustrating a line detection method according to a third embodiment of this disclosure is shown, as follows: Figure 5 As shown, the original detection area is adjusted to obtain the area to be detected, which mainly includes:

[0055] Step S301: Scan the original detection area to obtain the third edge point of the target edge.

[0056] In this embodiment, the original detection area is first scanned along the scanning direction to obtain the third edge point of the target edge. The third edge point is a pixel whose grayscale average value along the scanning direction and its adjacent first pixel set and second pixel set satisfies a second preset threshold. Specifically, if the scanning direction is from left to right, for all pixels in the original detection area along the scanning direction, it is determined whether the difference in grayscale average value between the first pixel set to the left and the second pixel set to the right satisfies the second preset threshold. If it does, the pixel is determined as the third edge point of the target edge. The first pixel set consists of a preset number of pixels adjacent to the left of the pixel, and the second pixel set consists of a preset number of pixels adjacent to the right of the pixel. The preset number can be set according to the actual situation.

[0057] Step S302: Perform linear fitting on the third edge point to obtain the initial edge line.

[0058] Step S303: Calculate the intersection point of the initial edge line and the boundary of the original detection area to obtain the target start point and target end point of the area to be detected.

[0059] In this embodiment, linear fitting is performed on the third edge point to obtain the initial edge line corresponding to the target edge, and the intersection of the initial edge line and the boundary of the original detection area is calculated to obtain the target start point and target end point of the area to be detected. Specifically, based on the first start point, first end point, and first scan width of the original detection area input from the target edge in the original image, the boundary of the original detection area can be determined, and the intersection of the initial edge line and the boundary of the original detection area is the target start point and target end point of the area to be detected.

[0060] Step S304: Determine the area to be detected based on the first preset threshold, the target start point, and the target end point.

[0061] In this embodiment, the first preset threshold is the maximum scanning width of the area to be detected, which is set in advance. Therefore, the area to be detected can be determined based on the target start point, the target end point, and the first preset threshold. Preferably, the first preset threshold can be 20 pixels in length.

[0062] In the second and third embodiments of this disclosure, the original detection region is adjusted according to the first scanning width of the original detection region in the original image. The resulting detection region not only has more accurate target start point and target end point, but also has a reduced scanning width, thereby improving the scanning speed of the detection region. In addition, binarizing the acquired detection image can reduce noise in the detection image, making the target edge clearer, and further improving the accuracy of the line detection result.

[0063] In the fourth embodiment of this disclosure, step S102 mainly includes:

[0064] Based on the detection step size and angle information, calculate the first horizontal offset and the first vertical offset of the first pixel on the detection path relative to the target starting point; based on the target starting point, the first horizontal offset and the first vertical offset, calculate the first edge point of the target edge in the region to be detected.

[0065] In this embodiment, firstly, based on the detection step size and angle information, the first horizontal offset and the first vertical offset of the first pixel on the detection path relative to the target starting point are calculated, where the horizontal offset is the offset on the horizontal coordinate and the vertical offset is the offset on the vertical coordinate. Then, based on the target starting point, the first horizontal offset, and the first vertical offset, the first edge point of the target edge in the area to be detected is calculated. Specifically, the detection step size can be set according to the actual situation. If the detection step size is 1, then every pixel on the detection path is considered to be the first pixel. Starting from the target starting point, the first horizontal offset and the first vertical offset of each first pixel on the detection path relative to the target starting point are calculated sequentially. For the first first pixel after the target starting point on the detection path, its straight-line distance from the target starting point can be considered to be 1. For the second first pixel after the target starting point on the detection path, its straight-line distance from the target starting point can be considered to be 2, and so on.

[0066] Figure 6 A schematic diagram of a scene for a line detection method according to the fourth embodiment of this disclosure is shown, such as... Figure 6 As shown, the angle information corresponding to the detection path is the degree measure of angle A. Figure 6 If the first pixel mentioned in the diagram is the nth first pixel after the target starting point, and the detection step size is 1, then its straight-line distance from the target starting point is n. Based on this straight-line distance n and the degree measure of angle A, the first horizontal offset and the first vertical offset of the first pixel relative to the target starting point can be calculated using trigonometric functions. The first horizontal offset is... Figure 6 The length of the dashed line d, and the first vertical offset are respectively. Figure 6The length of the dashed line e is determined, and then the coordinates of the first pixel can be calculated based on the coordinates of the target starting point, the first horizontal offset, and the first vertical offset. This first pixel is the first edge point of the target edge.

[0067] In the fourth embodiment of this disclosure, a first edge point of the target edge is calculated based on the target starting point and the first horizontal offset and the first vertical offset of the first pixel point on the detection path relative to the target starting point. The first edge point can preliminarily characterize the pixel point on the target edge, which facilitates the subsequent use of the first edge point to obtain a more accurate second edge point on the target edge.

[0068] Figure 7 A schematic flowchart of a line detection method according to a fifth embodiment of this disclosure is shown, as follows: Figure 7 As shown, step S103 mainly includes:

[0069] Step S401: Calculate the second pixel point on the scanning path along the scanning direction based on the scanning step length, angle information, and the first edge point.

[0070] In this embodiment, the second pixel point on the scanning path is first calculated along the scanning direction based on the scanning step size, angle information, and the first edge point. The scanning path is the path along the scanning direction and passing through the first edge point. The endpoints of the scanning path can be determined based on the second scanning width of the area to be detected. The scanning step size can be set according to the actual situation. If the scanning step size is 1, then each pixel point on the scanning path is determined as the second pixel point along the scanning direction.

[0071] Step S402: Obtain the grayscale gradient of the second pixel.

[0072] Step S403: Determine the second edge point of the target edge based on the grayscale gradient.

[0073] In this embodiment, it is also necessary to obtain the grayscale gradient of the second pixel and determine the second edge point of the target edge based on the grayscale gradient, that is, the second pixel whose grayscale gradient is greater than a third preset threshold is determined as the second edge point of the target edge. Specifically, the grayscale gradient of the second pixel can be determined based on the first derivative of the second pixel along the scanning direction; or, the grayscale gradient of the second pixel can be obtained based on the Sobel operator, where the first derivative is the difference in grayscale values ​​between two adjacent pixels along the scanning direction of the second pixel.

[0074] In the sixth embodiment of this disclosure, step S401 mainly includes:

[0075] Based on the second scan width and scan step size, calculate the straight-line distance between the second pixel and the first edge point; based on the straight-line distance and angle information, calculate the second horizontal offset and the second vertical offset of the second pixel relative to the first edge point; based on the first edge point, the second horizontal offset, and the second vertical offset, calculate the second pixel on the scan path, where the second scan width is the width of the area to be detected.

[0076] Figure 8 A schematic diagram of a scene for a line detection method according to the sixth embodiment of this disclosure is shown, as follows: Figure 8 As shown, with Figure 8 Taking the first edge point indicated in the middle as an example, this first edge point is... Figure 6 The first pixel indicated in the image, the scan path along the scan direction and passing through the first edge point is as follows: Figure 8 As shown by the straight line s, the angle of the scanning path is the degree measure of angle B. It can be understood that the degree measure of angle B is equal to... Figure 6 The degree measure of angle A. When calculating the second pixel on the scan path, first calculate the straight-line distance between the second pixel and the first edge point, so as to... Figure 8 Taking the second pixel as an example, its straight-line distance from the first edge point is half of the second scan width. If the second scan width is 20 pixels and the scan step size is 1, then its straight-line distance from the first edge point is 10 pixels. The straight-line distance between the next second pixel and the first edge point is 9 pixels, and so on. Then, based on the straight-line distance and angle information, the second horizontal offset and the second vertical offset of the second pixel relative to the first edge point are calculated. Figure 8 Taking the second pixel as an example, the second horizontal offset and the second vertical offset can be calculated using trigonometric functions based on its straight-line distance from the first edge point and the degree of angle B. The second horizontal offset is... Figure 8 The length of the dashed line f, and the second vertical offset are... Figure 8 The length of the dashed line g; finally, based on the first edge point, the second horizontal offset, and the second vertical offset, the second pixel point on the scan path is calculated sequentially.

[0077] In the seventh embodiment of this disclosure, step S403 mainly includes:

[0078] The second pixel with a grayscale gradient greater than a third preset threshold is determined as the initial second edge point of the target edge; the third pixel set and the fourth pixel set adjacent to the initial second edge point along the scanning direction are obtained, and the first grayscale average value of the third pixel set and the second grayscale average value of the fourth pixel set are calculated; the second difference and ratio between the first grayscale average value and the second grayscale average value are calculated; the second edge point of the target edge is determined based on the initial second edge point, the second difference and the ratio.

[0079] In this embodiment, firstly, the second pixel point whose grayscale gradient is greater than the third preset threshold is determined as the initial second edge point of the target edge. Then, the third pixel point set and the fourth pixel point set adjacent to the initial second edge point along the scanning direction are obtained, and the first grayscale average value of the third pixel point set and the second grayscale average value of the fourth pixel point set are calculated. The number of pixels in the third pixel point set and the fourth pixel point set and the third preset threshold can be set according to the actual situation. Then, the second difference and ratio between the first grayscale average value and the second grayscale average value are calculated, and the second edge point of the target edge is determined according to the initial second edge point, the second difference and the ratio.

[0080] In this embodiment, when determining the second edge point of the target edge based on the initial second edge point, the second difference, and the ratio, it is first determined whether the second difference is greater than a fourth preset threshold and whether the ratio is greater than a fifth preset threshold to obtain a first judgment result. Here, both the second difference and the ratio can characterize the grayscale difference between the sets of adjacent pixels on both sides of the initial second edge point. Therefore, if the first judgment result is yes, it proves that the grayscale difference on both sides of the initial second edge point along the scanning direction is large, and the initial second edge point can be determined as the second edge point. If the first judgment result is no, it proves that the grayscale difference on both sides of the initial second edge point along the scanning direction is small, that is, the initial second edge point is not a point on the target edge. The initial second edge point can be used as the starting point to determine the first judgment result corresponding to other second pixels on the scanning path along the scanning direction, and the second pixel point corresponding to the first judgment result is determined as the second edge point.

[0081] In the fifth, sixth and seventh embodiments of this disclosure, the second pixel point on the scanning path is first calculated, and the second pixel point whose gray level gradient is greater than the third preset threshold is determined as the initial second edge point of the target edge. Then, based on the gray level difference of the pixel point set on both sides of the initial second edge point, it is determined whether the initial second edge point is the second edge point of the target edge. This can remove interference points in the detection area that are not edge points of the target edge but whose gray level gradient is also greater than the third preset threshold, thereby obtaining a more accurate second edge point.

[0082] In the eighth embodiment of this disclosure, step S104 mainly includes:

[0083] Based on the angle information, the re-judgment direction of the second edge point is determined, and two adjacent pixels of the second edge point along the re-judgment direction are obtained; parabolic fitting is performed on the gray values ​​of the second edge point and the two adjacent pixels to obtain the first fitting result; based on the extreme points of the first fitting result, the sub-pixel edge points corresponding to the target edge are determined.

[0084] In this embodiment, the re-judgment direction of the second edge point is first determined based on the angle information of the detection path, and two adjacent pixels of the second edge point along the re-judgment direction are obtained. The specific process of determining the re-judgment direction based on the angle information has been described in step S104 above, and will not be repeated here. Then, parabolic fitting is performed on the gray values ​​of the second edge point and the two adjacent pixels to obtain the first fitting result, and the sub-pixel edge point corresponding to the target edge is determined based on the extreme point of the first fitting result.

[0085] In one possible implementation, a grayscale coordinate system is first constructed with the re-judgment direction as the abscissa and the grayscale value of the pixel as the ordinate, where the smallest unit of the abscissa is the width of one pixel. Then, a parabolic fitting is performed using the abscissa and grayscale values ​​of the second edge point and two adjacent pixels to obtain a first fitting result. Finally, the maximum extreme point of the first fitting result is obtained, which is the sub-pixel edge point. The coordinates of the extreme point in the grayscale coordinate system can be converted to the coordinates of the extreme point in the two-dimensional coordinate system. Specifically, the abscissa of the extreme point in the grayscale coordinate system is the same as the abscissa of the extreme point in the two-dimensional coordinate system. Therefore, the ordinate of the extreme point in the two-dimensional coordinate system can be calculated based on the abscissa of the extreme point in the grayscale coordinate system, thereby obtaining the sub-pixel edge point.

[0086] In the ninth embodiment of this disclosure, after determining the sub-pixel edge points corresponding to the target edge, a line detection method further includes:

[0087] According to the random consistency sampling method, sub-pixel edge points that meet the first preset condition are selected to obtain initial sub-pixel points; the gradient direction of the initial sub-pixel edge points is calculated, and the number of initial sub-pixel points corresponding to each gradient direction is counted; the initial sub-pixel point corresponding to the gradient direction with the largest number of initial sub-pixel points is determined as the target sub-pixel point.

[0088] In this embodiment, after determining the sub-pixel edge points corresponding to the target edge, it is also necessary to screen the sub-pixel edge points that meet the first preset condition according to the random consistency sampling method. The principle of the random consistency sampling method is to randomly select two sub-pixel edge points from all sub-pixel edge points to fit a straight line, and calculate the distance from other sub-pixel edge points to the straight line. Sub-pixel edge points whose distance from the straight line is less than a preset value are formed into an initial point set. The above steps are repeated until all sub-pixel points have been used to fit a straight line. The sub-pixel edge points in the initial point set with the largest number of sub-pixel edge points are determined as the initial sub-pixel points.

[0089] In this embodiment, the gradient direction angle of the initial sub-pixel can be calculated according to the following formula (i):

[0090]

[0091] Among them, G y G is the convolution array corresponding to the initial sub-pixel points in the vertical direction. x The initial sub-pixel points are convolutional arrays corresponding to the horizontal coordinate direction; if the neighborhood property of the initial sub-pixel points is 8-neighborhood, then the gradient direction is divided into 8 directions. Then, the number of initial sub-pixel points corresponding to the eight gradient directions can be counted, and the initial sub-pixel point corresponding to the gradient direction with the largest number of initial sub-pixel points is determined as the target sub-pixel point. Accordingly, in step S105, linear fitting is performed on the sub-pixel edge points, including linear fitting on the target sub-pixel points.

[0092] In the eighth and ninth embodiments of this disclosure, the sub-pixel edge points corresponding to the target edge are first calculated, and then the sub-pixel edge points are filtered according to the random consistency sampling method and gradient direction to obtain the target sub-pixel edge points. This can remove interference points and further improve the accuracy of the line detection results.

[0093] Figure 9 A schematic flowchart of a line detection method according to the tenth embodiment of this disclosure is shown, as follows: Figure 9 As shown, step S105 mainly includes:

[0094] According to the weighted least squares method, a straight line is fitted to the sub-pixel edge points to obtain a second fitting result; it is then determined whether the total error corresponding to the second fitting result satisfies the second preset condition to obtain a second judgment result; if the second judgment result is yes, the second fitting result is determined as the straight line detection result; if the second judgment result is no, the weights corresponding to the sub-pixel edge points are updated according to the total error, and a straight line is fitted to the sub-pixel edge points according to the updated weights until the second judgment result is yes.

[0095] In this embodiment, after the fitting begins, sub-pixel edge points are input, and a weighted least squares method is used to fit the sub-pixel edge points with a straight line to obtain a second fitting result. Then, it is determined whether the total error corresponding to the second fitting result satisfies a second preset condition to obtain a second judgment result. If the second judgment result is yes, the second fitting result is determined as a straight line detection result; if the second judgment result is no, the weights corresponding to the sub-pixel edge points are updated according to the total error, and a straight line is fitted to the sub-pixel edge points according to the updated weights until the second judgment result is yes.

[0096] In one possible implementation, a straight line is fitted to the sub-pixel edge points according to the following formula (ii):

[0097]

[0098] Where A is an n×3 matrix of subpixel edge points, C is an n×3 matrix with a value of 0, w is the weight, and B is a 3×1 matrix of parameters a, b, and c to be determined.

[0099] In one possible implementation, when performing straight-line fitting on sub-pixel edge points, each sub-pixel edge point has a corresponding weight in each round of fitting, and the weight w can be calculated according to the following formula (iii):

[0100]

[0101] Where err is the total error, which represents the total distance from all sub-pixel edge points in the current round to the second fitting result, and σ is the error parameter, which represents the allowable pixel error value from the external set point to the target line. If the second judgment result is negative, the weights corresponding to the sub-pixel edge points are updated according to formula (III) and the formula (III) for the total error of the current round, and the sub-pixel edge points are fitted with a straight line according to the updated weights until the second judgment result is positive.

[0102] In one possible implementation, determining whether the total error corresponding to the second fitting result satisfies a second preset condition to obtain a second determination result includes: if the second fitting result is the result of the first iteration, then determining whether the total error corresponding to the second fitting result is less than a sixth preset threshold to obtain a second determination result; if the second fitting result is not the result of the first iteration, then determining whether the total error corresponding to the second fitting result is less than a seventh preset threshold to obtain a second determination result. The sixth and seventh preset thresholds can be set according to actual conditions. Preferably, the sixth preset threshold can be 1. -7 The seventh preset threshold can be 1. -5 .

[0103] In the tenth embodiment of this disclosure, the sub-pixel edge points are iteratively fitted according to the weighted least squares method and the sum of errors to obtain the line detection result. Thus, a line detection result with smaller error and more accurate result can be obtained.

[0104] Figure 10 A schematic diagram of a straight line detection device according to the eleventh embodiment of this disclosure is shown, as follows: Figure 10 As shown, the device mainly includes:

[0105] The determination module 10 is used to determine the angle information corresponding to the detection path of the detection area based on the target position information of the detection area in the image to be detected. The target position information includes the target starting point of the detection area. The first calculation module 11 is used to calculate the first edge point of the target edge in the detection area based on the angle information and the target starting point. The scanning module 12 is used to scan the detection area based on the scanning direction of the detection area and the first edge point to obtain the second edge point of the target edge. The second calculation module 13 is used to calculate the sub-pixel edge point corresponding to the target edge based on the re-judgment direction and the second edge point. The linear fitting module 14 is used to perform linear fitting on the sub-pixel edge points to obtain the line detection result corresponding to the target edge.

[0106] In one embodiment, the device further includes: an acquisition module for acquiring a first scanning width of an original detection region in an original image; a second determination module for determining a region to be detected based on the first scanning width and the original detection region; a cropping module for cropping the original image based on the minimum bounding rectangle of the region to be detected to obtain a region to be detected; and a conversion module for converting the initial position information of the region to be detected into target position information based on the coordinate transformation relationship between the region to be detected and the original image.

[0107] In one possible implementation, the second determining module includes: an adjustment submodule, used to adjust the original detection area to obtain a detection area if the first scan width is greater than a first preset threshold; and a determining submodule, used to determine the original detection area as the detection area if the first scan width is not greater than the first preset threshold.

[0108] In one embodiment, the adjustment submodule includes: a scanning unit for scanning the original detection area to obtain a third edge point of the target edge, wherein the third edge point is a pixel whose difference between the average gray values ​​of its adjacent first pixel set and second pixel set along the scanning direction satisfies a second preset threshold; a fitting unit for linearly fitting the third edge point to obtain an initial edge line; a first calculation unit for calculating the intersection point of the initial edge line and the boundary of the original detection area to obtain the target start point and target end point of the area to be detected; and a determination unit for determining the area to be detected based on the first preset threshold, the target start point, and the target end point.

[0109] In one embodiment, the clipping module is further configured to: obtain the coordinates of pixels within the detection area based on the initial position information of the detection area, thereby obtaining a coordinate set; compare the abscissas in the coordinate set to obtain the maximum and minimum abscissas in the coordinate set, and compare the ordinates in the coordinate set to obtain the maximum and minimum ordinates in the coordinate set; and determine the minimum bounding rectangle of the detection area based on the maximum abscissa, minimum abscissa, maximum ordinate, and minimum ordinate.

[0110] In one embodiment, the device further includes a binarization module, used to perform binarization processing on the image to be detected according to a binarization threshold to obtain a binarized image to be detected.

[0111] In one embodiment, the target location information includes the target termination point of the area to be detected. The determination module 10 is also used to calculate the angle between the target start point and the target termination point, and to determine the angle as the angle information corresponding to the detection path. The detection path is a straight path from the target start point to the target termination point.

[0112] In one embodiment, the first calculation module 11 mainly includes: a first calculation submodule, used to calculate the first horizontal offset and the first vertical offset of the first pixel point on the detection path relative to the target starting point according to the detection step size and angle information; and a second calculation submodule, used to calculate the first edge point of the target edge in the area to be detected according to the target starting point, the first horizontal offset and the first vertical offset.

[0113] In one embodiment, the scanning module 12 mainly includes: a third calculation submodule, used to calculate a second pixel on the scanning path along the scanning direction based on the scanning step size, angle information and the first edge point, wherein the scanning path is a path along the scanning direction and passing through the first edge point; an acquisition submodule, used to acquire the grayscale gradient of the second pixel; and a second determination submodule, used to determine the second edge point of the target edge based on the grayscale gradient.

[0114] In one embodiment, the third calculation submodule is further configured to: calculate the straight-line distance between the second pixel and the first edge point along the scanning direction based on the second scanning width and the scanning step size; calculate the second horizontal offset and the second vertical offset of the second pixel relative to the first edge point based on the straight-line distance and angle information; and calculate the second pixel of the scanning path based on the first edge point, the second horizontal offset, and the second vertical offset.

[0115] In one embodiment, the acquisition submodule is further configured to: determine the grayscale gradient of the second pixel based on the first derivative of the second pixel along the scanning direction; or, acquire the grayscale gradient of the second pixel based on the Sobel operator.

[0116] In one embodiment, the second determining submodule includes: a second determining unit, configured to determine a second pixel point with a grayscale gradient greater than a third preset threshold as an initial second edge point of the target edge; an acquisition unit, configured to acquire a set of third pixels and a set of fourth pixels adjacent to the initial second edge point along the scanning direction; a second calculation unit, configured to calculate a first grayscale average value of the third pixel set and a second grayscale average value of the fourth pixel set; a third calculation unit, configured to calculate a second difference and ratio between the first grayscale average value and the second grayscale average value; and a third determining unit, configured to determine the second edge point of the target edge based on the initial second edge point, the second difference, and the ratio.

[0117] In one embodiment, the third determining unit is further configured to: determine whether the second difference is greater than a fourth preset threshold and whether the ratio is greater than a fifth preset threshold to obtain a first determination result; if the first determination result is yes, then the initial second edge point is determined as the second edge point; if the first determination result is no, then starting from the initial second edge point, the first determination result corresponding to other second pixel points on the scanning path is determined along the scanning direction, and the second pixel point corresponding to the first determination result is determined as the second edge point.

[0118] In one embodiment, the second calculation module 13 mainly includes: a third determination submodule, used to determine the re-judgment direction of the second edge point based on angle information; a second acquisition submodule, used to acquire two adjacent pixel points of the second edge point along the re-judgment direction; a parabolic fitting submodule, used to perform parabolic fitting on the gray values ​​of the second edge point and the two adjacent pixel points to obtain a first fitting result; and a fourth determination submodule, used to determine the sub-pixel edge point corresponding to the target edge based on the extreme point of the first fitting result.

[0119] In one embodiment, the device further includes: a filtering module, used to filter sub-pixel edge points that meet the first preset conditions according to a random consistency sampling method to obtain initial sub-pixel points; a third calculation module, used to calculate the gradient direction of the initial sub-pixel edge points and count the number of initial sub-pixel points corresponding to each gradient direction; and a third determination module, used to determine the initial sub-pixel point corresponding to the gradient direction with the largest number of initial sub-pixel points as the target sub-pixel point.

[0120] In one embodiment, the linear fitting module 14 mainly includes: a straight line fitting submodule, used to perform straight line fitting on the sub-pixel edge points according to the weighted least squares method to obtain a second fitting result; and a judgment submodule, used to judge whether the total error corresponding to the second fitting result satisfies a second preset condition to obtain a second judgment result; if the second judgment result is yes, then the second fitting result is determined as a straight line detection result; if the second judgment result is no, then the weights corresponding to the sub-pixel edge points are updated according to the total error, and straight line fitting is performed on the sub-pixel edge points according to the updated weights until the second judgment result is yes.

[0121] In one possible implementation, the judgment submodule is further configured to: if the second fitting result is the result of the first iteration, then determine whether the total error corresponding to the second fitting result is less than a sixth preset threshold, and obtain a second judgment result; if the second fitting result is not the result of the first iteration, then determine whether the total error corresponding to the second fitting result is less than a seventh preset threshold, and obtain a second judgment result.

[0122] According to embodiments of this disclosure, this disclosure also provides an electronic device and a readable storage medium.

[0123] Figure 11 A schematic block diagram of an example electronic device 1100 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0124] like Figure 11 As shown, device 1100 includes a computing unit 1101, which can perform various appropriate actions and processes according to a computer program stored in read-only memory (ROM) 1102 or a computer program loaded from storage unit 1108 into random access memory (RAM) 1103. The RAM 1103 may also store various programs and data required for the operation of device 1100. The computing unit 1101, ROM 1102, and RAM 1103 are interconnected via bus 1104. Input / output (I / O) interface 1105 is also connected to bus 1104.

[0125] Multiple components in device 1100 are connected to I / O interface 1105, including: input unit 1106, such as keyboard, mouse, etc.; output unit 1107, such as various types of monitors, speakers, etc.; storage unit 1108, such as disk, optical disk, etc.; and communication unit 1109, such as network card, modem, wireless transceiver, etc. Communication unit 1109 allows device 1100 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0126] The computing unit 1101 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 1101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 1101 performs the various methods and processes described above, such as a line detection method. For example, in some embodiments, a line detection method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 1108. In some embodiments, part or all of the computer program may be loaded and / or installed on device 1100 via ROM 1102 and / or communication unit 1109. When the computer program is loaded into RAM 1103 and executed by the computing unit 1101, one or more steps of a line detection method described above may be performed. Alternatively, in other embodiments, the computing unit 1101 may be configured to perform a line detection method by any other suitable means (e.g., by means of firmware).

[0127] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0128] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0129] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0130] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0131] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0132] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0133] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0134] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this disclosure, "a plurality of" means two or more, unless otherwise explicitly specified.

[0135] The above description is merely a specific embodiment of this disclosure, but the scope of protection of this disclosure 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 disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.

Claims

1. A method for detecting straight lines, characterized in that, The method includes: Based on the target position information of the region to be detected in the image to be detected, the angle information corresponding to the detection path of the region to be detected is determined, wherein the target position information includes the target starting point of the region to be detected; Based on the angle information and the target starting point, calculate the first edge point of the target edge in the region to be detected; Based on the scanning direction of the area to be detected and the first edge point, the area to be detected is scanned to obtain the second edge point of the target edge; Based on the re-judgment direction and the second edge point, the sub-pixel edge point corresponding to the target edge is calculated; the re-judgment direction is the neighborhood direction corresponding to the second edge point; Linear fitting is performed on the sub-pixel edge points to obtain the line detection result corresponding to the target edge; The step of scanning the region to be detected based on the scanning direction of the region to be detected and the first edge point to obtain the second edge point of the target edge includes: Based on the scanning step size, the angle information, and the first edge point, the second pixel point on the scanning path is calculated along the scanning direction, and the scanning path is a path along the scanning direction that passes through the first edge point; Obtain the grayscale gradient of the second pixel, and determine the second edge point of the target edge based on the grayscale gradient; The step of calculating the second pixel point on the scanning path along the scanning direction based on the scanning step size, the angle information, and the first edge point includes: Based on the second scan width and the scan step size, calculate the straight-line distance between the second pixel and the first edge point along the scan direction; Based on the straight-line distance and the angle information, calculate the second horizontal offset and the second vertical offset of the second pixel relative to the first edge point; The second pixel point of the scan path is calculated based on the first edge point, the second horizontal offset, and the second vertical offset; The step of determining the second edge point of the target edge based on the grayscale gradient includes: The second pixel point whose grayscale gradient is greater than the third preset threshold is determined as the initial second edge point of the target edge; Obtain the third pixel set and the fourth pixel set adjacent to the initial second edge point along the scanning direction, and calculate the first grayscale average value of the third pixel set and the second grayscale average value of the fourth pixel set; Calculate the second difference and ratio between the first average grayscale value and the second average grayscale value; The second edge point of the target edge is determined based on the initial second edge point, the second difference, and the ratio. The step of determining the second edge point of the target edge based on the initial second edge point, the second difference, and the ratio includes: Determine whether the second difference is greater than a fourth preset threshold and whether the ratio is greater than a fifth preset threshold to obtain a first determination result; If the first determination result is yes, then the initial second edge point is determined as the second edge point; If the first judgment result is negative, then starting from the initial second edge point, determine the first judgment result corresponding to other second pixel points on the scanning path along the scanning direction, and determine the second pixel point corresponding to the first judgment result as the second edge point; The step of calculating the sub-pixel edge point corresponding to the target edge based on the re-judgment direction and the second edge point includes: Based on the angle information, determine the re-judgment direction of the second edge point, and obtain two adjacent pixel points of the second edge point along the re-judgment direction; Parabolic fitting is performed on the gray values ​​of the second edge point and the two adjacent pixels to obtain the first fitting result; Based on the extreme points of the first fitting result, the sub-pixel edge points corresponding to the target edge are determined.

2. The method according to claim 1, characterized in that, The target location information of the region to be detected in the image to be detected is obtained in the following manner: Obtain the first scan width of the original detection region in the original image; The region to be detected is determined based on the first scan width and the original detection area; The original image is cropped based on the minimum bounding rectangle of the region to be detected to obtain the image to be detected. Based on the coordinate transformation relationship between the image to be detected and the original image, the initial position information of the region to be detected is converted into the target position information.

3. The method according to claim 2, characterized in that, The step of determining the region to be detected based on the first scan width and the original detection region includes: If the first scan width is greater than the first preset threshold, the original detection area is adjusted to obtain the area to be detected; If the first scan width is not greater than the first preset threshold, then the original detection area is determined as the area to be detected.

4. The method according to claim 3, characterized in that, The step of adjusting the original detection area to obtain the area to be detected includes: The original detection area is scanned to obtain the third edge point of the target edge. The third edge point is a pixel whose gray value difference with the average gray value of the first pixel set and the second pixel set adjacent to it along the scanning direction satisfies the second preset threshold. A linear fit is performed on the third edge point to obtain the initial edge line; Calculate the intersection point of the initial edge line and the boundary of the original detection area to obtain the target start point and target end point of the area to be detected; The region to be detected is determined based on the first preset threshold, the target starting point, and the target ending point.

5. The method according to claim 2, characterized in that, The minimum bounding rectangle of the region to be detected is obtained as follows: Based on the initial position information of the region to be detected, the coordinates of the pixels within the region to be detected are obtained to obtain a coordinate set; By comparing the x-coordinates in the coordinate set, the maximum and minimum x-coordinates in the coordinate set are obtained; and by comparing the y-coordinates in the coordinate set, the maximum and minimum y-coordinates in the coordinate set are obtained. The minimum bounding rectangle of the region to be detected is determined based on the maximum x-coordinate, the minimum x-coordinate, the maximum y-coordinate, and the minimum y-coordinate.

6. The method according to claim 2, characterized in that, After cropping the original image according to the minimum bounding rectangle of the region to be detected to obtain the image to be detected, the process further includes: The image to be detected is binarized according to the binarization threshold to obtain the binarized image to be detected.

7. The method according to claim 1, characterized in that, The target location information includes the target termination point of the region to be detected. The step of determining the angle information corresponding to the detection path of the region to be detected based on the target location information of the region to be detected in the image to be detected includes: Calculate the angle of the line connecting the target starting point and the target ending point, and determine the angle of the line connecting the target as the angle information corresponding to the detection path, wherein the detection path is a straight line path from the target starting point to the target ending point.

8. The method according to claim 1, characterized in that, The step of calculating the first edge point of the target edge in the region to be detected based on the angle information and the target starting point includes: Based on the detection step size and the angle information, calculate the first horizontal offset and the first vertical offset of the first pixel on the detection path relative to the target starting point; Based on the target starting point, the first horizontal offset, and the first vertical offset, calculate the first edge point of the target edge in the region to be detected.

9. The method according to claim 1, characterized in that, The step of obtaining the grayscale gradient of the second pixel includes: The grayscale gradient of the second pixel is determined based on the first derivative of the second pixel along the scanning direction; or, The grayscale gradient of the second pixel is obtained using the Sobel operator.

10. The method according to claim 1, characterized in that, After determining the sub-pixel edge point corresponding to the target edge based on the extreme point of the first fitting result, the method further includes: Based on the random consistency sampling method, sub-pixel edge points that meet the first preset condition are selected to obtain initial sub-pixel points; Calculate the gradient direction of the initial sub-pixel edge points and count the number of initial sub-pixel points corresponding to each gradient direction; The initial sub-pixel corresponding to the gradient direction with the largest number of initial sub-pixels is determined as the target sub-pixel.

11. The method according to claim 1, characterized in that, The step of performing linear fitting on the sub-pixel edge points to obtain the line detection result corresponding to the target edge includes: According to the weighted least squares method, a straight line is fitted to the sub-pixel edge points to obtain a second fitting result; Determine whether the total error corresponding to the second fitting result satisfies the second preset condition to obtain the second judgment result; If the second judgment result is yes, then the second fitting result is determined as the line detection result; If the second judgment result is negative, then the weights corresponding to the sub-pixel edge points are updated according to the total error, and the sub-pixel edge points are fitted with straight lines according to the updated weights, until the second judgment result is positive.

12. The method according to claim 11, characterized in that, The step of determining whether the sum of errors corresponding to the second fitting result satisfies the second preset condition to obtain the second determination result includes: If the second fitting result is the result of the first iteration, then it is determined whether the total error corresponding to the second fitting result is less than the sixth preset threshold, and the second determination result is obtained. If the second fitting result is not the result of the first iteration, then it is determined whether the total error corresponding to the second fitting result is less than the seventh preset threshold, and the second judgment result is obtained.

13. A straight line detection device, characterized in that, The device includes: The determination module is used to determine the angle information corresponding to the detection path of the region to be detected based on the target position information of the region to be detected in the image to be detected, wherein the target position information includes the target starting point of the region to be detected. The first calculation module is used to calculate the first edge point of the target edge in the region to be detected based on the angle information and the target starting point; The scanning module is used to scan the area to be detected according to the scanning direction of the area to be detected and the first edge point to obtain the second edge point of the target edge; The second calculation module is used to calculate the sub-pixel edge point corresponding to the target edge based on the re-judgment direction and the second edge point; the re-judgment direction is the neighborhood direction corresponding to the second edge point; The linear fitting module is used to perform linear fitting on the sub-pixel edge points to obtain the line detection result corresponding to the target edge; The step of scanning the region to be detected based on the scanning direction of the region to be detected and the first edge point to obtain the second edge point of the target edge includes: Based on the scanning step size, the angle information, and the first edge point, the second pixel point on the scanning path is calculated along the scanning direction, and the scanning path is a path along the scanning direction that passes through the first edge point; Obtain the grayscale gradient of the second pixel, and determine the second edge point of the target edge based on the grayscale gradient; The step of calculating the second pixel point on the scanning path along the scanning direction based on the scanning step size, the angle information, and the first edge point includes: Based on the second scan width and the scan step size, calculate the straight-line distance between the second pixel and the first edge point along the scan direction; Based on the straight-line distance and the angle information, calculate the second horizontal offset and the second vertical offset of the second pixel relative to the first edge point; The second pixel point of the scan path is calculated based on the first edge point, the second horizontal offset, and the second vertical offset; The step of determining the second edge point of the target edge based on the grayscale gradient includes: The second pixel point whose grayscale gradient is greater than the third preset threshold is determined as the initial second edge point of the target edge; Obtain the third pixel set and the fourth pixel set adjacent to the initial second edge point along the scanning direction, and calculate the first grayscale average value of the third pixel set and the second grayscale average value of the fourth pixel set; Calculate the second difference and ratio between the first average grayscale value and the second average grayscale value; The second edge point of the target edge is determined based on the initial second edge point, the second difference, and the ratio. The step of determining the second edge point of the target edge based on the initial second edge point, the second difference, and the ratio includes: Determine whether the second difference is greater than a fourth preset threshold and whether the ratio is greater than a fifth preset threshold to obtain a first determination result; If the first determination result is yes, then the initial second edge point is determined as the second edge point; If the first judgment result is negative, then starting from the initial second edge point, determine the first judgment result corresponding to other second pixel points on the scanning path along the scanning direction, and determine the second pixel point corresponding to the first judgment result as the second edge point; The step of calculating the sub-pixel edge point corresponding to the target edge based on the re-judgment direction and the second edge point includes: Based on the angle information, determine the re-judgment direction of the second edge point, and obtain two adjacent pixel points of the second edge point along the re-judgment direction; Parabolic fitting is performed on the gray values ​​of the second edge point and the two adjacent pixels to obtain the first fitting result; Based on the extreme points of the first fitting result, the sub-pixel edge points corresponding to the target edge are determined.

14. An electronic device, characterized in that, include: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-12.

15. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-12.

Citation Information

Patent Citations

  • Anti-jamming sub pixel straight line fitting method

    CN108921865A

  • Curve consistency detection method and storage medium

    CN110660096A

  • Detection method, detection system, equipment and storage medium

    CN114022503A