A method for detecting straight line edges, a one-dimensional measurement method, an electronic device, and a medium.

By rotating the ROI and combining it with subpixel-level edge position calculation, the problem of high-precision edge detection when the edge of the detected object is not perpendicular to the ROI is solved, realizing automated and fast edge detection and one-dimensional measurement.

CN118710674BActive Publication Date: 2026-07-31HEFEI I TEK OPTOELECTRONICS CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HEFEI I TEK OPTOELECTRONICS CO LTD
Filing Date
2024-07-23
Publication Date
2026-07-31

AI Technical Summary

Technical Problem

Existing technologies, when the edge of the detected object is not perpendicular to the ROI, rely on manual adjustment of edge detection parameters, which is inaccurate and inefficient. Template matching methods are computationally complex and time-consuming, making it difficult to achieve high-precision straight edge detection.

Method used

By rotating the ROI to gradually approach the vertical direction of the line to be measured, and combining this with sub-pixel level edge position calculation, the ROI posture is automatically adjusted to achieve high-precision edge detection.

Benefits of technology

It achieves high-precision edge detection even when the straight line of the edge to be detected is not perpendicular to the edge search direction, reducing human intervention and improving the robustness and computational efficiency of edge detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118710674B_ABST
    Figure CN118710674B_ABST
Patent Text Reader

Abstract

This invention proposes a method for detecting straight line edges, a one-dimensional measurement method, an electronic device, and a medium. The method includes: acquiring a grayscale image containing the edge of the line to be detected; defining a first Region of Interest (ROI) and several first sub-regions; calculating the first coordinate point of the edge position in each first sub-region, and calculating the first angle between a first fitted line and the first ROI; rotating each first sub-region relative to the grayscale image based on the first angle to obtain a rotated second ROI and several second sub-regions; calculating the second coordinate point of each second sub-region to determine the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be detected; if perpendicular, outputting the second coordinate point as the edge point to be detected; otherwise, using the rotated second ROI as the first ROI, repeating the previous step until perpendicular. This application, based on a single edge detection algorithm, achieves automated adjustment of the edge-finding direction to adapt to edge detection at different angles, improving the robustness of the edge detection results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a method for detecting straight line edges, a one-dimensional measurement method, an electronic device, and a medium. Background Technology

[0002] In industrial production, straightness, parallelism, and line spacing are common product quality control parameters. Using online measurement equipment to monitor the straightness, parallelism, or line spacing of manufactured products is a common and important product quality control method. The prerequisite for calculating straightness, parallelism, and line spacing is the accurate extraction of edge positions from the measured image; the reliability of the edge-finding algorithm is a prerequisite for achieving accurate and reliable calculations of straightness, parallelism, and line spacing.

[0003] In existing technologies, there are many edge detection algorithms, such as the Canny and Sobel algorithms, which acquire all continuous, complete, and arbitrarily shaped contours on an image, focusing on edge finding. Edge detection based on one-dimensional (1D) measurement, on the other hand, targets straight contours, acquiring discrete edges, emphasizing high-precision edge localization. This is suitable for traditional computer vision algorithms that measure linear geometric parameters such as the position, length, and spacing of object edges. The advantages of this measurement method are its ease of use, short execution time, and high accuracy.

[0004] With the development of artificial intelligence and the widespread use of deep learning and neural networks, edge detection and localization can be achieved through intelligent training, as exemplified by Chinese patent CN115661872A. However, methods such as network models require a large number of samples for training and lack interpretability. In contrast, traditional vision methods are more reliable, as each operation is interpretable and reproducible.

[0005] The core of 1D measurement technology is to identify and locate edges in an image through image processing to obtain the key geometric features of the target object. However, when the edge of the object being detected is not perpendicular to the edge-finding direction of the ROI (Region of Interest), current methods mainly involve manually adjusting edge detection parameters or rotating the image using template matching to make the position of the detected edge in the image adapt to the pre-set edge detection parameters. However, manual methods are inaccurate, have a high degree of randomness, and the adjusted parameters may not necessarily achieve the best edge detection results; moreover, they are slow and inefficient. The latter method uses template matching, as seen in Chinese patents CN116777889 A and CN111079772B. However, template matching requires complex calculations, has complex algorithms, a large computational load, is time-consuming, and is prone to matching failures.

[0006] Chinese patent CN 112215240 B discloses an optimization method to improve the accuracy of 2D complex edge detection. This method selects a rectangular Region of Interest (ROI) in the image to be processed, rotates it horizontally, establishes a coordinate system with the center point of the ROI as the origin, calculates the sum of the projected grayscale values ​​of each row of pixels within the ROI, and selects the row with the smallest sum of projected grayscale values ​​as the black peak row. Based on the distance differences Dx and Dy between the center coordinates of the black peak row and the center of the original ROI before rotation in the horizontal and vertical directions, the center coordinates of the black peak row are mapped back to the original ROI. Combined with edge attributes, multiple edges with the same attributes within the ROI are extracted. The technical problem solved by this patent differs from the solution presented here.

[0007] Chinese patent CN113077467B discloses a method, apparatus, and storage medium for detecting edge defects in a target object. This solution, when configuring the baseline for each curve segment, no longer considers the shape of the region of interest in the image to be detected. Instead, it sets the baseline as a parabola based on the characteristics of the curve segments on a free curve, enabling rapid and accurate fitting of the baseline for each curve segment and improving the subsequent edge point selection capability. The technical problem solved by this patent and the technical means employed are different from this solution. Summary of the Invention

[0008] This invention proposes a method for detecting straight line edges, a one-dimensional measurement method, an electronic device, and a medium, which can solve at least one of the above-mentioned technical problems.

[0009] To achieve the above objectives, the present invention proposes the following technical solution: A method for detecting straight line edges includes: acquiring a grayscale image containing the edge of a straight line to be detected; setting an initial region of interest (ROI), wherein any initial ROI contains one edge of a straight line to be detected; and further comprising: Divide the initial ROI to obtain several initial sub-regions; The initial ROI is taken as the first ROI, and the initial sub-region is taken as the first sub-region; Calculate the first coordinate point of the edge position in each first sub-region, obtain the first fitted line, and calculate the first angle between the first fitted line and the first ROI; based on the first angle, rotate each first sub-region relative to the grayscale image to obtain the rotated second ROI and several second sub-regions; Calculate the second coordinate point of the edge position in each second sub-region to determine the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured; if they are perpendicular, output the second coordinate point as the edge point to be measured; otherwise, take the rotated second ROI as the first ROI and repeat the previous step until they are perpendicular.

[0010] Further, determining the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured includes: obtaining a second fitted line based on the second coordinate point, calculating a second angle between the second fitted line and the perpendicular direction of the edge-finding direction of the second ROI, and if the second angle meets the angle threshold, then they are perpendicular; otherwise, they are not perpendicular.

[0011] Furthermore, determining the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured includes: calculating the distance between the coordinate points before and after rotation corresponding to the same edge position in the second ROI; if the distance threshold is met, then they are perpendicular; otherwise, they are not perpendicular.

[0012] Further, the calculation of the first coordinate point of the edge position in each first sub-region includes: obtaining a one-dimensional array of the first sub-region based on the pixel points in any first sub-region; filtering the one-dimensional array to obtain edge position data; calculating the gradient of the edge position data, setting a gradient threshold, and filtering out the sub-pixel extreme point coordinates as the first coordinate point.

[0013] Furthermore, the step of filtering out sub-pixel extreme point coordinates includes: obtaining extreme points based on the gradient of edge position data; interpolating the extreme points to obtain sub-pixel candidate edge points; setting a gradient threshold, and filtering out the edge coordinates corresponding to the precise sub-pixel position from the sub-pixel candidate edge points where the absolute value of the first-order gradient is greater than the gradient threshold, as the first coordinate point.

[0014] Based on the same inventive concept, this invention also proposes a one-dimensional measurement method, comprising: Acquire the grayscale image of the object to be tested; Using the straight edge detection method described above, at least two edge points to be detected are obtained; Calculate the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

[0015] Furthermore, the measurement information includes the feature location information of the object to be measured obtained directly and the measurement information obtained through secondary calculation.

[0016] The present invention also proposes a one-dimensional measurement system, comprising: The acquisition module acquires the grayscale image of the object under test. The ROI module is used to set the initial ROI, which contains a line edge to be measured; and to segment the initial ROI to obtain several initial sub-regions. The edge calculation module takes the initial ROI as the first ROI and the initial sub-region as the first sub-region; calculates the first coordinate point of the edge position in each first sub-region, obtains the first fitted line, and calculates the first angle between the first fitted line and the first ROI; based on the first angle, each first sub-region is rotated relative to the grayscale image to obtain the rotated second ROI and several second sub-regions. The edge determination module calculates the second coordinate point of the edge position in each second sub-region to determine the positional relationship between the edge finding direction of the second ROI and the edge of the line to be measured. If they are perpendicular, the second coordinate point is output as the edge point to be measured. Otherwise, the rotated second ROI is used as the first ROI. The edge calculation module repeats the process until they are perpendicular. The distance calculation module calculates the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

[0017] The present invention also proposes an electronic device, including a processor and a memory, wherein the memory is used to store a computer program, the computer program including program instructions, and the processor is configured to call the program instructions to execute a straight edge detection method or a one-dimensional measurement method as described above.

[0018] On the other hand, the present invention also proposes a computer-readable storage medium including a computer program, which, when executed by a processor, implements a straight edge detection method or a one-dimensional measurement method as described above.

[0019] The beneficial effects of this invention are as follows: This application provides a method for detecting straight line edges. Based on the traditional single edge detection algorithm, by continuously adjusting the pose of the ROI, the edge-finding direction (the direction for finding the edge position) of the straight line edge to be tested gradually approaches the perpendicular direction of the straight line edge to be tested. Thus, even when the straight line edge to be tested is not perpendicular to the edge-finding direction, it still maintains a high-precision edge detection effect.

[0020] This application, building upon the high precision of single-edge detection algorithms, implements automated adjustment of the edge-finding direction to adapt to edge detection at different angles, outputting sub-pixel-level edge position coordinates and improving the robustness of edge detection results. Compared to methods that manually adjust ROI setting parameters, this reduces human intervention, thus providing stable and reliable edge detection results.

[0021] Compared to the complex calculation process of template matching, the edge detection method proposed in this application can quickly adjust and locate the position of the target edge within the set ROI, with less computation, less resource consumption, and easier hardware implementation.

[0022] Based on the line edge detection method, this application also proposes a measurement method suitable for one-dimensional measurement, providing a new solution for the automated and efficient application of one-dimensional measurement technology. Attached Figure Description

[0023] Figure 1 This is a flowchart illustrating the straight line edge detection method of the present invention; Figure 2 This is a schematic diagram of the initial ROI in this invention; Figure 3 This is a schematic diagram of segmenting the initial ROI in this invention; Figure 4 This is a schematic diagram of the vertical projection of the first sub-region in this invention; Figure 5 This is a schematic diagram of the non-vertical projection of the first sub-region in this invention; Figure 6 This is a schematic diagram of the first coordinate point in this invention; Figure 7 This is a schematic diagram of the first fitting straightness in this invention; Figure 8 This is a schematic diagram of the second ROI in this invention; Figure 9 This is a schematic diagram of the second coordinate point in this invention; Figure 10 This is a schematic diagram of the edge detection results in this invention; Figure 11 a is a schematic diagram of straight line edge detection using the baseline method; Figure 11 b is a schematic diagram of straight edge detection using the single edge detection method; Figure 11 c is a schematic diagram of the straight line edge detection in this scheme; Figure 12 This is a flowchart illustrating the one-dimensional measurement method in this invention. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are some embodiments of the present invention, but not all embodiments.

[0025] This embodiment uses a rotated Region of Interest (ROI) as an example to illustrate the implementation process of the straight-line edge detection method. Considering the limited resources used by the ROI, this embodiment achieves accurate detection of the edge to be detected in a grayscale image simply by rotating the ROI. If the size of the grayscale image is limited, rotating the grayscale image can also achieve the straight-line detection method described in this invention. Specifically, if the initial ROI is used as a reference, i.e., the vertical and horizontal directions of the initial ROI are used as the vertical and horizontal directions, rotating the grayscale image can also achieve the straight-line edge detection method described in this invention, thereby obtaining sub-pixel-level accurate edge localization results. Example 1

[0026] like Figure 1 As shown, this invention proposes a method for detecting straight line edges, comprising: Acquire a grayscale image containing the edge of the line to be tested. Set an initial Region of Interest (ROI), each containing a line edge to be tested. This line edge is neither parallel nor perpendicular to any side of the initial ROI; that is, the angle between the line edge and any side of the initial ROI is not 0 or 90 degrees (or an integer multiple of 90 degrees). Using the grayscale image containing the line edge as a reference, rotate the initial ROI by this angle, and the rotated line edge will be either parallel or perpendicular to any side of the initial ROI.

[0027] like Figure 2 As shown, in this embodiment, the grayscale image is a right-angled triangle, with its hypotenuse being the edge to be detected. This edge forms an angle with the currently selected bounding box (initial ROI) (the angle is not 0 and is not an integer multiple of 90 degrees), and after rotating the edge by this angle, it can be parallel to the long or wide side of the currently selected bounding box. In this embodiment, the horizontal and vertical directions where the grayscale image is located are used as the horizontal and vertical directions, respectively.

[0028] like Figure 3 As shown, the initial ROI is segmented to obtain several initial sub-regions; each initial ROI contains a line edge to be measured.

[0029] The initial ROI is taken as the first ROI, and the initial sub-region is taken as the first sub-region.

[0030] Calculate the first coordinate point of the edge position in each first sub-region, obtain the first fitted line, and calculate the first angle between the first fitted line and the first ROI; based on the first angle, rotate each first sub-region relative to the grayscale image to obtain the rotated second ROI and several second sub-regions.

[0031] like Figure 4-6 As shown, calculate the first coordinate point of the edge position in each first sub-region.

[0032] Based on any pixel within the first sub-region, obtain a one-dimensional array of the first sub-region; filter the one-dimensional array to obtain edge position data; calculate the gradient of the edge position data, set a gradient threshold, and filter out the sub-pixel extreme point coordinates as the first coordinate point.

[0033] In this embodiment, a single edge detection algorithm is used to calculate the first coordinate point.

[0034] Based on the pixels within any first sub-region, obtain a one-dimensional array of the first sub-region. Specifically, this includes: based on the location and direction of the initial ROI (first ROI), setting the edge-finding direction, determining the projection direction, constructing several equidistant projection lines such that the length of any equidistant projection line is equal to the width or long side of the first sub-region; along each equidistant projection line, calculating the average gray value of the grayscale image pixels, and obtaining a one-dimensional array.

[0035] like Figure 4 As shown, in this embodiment, the direction of edge finding of the first ROI is set to the wide side parallel to the first ROI (i.e., the direction of edge finding parallel to the long side of the first sub-region), and edge positions and data are found one by one; the projection direction is perpendicular to the direction of edge finding, so the direction of edge finding parallel to the long side of the first ROI is the projection direction, that is, the direction of edge finding parallel to the wide side of the first sub-region is the projection direction.

[0036] In this embodiment, several equidistant projection lines are constructed with the length of any equidistant projection line equal to the width of the first sub-region, thereby obtaining a one-dimensional array of the first sub-region.

[0037] like Figure 5 As shown, if the first ROI is not horizontal or vertical, then the equidistant projection lines constructed in any of the first sub-regions are also not vertical or horizontal. Therefore, pixel values ​​along the equidistant projection lines in the first sub-region need to be interpolated to obtain a one-dimensional array.

[0038] A one-dimensional array is filtered to obtain edge location data. This one-dimensional array includes both the edge of interest (the edge to be detected) and other noise. Filtering the one-dimensional array can suppress the noise and obtain the edge location data. Preferably, the filtering process can be Gaussian filtering, but other filtering methods are also possible.

[0039] Calculate the gradient of the edge location data, set the gradient threshold, and filter out the sub-pixel extreme point coordinates as the first coordinate point.

[0040] Edge locations are defined as areas of varying brightness. Preferably, a simple central difference method is used to calculate the gradient of the edge location data. Specifically, this includes: for the starting point of the one-dimensional array, inserting a zero-level grayscale (grayscale value of zero) to its left, the gradient of which is equal to the average difference between the grayscale of its right-hand neighboring pixel and the zero-level grayscale. For the ending point of the one-dimensional array, inserting a zero-level grayscale (grayscale value of zero) to its right, the gradient of which is equal to the average difference between the grayscale of its left-hand neighboring pixel and the zero-level grayscale. For the middle point of the one-dimensional array, the gradient of which is equal to the average difference between the grayscale of its right-hand neighboring pixel and the grayscale of its left-hand neighboring pixel. In this embodiment, the central difference method is only used as an example of a method for calculating the first derivative (first-order gradient), and other calculation methods are not limited.

[0041] Based on the gradient of the edge location data, the extreme points are obtained; the extreme points are interpolated to obtain sub-pixel candidate edge points; a gradient threshold is set; and the coordinates of the sub-pixel extreme points whose absolute value of the first gradient is greater than the gradient threshold are selected from the sub-pixel candidate edge points and used as the first coordinate points.

[0042] Among them, extreme points are generally defined as local maxima and local minima. A local maxima is greater than both its left and right adjacent points, and a local minima is less than both its left and right adjacent points.

[0043] Extreme points are obtained based on the gradient of edge location data. Since the extreme points obtained from the first-order gradient calculation are pixel-level locations, to obtain more accurate edge detection results, the coordinates of the extreme points are further interpolated to obtain sub-pixel-level coordinates. Specifically, this involves fitting a quadratic curve with the first-order gradient magnitude using the coordinates of any extreme point, its left adjacent point, and its right adjacent point, and then interpolating to obtain the coordinates of the extreme points of the quadratic curve. These are then used as candidate edge points for sub-pixel precise locations, i.e., sub-pixel candidate edge points.

[0044] Set a gradient threshold, and select the coordinates of sub-pixel extreme points from the sub-pixel candidate edge points whose absolute value of the first gradient is greater than the gradient threshold, and use them as the first coordinate points.

[0045] like Figure 6 As shown, because the edge to be detected forms a certain angle with the search direction of the first ROI, the calculated first coordinate point in the sub-pixel level calculation results does not fall precisely on the edge to be detected, resulting in a visible error in the edge detection result. To solve the above error problem, this scheme reduces the edge detection error based on the calculation result of the first coordinate point.

[0046] like Figure 7 As shown, based on the calculation results of the first coordinate point, a first fitted line is fitted, and the first angle θ between the first fitted line and the first ROI is calculated.

[0047] In this embodiment, the least squares method is used to fit the linear equation for the first coordinate point: Ax + By + C = 0; where A, B, and C are the equation coefficients. To prevent edge detection errors from introducing more obvious disturbances, other robust linear fitting methods can also be used.

[0048] Let the angle of the first ROI be α, that is, the angle between the longer side of the first ROI and the horizontal line ( Figure 7 The angle between the horizontal dashed line (representing the horizontal direction of the grayscale image) and the first ROI is α. Therefore, the first angle between the first fitted line and the first ROI is... .

[0049] In this embodiment, when the first ROI is set horizontally, α=0; therefore, in this embodiment, the first included angle... .

[0050] As described above, in this embodiment, the angle between the first fitted line and the long side of the first ROI is used as the first angle, which facilitates the calculation of the specific value of the angle. Preferably, the angle between the first fitted line and the wide side of the first ROI can also be used as the first angle; in this case, the first angle, together with the calculation result of the inverse trigonometric function used to calculate the slope of the first fitted line, is 90 degrees.

[0051] like Figure 8 and Figure 9 As shown, based on the first included angle, each first sub-region is rotated relative to the grayscale image to obtain the rotated second ROI and several second sub-regions.

[0052] Calculate the second coordinate point of the edge position in each second sub-region to determine the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured; if they are perpendicular, output the second coordinate point as the edge point to be measured; otherwise, take the rotated second ROI as the first ROI and repeat the previous step until they are perpendicular.

[0053] In this embodiment, the calculation process for the second coordinate point differs from that for the first coordinate point in that the second ROI is neither horizontal nor vertical. Therefore, the equidistant projection lines constructed in any second sub-region are not vertical or horizontal. Consequently, pixel values ​​along the equidistant projection lines in the second sub-region need to be interpolated to obtain a one-dimensional array. Other calculation processes are the same as those for the first coordinate point and will not be elaborated upon here.

[0054] In this embodiment, the wide side parallel to the second ROI (i.e., the direction parallel to the long side of the second sub-region) is set as the edge-finding direction of the second ROI.

[0055] There are two methods to determine the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured. Either one of these methods is sufficient, as follows: Based on the second coordinate point, obtain the second fitted straight line, and calculate the second angle between the second fitted straight line and the perpendicular direction of the edge-finding direction of the second ROI. If the second angle meets the angle threshold, then it is perpendicular; otherwise, it is not perpendicular. The angle threshold is set by the image processing environment and user needs.

[0056] As described above, in this embodiment, the angle between the second fitted line and the perpendicular direction of the edge-finding direction of the second ROI (i.e., the long side of the second ROI) is taken as the second angle, which facilitates the calculation of the specific value of the angle.

[0057] Preferably, the angle between the second fitted line and the wide side of the second ROI can also be used as the second included angle; in this case, the second included angle, together with the calculation result of the inverse trigonometric function for calculating the slope of the second fitted line, is 90 degrees.

[0058] The setting of the second included angle here must be consistent with the setting of the first included angle. The included angle thresholds corresponding to different included angle settings are also different.

[0059] Calculate the distance between the coordinates of the point before rotation and the coordinates of the point after rotation corresponding to the same edge position in the second ROI. If the distance threshold is met, the points are perpendicular; otherwise, they are not perpendicular. The distance threshold can be set by the image processing environment and user requirements.

[0060] In the field of image processing, different distance definitions exist between pixel locations, such as chessboard distance and street distance. In this embodiment, the Euclidean distance between the coordinates of the point before rotation and the coordinates of the point after rotation corresponding to the same edge position is calculated as a judgment example. The formula for calculating the Euclidean distance is as follows: In the formula, the coordinates of the same edge position in the second ROI before rotation are (x1, y1), and the coordinates of the same edge position after rotation are (x2, y2).

[0061] After the above calculation process, the edge-finding direction of the second ROI is finally determined. By searching for edges along the height (width) direction of the second ROI, accurate sub-pixel-level edge detection results can be obtained, such as... Figure 10 As shown.

[0062] like Figure 11 As shown, the results of the line edge detection method in this application are verified as follows: To quantify the measurement error, a grayscale image containing edges with known tilt angles was used to verify the detection progress of the proposed method.

[0063] like Figure 11As shown in Figure a, by manually setting the edge-finding direction of the ROI so that the edge-finding direction of the ROI is completely perpendicular to the edge, and performing a single-edge detection method, the pixel position coordinates of the edge to be detected (279.815, 273.184) are obtained, in pixels, and used as the basis for error calculation. Figure 11 As shown in b, only the single-edge detection method is performed to obtain the pixel coordinates (280, 265) of the edge to be detected, and its error is calculated to be 7.68 pixels; Figure 11 As shown in c, the line edge detection method described above in this scheme is executed to obtain the pixel position coordinates (279.814, 273.184) of the edge to be detected, and its error is calculated to be 0.013 pixels.

[0064] Example 2

[0065] like Figure 12 As shown, this embodiment, based on Embodiment 1, proposes a one-dimensional measurement method, including: Acquire the grayscale image of the object to be tested; Using the straight edge detection method described in Example 1, at least two edge points to be detected are obtained; Calculate the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

[0066] In this embodiment, the straight-line edge detection method described in Embodiment 1 is used to obtain at least two edge points to be detected. Since Embodiment 1 of this application is an improved method of single-edge detection algorithm, only the relevant data of one edge to be detected is calculated in any ROI. Therefore, the at least two edge points to be detected can be two edge points in the same ROI, or they can be one edge point corresponding to each of any at least two ROIs in the same grayscale image.

[0067] In this embodiment, the measurement information includes directly acquired measurement information of the object to be measured and measurement information acquired through secondary calculation. Specifically, it includes: calculating the distance between at least two edge points to be measured, which can directly obtain feature position information such as the length and width of the object to be measured; or, based on the length and width, performing further calculations to obtain measurement information such as the area of ​​the object to be measured.

[0068] Based on the same inventive concept, this invention also proposes a one-dimensional measurement system for performing the above-described method. Specifically, it includes: The acquisition module acquires the grayscale image of the object under test. The ROI module is used to set the initial ROI, which contains a line edge to be measured; and to segment the initial ROI to obtain several initial sub-regions. The edge calculation module takes the initial ROI as the first ROI and the initial sub-region as the first sub-region; calculates the first coordinate point of the edge position in each first sub-region, obtains the first fitted line, and calculates the first angle between the first fitted line and the first ROI; based on the first angle, each first sub-region is rotated relative to the grayscale image to obtain the rotated second ROI and several second sub-regions. The edge determination module calculates the second coordinate point of the edge position in each second sub-region to determine the positional relationship between the edge finding direction of the second ROI and the edge of the line to be measured. If they are perpendicular, the second coordinate point is output as the edge point to be measured. Otherwise, the rotated second ROI is used as the first ROI. The edge calculation module repeats the process until they are perpendicular. The distance calculation module calculates the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

[0069] The present invention also proposes an electronic device, including a processor and a memory, wherein the memory is used to store a computer program, the computer program including program instructions, and the processor is configured to call the program instructions to execute a straight edge detection method or a one-dimensional measurement method as described above.

[0070] The present invention also proposes a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements a straight edge detection method or a one-dimensional measurement method as described above.

[0071] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0072] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method of straight-line edge detection, comprising: Acquire a grayscale image containing the edge of the line to be tested, set an initial ROI, and then... An initial ROI contains the edge of a line to be measured, characterized in that it further includes: Divide the initial ROI to obtain several initial sub-regions; The initial ROI is designated as the first ROI, and the initial sub-region is designated as the first sub-region. The initial ROI and the first sub-region are both graphics with a long side and a wide side, and the wide side of the first ROI is parallel to the direction of the long side of the first sub-region, and the direction of the long side of the first ROI is parallel to the direction of the wide side of the first sub-region. Calculate the first coordinate point of the edge position in each first sub-region, obtain the first fitted line, and calculate the first angle between the first fitted line and the long side or wide side of the first ROI; based on the first angle, rotate each first sub-region relative to the grayscale image to obtain the rotated second ROI and several second sub-regions. Calculate the second coordinate point of the edge position in each second sub-region to determine the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured; if they are perpendicular, output the second coordinate point as the edge point to be measured; otherwise, take the rotated second ROI as the first ROI and repeat the previous step until they are perpendicular; wherein, the edge-finding direction refers to the direction of finding the edge position.

2. The straight edge detection method of claim 1, wherein The determination of the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured includes: obtaining a second fitted line based on the second coordinate point, calculating a second angle between the second fitted line and the perpendicular direction of the edge-finding direction of the second ROI, and if the second angle meets the angle threshold, then it is perpendicular; otherwise, it is not perpendicular.

3. The straight edge detection method of claim 1, wherein, The determination of the positional relationship between the edge-finding direction of the second ROI and the edge of the line to be measured includes: calculating the distance between the coordinate points before and after rotation corresponding to the same edge position in the second ROI; if the distance threshold is met, then they are perpendicular; otherwise, they are not perpendicular.

4. The straight edge detection method of claim 1, wherein The calculation of the first coordinate point of the edge position in each first sub-region includes: obtaining a one-dimensional array of the first sub-region based on the pixels in any first sub-region; filtering the one-dimensional array to obtain edge position data; calculating the gradient of the edge position data, setting a gradient threshold, and filtering out the sub-pixel extreme point coordinates as the first coordinate point.

5. The straight edge detection method of claim 4, wherein, The process of selecting sub-pixel extreme point coordinates includes: obtaining extreme points based on the gradient of edge position data; interpolating the extreme points to obtain sub-pixel candidate edge points; setting a gradient threshold, and selecting the edge coordinates corresponding to the precise sub-pixel position from the sub-pixel candidate edge points where the absolute value of the first-order gradient is greater than the gradient threshold, as the first coordinate point.

6. A one-dimensional measurement method, characterized by, include: Acquire the grayscale image of the object to be tested; Using the straight edge detection method as described in any one of claims 1-5, at least two edge points to be detected are obtained; Calculate the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

7. The one-dimensional measurement method according to claim 6, characterized in that, The measurement information includes the feature location information of the object under test obtained directly and the measurement information obtained through secondary calculation.

8. A one-dimensional measurement system, characterized by include: The acquisition module acquires the grayscale image of the object under test. The ROI module is used to set the initial ROI, and any initial ROI contains the edge of a line to be measured. Divide the initial ROI to obtain several initial sub-regions; The edge computing module takes an initial ROI as the first ROI and an initial sub-region as the first sub-region; calculates the first coordinate point of the edge position in each first sub-region, obtains a first fitted line, and calculates the first angle between the first fitted line and the long side or wide side of the first ROI; based on the first angle, each first sub-region is rotated relative to the grayscale image to obtain a rotated second ROI and several second sub-regions; wherein, the initial ROI and the first sub-region are graphics with a long side and a wide side, and the wide side of the first ROI is parallel to the long side of the first sub-region, and the direction of the long side of the first ROI is parallel to the direction of the wide side of the first sub-region; The edge determination module calculates the second coordinates of the edge location in each second sub-region to determine the edge finding for the second ROI. The direction is relative to the position of the edge of the line to be measured; if it is perpendicular, the second coordinate point is output as the edge point to be measured; otherwise, the rotated second ROI is used as the first ROI, and the edge calculation module is repeated until it is perpendicular; wherein, the edge finding direction represents the direction of finding the edge position. The distance calculation module calculates the distance between at least two edge points to be measured in order to obtain measurement information of the object under test.

9. An electronic device, comprising: The device includes a processor and a memory, wherein the memory is used to store a computer program, the computer program including program instructions, and the processor is configured to call the program instructions to execute a straight edge detection method as described in any one of claims 1-5 or a one-dimensional measurement method as described in any one of claims 6-7.

10. A computer readable storage medium comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements a straight edge detection method as described in any one of claims 1-5 or a one-dimensional measurement method as described in any one of claims 6-7.