Line-circle distance measurement method and system based on edge guidance and spatial search
Patent Information
- Application Number
- CN202610693144.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-20
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2046-05-20
AI Technical Summary
[0008]场景适应性差:当直线或圆被部分遮挡、边缘模糊或存在多个干扰结构时,现有方法难以准确地提取出完整且正确的几何元素,导致测量失败或结果错误
[0065]由上可知,本申请实施例提供的一种基于边缘引导与空间搜索的直线-圆距离测量方法与系统,通过采集原始图像,对原始图像进行预处理,基于Sobel算子对预处理后的原始图像计算图像梯度与梯度方向,得到原始图像的亚像素边缘点集;采用概率Hough变换对直线进行粗定位,采用轮廓提取与最小包围圆方法对圆进行粗定位,得到直线与圆的粗定位结果;基于直线与圆的粗定位结果分别构建直线的带状ROI区域与圆处理 的环形ROI区域;基于环形ROI区域内的亚像素边缘点作为搜索点,通过距离场变换计算搜索点到直线的距离,遍历环形ROI区域内所有亚像素边缘点,得到直线与圆之间的全局最小距离及对应最近点对;将最近点对进行法线方向一致性检查,对距离结果进行统计验证,输出直线与圆的最小距离,并可视化标注最小距离对应的线段;本发明通过粗定位大致确定目标区域,并能提取出部分有效的亚像素边缘点,即可找到正确的最小距离,能够有效处理部分遮挡、边缘模糊、存在干扰元素等复杂情况。
Smart Images

Figure CN122223125B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distance measurement technology, and more specifically, to a method and system for measuring straight-line to circular distance based on edge guidance and spatial search. Background Technology
[0002] In the fields of industrial automation, precision manufacturing, and inspection, accurately measuring the spatial relationships between geometric elements is a crucial step in ensuring product quality. Measuring the minimum distance between a straight line and a circle (or arc) is a common yet challenging task, widely used in scenarios such as detecting the spacing between PCB board pads and gold fingers, evaluating the distance between mounting holes and reference edges in mechanical parts, and measuring wiring gaps in LCD panels. Machine vision technology, due to its non-contact, high-precision, and high-speed characteristics, has become the mainstream method for achieving such measurements.
[0003] Existing machine vision-based methods for measuring line-circle distance typically follow a "recognition first, calculation later" approach. This involves first extracting the geometric parameters of the line and circle from the digital image, and then calculating the minimum distance between them using analytical geometric formulas. The most similar implementations include measurement methods based on Hough transform, least squares fitting, and edge point distance statistics.
[0004] Existing measurement methods have the following drawbacks:
[0005] Accuracy bottleneck: The accuracy of existing methods is limited either by quantization errors in the parameter space or by pixel-level accuracy in edge localization. Even with least-squares fitting, the foundation remains pixel-level edges, making it difficult to break through the pixel limit and meet the growing demand for sub-pixel and even nanometer-level measurements.
[0006] Weak anti-interference capability: Least squares method is sensitive to outliers; point-to-distance methods are sensitive to noise points; although Hough transform has a certain tolerance for noise, the peak values in the parameter space are easily blurred or shifted by noise interference. In actual industrial images, false edges and edge breaks introduced by factors such as uneven lighting, background texture, and material reflection are common, and existing methods are not stable enough in this environment.
[0007] The trade-off between computational efficiency and accuracy: To achieve high accuracy, the Hough transform requires a fine parameter space, leading to computational explosion; point-to-distance-based methods need to handle dense edge points, resulting in enormous computational costs. Fast algorithms often come at the cost of sacrificing accuracy and robustness.
[0008] Poor scene adaptability: When a straight line or circle is partially occluded, the edges are blurred, or there are multiple interfering structures, existing methods have difficulty accurately extracting complete and correct geometric elements, leading to measurement failure or incorrect results. Summary of the Invention
[0009] The purpose of this application is to provide a method and system for measuring straight-line-circle distance based on edge guidance and spatial search. By coarsely locating the target area and extracting some effective sub-pixel edge points, the correct minimum distance can be found. This method can effectively handle complex situations such as partial occlusion, blurred edges, and the presence of interfering elements.
[0010] This application also provides a method for measuring line-circle distance based on edge guidance and spatial search, including:
[0011] The original image is acquired, preprocessed, and the gradient and gradient direction are calculated on the preprocessed original image based on the Sobel operator to obtain the sub-pixel edge point set of the original image.
[0012] The probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, thus obtaining the coarse positioning results of the line and the circle.
[0013] Based on the coarse positioning results of straight lines and circles, a strip-shaped ROI region for straight lines and an annular ROI region for circular processing are constructed respectively.
[0014] Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. By traversing all sub-pixel edge points within the annular ROI region, the global minimum distance between the line and the circle and the corresponding nearest point pair are obtained.
[0015] Perform a normal direction consistency check on the nearest point pairs, statistically verify the distance results, output the minimum distance between the line and the circle, and visually label the line segment corresponding to the minimum distance.
[0016] Optionally, in the line-circle distance measurement method based on edge guidance and spatial search described in the embodiments of this application, the original image is acquired and preprocessed, specifically including:
[0017] The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image.
[0018] Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image;
[0019] The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image.
[0020] Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold;
[0021] Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
[0022] Optionally, in the line-circle distance measurement method based on edge guidance and spatial search described in the embodiments of this application, the method for obtaining the sub-pixel edge point set of the original image is as follows:
[0023] Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula:
[0024]
[0025] in, Represents the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates;
[0026] Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows:
[0027]
[0028] in These are the integer pixel coordinates of the center of the local window;
[0029] By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. and the corresponding normal direction;
[0030] In the formula, represents the Zernike moment, which describes the shape features of a local image window and is the input data for solving the subpixel offset; n and m represent the order and repetition of the Zernike polynomial, respectively. This represents the complex conjugate of the Zernike polynomial, used to compute orthogonal basis functions of the projection of the image onto the ideal model; This represents the sub-pixel coordinates calculated for a single window. This represents the sub-pixel coordinates of the k-th edge point. The algorithm ultimately produces a high-precision set of edge positions, which is used for subsequent distance measurements.
[0031] Optionally, in the straight-line-circle distance measurement method based on edge guidance and spatial search described in the embodiments of this application, the radius of the annular ROI region processed by the circle is r0-Δr, the outer radius is r0+Δr, and Δr is a safety margin;
[0032] The width of the strip-shaped ROI region of the straight line is a strip-shaped region with a width greater than or equal to 2Δr.
[0033] Optionally, in the line-circle distance measurement method based on edge guidance and spatial search described in the embodiments of this application, calculating the global minimum distance between the line and the circle and the corresponding nearest point pair specifically includes:
[0034] Guided by the normal direction of the sub-pixel edge points within the annular ROI region;
[0035] Starting from the edge of the circle, dynamically search for points within the straight ROI region along the normal direction with a set step size to obtain candidate points;
[0036] The distance from the candidate point to the line is calculated based on the distance field transformation, and the point corresponding to the local minimum is obtained. The point corresponding to the local minimum is taken as the approximate closest point from the edge of the circle to the line.
[0037] Traverse all sub-pixel edge points within the circular ROI region, calculate the Euclidean distance from each circular edge point to the point corresponding to the local minimum, and obtain the distance set;
[0038] Based on the distance set, the edge point of the circle with the minimum Euclidean distance and the point corresponding to the local minimum are selected, and the closest point pair with the global minimum distance from the line to the circle is output.
[0039] Optionally, in the line-circle distance measurement method based on edge guidance and spatial search described in the embodiments of this application, the normal direction consistency check is performed on the nearest point pair, specifically including:
[0040] Obtain the normal direction of the edge point of the circle and the normal direction of the nearest point on the straight line based on the sub-pixel edge point set;
[0041] Verify whether the normal direction of a point on the edge of a circle is approximately collinear with and opposite to the normal direction of the nearest point on a line;
[0042] If the conditions of approximation collinearity and opposite directions are met, then the edge point of the circle is considered valid;
[0043] If the approximate collinearity or opposite direction is not satisfied, then the point pair at the edge of the circle is deemed invalid.
[0044] Secondly, embodiments of this application provide a straight-circle distance measurement system based on edge guidance and spatial search. The system includes a memory and a processor. The memory includes a program for a straight-circle distance measurement method based on edge guidance and spatial search. When the program for the straight-circle distance measurement method based on edge guidance and spatial search is executed by the processor, it implements the following steps:
[0045] The original image is acquired, preprocessed, and the gradient and gradient direction are calculated on the preprocessed original image based on the Sobel operator to obtain the sub-pixel edge point set of the original image.
[0046] The probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, thus obtaining the coarse positioning results of the line and the circle.
[0047] Based on the coarse positioning results of straight lines and circles, a strip-shaped ROI region for straight lines and an annular ROI region for circular processing are constructed respectively.
[0048] Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. By traversing all sub-pixel edge points within the annular ROI region, the global minimum distance between the line and the circle and the corresponding nearest point pair are obtained.
[0049] Perform a normal direction consistency check on the nearest point pairs, statistically verify the distance results, output the minimum distance between the line and the circle, and visually label the line segment corresponding to the minimum distance.
[0050] Optionally, in the line-circle distance measurement system based on edge guidance and spatial search described in this application embodiment, acquiring the original image and preprocessing the original image specifically includes:
[0051] The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image.
[0052] Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image;
[0053] The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image.
[0054] Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold;
[0055] Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
[0056] Optionally, in the line-circle distance measurement system based on edge guidance and spatial search described in this application embodiment, the method for obtaining the sub-pixel edge point set of the original image is as follows:
[0057] Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula:
[0058]
[0059] in, Represents the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates;
[0060] Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows:
[0061]
[0062] in These are the integer pixel coordinates of the center of the local window;
[0063] By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. And the corresponding normal direction.
[0064] Thirdly, embodiments of this application also provide a computer-readable storage medium, which includes a program for a line-circle distance measurement method based on edge guidance and spatial search. When the program for a line-circle distance measurement method based on edge guidance and spatial search is executed by a processor, it implements the steps of the line-circle distance measurement method based on edge guidance and spatial search as described in any of the preceding claims.
[0065] As can be seen from the above, the line-circle distance measurement method and system based on edge guidance and spatial search provided in this application involves acquiring an original image, preprocessing the original image, calculating the image gradient and gradient direction based on the Sobel operator to obtain the sub-pixel edge point set of the original image, using probabilistic Hough transform for coarse localization of the line, and using contour extraction and minimum bounding circle methods for coarse localization of the circle to obtain the coarse localization results of the line and the circle, constructing a strip-shaped ROI region for the line and a ring-shaped ROI region for the circle based on the coarse localization results of the line and the circle, respectively; and constructing a ring-shaped ROI region for the line and a ring-shaped ROI region for the circle based on the ring-shaped ROI region. Subpixel edge points within the I-region are used as search points. The distance from the search point to the line is calculated through distance field transformation. All subpixel edge points within the annular ROI region are traversed to obtain the global minimum distance between the line and the circle and the corresponding nearest point pair. The normal direction consistency of the nearest point pair is checked, the distance results are statistically verified, the minimum distance between the line and the circle is output, and the line segment corresponding to the minimum distance is visually labeled. This invention can roughly determine the target area through coarse localization and can extract some effective subpixel edge points to find the correct minimum distance. It can effectively handle complex situations such as partial occlusion, edge blurring, and the presence of interfering elements. Attached Figure Description
[0066] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0067] Figure 1 A flowchart of a line-circle distance measurement method based on edge guidance and spatial search provided in this application embodiment; Figure 2 A flowchart illustrating a preferred embodiment of the line-circle distance measurement method based on edge guidance and spatial search provided in this application. Figure 3 A schematic diagram of dynamic spatial search based on normal direction for the line-circle distance measurement method based on edge guidance and spatial search provided in the embodiments of this application; Figure 4 A visualization example of the measurement results of the line-circle distance measurement method based on edge guidance and spatial search provided in the embodiments of this application. Detailed Implementation
[0068] The technical solutions of the embodiments of this application 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 application, and not all of the embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0069] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, the terms "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0070] Please refer to Figures 1-4 As shown, the line-to-circle distance measurement method based on edge guidance and spatial search is used in a terminal device. This method includes the following steps:
[0071] S101: Acquire the original image, preprocess the original image, calculate the image gradient and gradient direction based on the Sobel operator, and obtain the sub-pixel edge point set of the original image.
[0072] S102, the probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, so as to obtain the coarse positioning results of the line and the circle.
[0073] S103, Based on the coarse positioning results of straight lines and circles, construct the strip-shaped ROI region of the straight line and the annular ROI region of the circle respectively;
[0074] S104: Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. All sub-pixel edge points within the annular ROI region are traversed to obtain the global minimum distance between the line and the circle and the corresponding nearest point pair.
[0075] S105 performs a normal direction consistency check on the nearest point pairs, performs statistical verification on the distance results, outputs the minimum distance between the line and the circle, and visually labels the line segment corresponding to the minimum distance.
[0076] According to an embodiment of the present invention, acquiring an original image and preprocessing the original image specifically includes:
[0077] The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image.
[0078] Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image;
[0079] The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image.
[0080] Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold;
[0081] Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
[0082] It should be noted that the original images acquired... Preprocessing is performed, including Gaussian filtering to suppress noise while preserving edge information as much as possible. Then, the gradient magnitude of the image is calculated using a first-order differential operator (such as Sobel). and gradient direction .
[0083] According to an embodiment of the present invention, the method for obtaining the sub-pixel edge point set of the original image is as follows:
[0084] Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula:
[0085]
[0086] in, Represents the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates;
[0087] Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows:
[0088]
[0089] in These are the integer pixel coordinates of the center of the local window;
[0090] By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. And the corresponding normal direction.
[0091] It should be noted that the Zernike moment method can be replaced by moment-preserving methods, edge model-fitting methods (such as fitting a parabola after bilinear interpolation), or gradient-based interpolation methods (such as Gaussian interpolation using gradient magnitude).
[0092] The Hough transform can be replaced by a contour segment detection-based method (such as LSD) for coarse line localization, or by an edge-connected component analysis-based method for coarse circle localization.
[0093] According to an embodiment of the present invention, the radius of the annular ROI region after circular processing is r0-Δr, the outer radius is r0+Δr, and Δr is a safety margin;
[0094] The width of the linear ROI region is a strip region greater than or equal to 2Δr.
[0095] Specifically, robust region localization of lines and circles.
[0096] Unlike traditional methods that directly apply Hough transform or fitting to the entire image, this invention employs a more efficient and robust region localization strategy.
[0097] Coarse localization: First, using fast algorithms, such as the Probabilistic Hough Transform (PHT) for lines, or contour extraction and minimum bounding circle methods for circles, a rapid coarse localization of the target lines and circles is performed. The purpose of this step is not to obtain high-precision geometric parameters, but to determine the region of interest (ROI) in which they are located. For example, for a circle, an approximate center can be obtained. and radius For a straight line, its approximate angle can be obtained. and location .
[0098] ROI Definition: Based on the coarse positioning results, fine-processed ROIs for lines and circles are defined separately. The ROI for a line can be a strip-shaped region surrounding the coarse positioning line.
[0099] According to an embodiment of the present invention, calculating the global minimum distance between a line and a circle and the corresponding nearest point pair specifically includes:
[0100] Guided by the normal direction of the sub-pixel edge points within the annular ROI region;
[0101] Starting from the edge of the circle, dynamically search for points within the straight ROI region along the normal direction with a set step size to obtain candidate points;
[0102] The distance from the candidate point to the line is calculated based on the distance field transformation, and the point corresponding to the local minimum is obtained. The point corresponding to the local minimum is taken as the approximate closest point from the edge of the circle to the line.
[0103] Traverse all sub-pixel edge points within the circular ROI region, calculate the Euclidean distance from each circular edge point to the point corresponding to the local minimum, and obtain the distance set.
[0104] Based on the distance set, the edge point of the circle with the minimum Euclidean distance and the point corresponding to the local minimum are selected, and the closest point pair with the global minimum distance from the line to the circle is output.
[0105] It should be noted that a dynamic search strategy guided by sub-pixel edge points and their normal directions is used to directly find the minimum distance point pairs.
[0106] Construction and initialization of the distance field: Within the circular region of interest (ROI), there is a sub-pixel edge point set. Each point All have normal direction (For a circle, the normal direction approximately points towards the center.) Within the ROI of a straight line, there is a set of sub-pixel edge points. Each point All have normal direction (For a straight line, the direction of the normal is perpendicular to the direction of the line.)
[0107] (Complete Set) Meaning: The set of all sub-pixel edge points detected in the entire image and their normal directions.
[0108] (Target Subset) Meaning: A subset of subpixel edge points located within the annular ROI region, which are considered to belong to the edge of the target circle.
[0109] (Target Subset) Meaning: A subset of subpixel edge points located within a strip-shaped ROI region, which are considered to be edges belonging to the target line.
[0110] Guided nearest-point search: for a point on the edge of a circle The shortest path direction to the line should be approximately the direction of its normal. In the direction of the straight line normal The projection direction (obtainable from the coarse positioning line) does not need to be calculated. arrive The distance of all points. Conversely, with Starting from the direction of its normal, A dynamic step-by-step ray search is performed on both sides (because it is uncertain which side of the circle the line is on).
[0111] Set a search step size (e.g., 0.1 pixels).
[0112] from Depart, along Direction, by step Move to obtain a series of candidate points .
[0113] For each candidate point This calculates a value for a predefined "linear distance field." This "linear distance field" can be obtained by... The distance field is obtained by performing a distance transformation, resulting in a two-dimensional array where each pixel's value represents the Euclidean distance from that point to the nearest straight-line edge. To achieve sub-pixel accuracy, this distance field needs to be interpolated at the sub-pixel level. When a candidate point is found... Its value in the distance field It is a local minimum, and the gradient direction at that point is parallel to... Conversely (indicating this is near the foot of the perpendicular from the circle to the line), it is believed that a path has been found from... Approximate closest point to the line .
[0114] Record this point pair and its Euclidean distance .
[0115] Determining the global minimum distance: Traverse all sub-pixel edge points within the circular ROI. By performing the above search process, a distance set is obtained. The minimum value in this set and their corresponding point pairs This represents the minimum distance between the line and the circle, and the corresponding nearest point pair.
[0116] According to an embodiment of the present invention, a normal direction consistency check is performed on the nearest point pair, specifically including:
[0117] Obtain the normal direction of the edge point of the circle and the normal direction of the nearest point on the straight line based on the sub-pixel edge point set;
[0118] Verify whether the normal direction of a point on the edge of a circle is approximately collinear with and opposite to the normal direction of the nearest point on a line;
[0119] If the conditions of approximation collinearity and opposite directions are met, then the edge point of the circle is considered valid;
[0120] If the approximate collinearity or opposite direction is not satisfied, then the point pair at the edge of the circle is deemed invalid.
[0121] It should be noted that a result verification mechanism is introduced:
[0122] Consistency check: Check the nearest pair of points found. Are the normal directions at a given point approximately collinear and opposite? That is, check... Is the result valid? If not, it may be due to noise or a search error, and the result will be marked as unreliable.
[0123] Statistical Validation: Analyzing the Distance Set The distribution. If This is a clear outlier (e.g., much smaller than other distances), and may require a comprehensive assessment in conjunction with the second smallest value, or a confidence evaluation when the line / circle is severely occluded. Ultimately, the system outputs the minimum distance. And draw the line segment corresponding to that distance on the image (connecting) and ).
[0124] In summary, the beneficial effects of the present invention are as follows:
[0125] Measurement accuracy reaches sub-pixel level: By using Zernike moments for sub-pixel edge localization and incorporating this high-precision information into subsequent dynamic search and distance calculation, this invention successfully breaks through the pixel-level accuracy bottleneck of traditional methods, enabling sub-pixel level or even higher precision distance measurement.
[0126] Strong anti-interference capability and robustness: The dynamic spatial search strategy does not rely on an exact fit to the complete geometry, thus exhibiting inherent robustness against edge breaks and local occlusion. Guided search, based on edge normal directions, effectively avoids most irrelevant regions and noise points. A result verification mechanism further ensures the reliability of the output results.
[0127] Significantly improved computational efficiency: coarse localization narrows the scope of fine-grained processing (ROI), and guided search avoids calculating the massive distance matrix between all point pairs, reducing computational complexity from... Reduced to approximately (K is the average number of search steps, and) While ensuring accuracy, it significantly improves the calculation speed, meeting the needs of real-time industrial detection.
[0128] The symbols O(M×N) and O(M×K) represent the time complexity of an algorithm, used to measure the trend of algorithm execution time as the size of the input data increases.
[0129] O: Big O notation, which stands for "Order" and is used to describe the time complexity of an algorithm in the worst-case or average-case scenario.
[0130] M: Usually represents the number of sub-pixels on the edge of a circle.
[0131] N: Usually represents the number of sub-pixels on the edge of a straight line.
[0132] K: In the patented new method, K represents the average number of steps taken to search along the normal direction starting from a point on the edge of a circle. K is a number much smaller than N (K << N).
[0133] Secondly, embodiments of this application provide a straight-circle distance measurement system based on edge guidance and spatial search. The system includes a memory and a processor. The memory includes a program for a straight-circle distance measurement method based on edge guidance and spatial search. When the program for the straight-circle distance measurement method based on edge guidance and spatial search is executed by the processor, it implements the following steps:
[0134] The original image is acquired, preprocessed, and the gradient and gradient direction are calculated on the preprocessed original image based on the Sobel operator to obtain the sub-pixel edge point set of the original image.
[0135] The probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, thus obtaining the coarse positioning results of the line and the circle.
[0136] Based on the coarse positioning results of straight lines and circles, a strip-shaped ROI region for straight lines and an annular ROI region for circular processing are constructed respectively.
[0137] Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. By traversing all sub-pixel edge points within the annular ROI region, the global minimum distance between the line and the circle and the corresponding nearest point pair are obtained.
[0138] Perform a normal direction consistency check on the nearest point pairs, statistically verify the distance results, output the minimum distance between the line and the circle, and visually label the line segment corresponding to the minimum distance.
[0139] According to an embodiment of the present invention, acquiring an original image and preprocessing the original image specifically includes:
[0140] The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image.
[0141] Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image;
[0142] The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image.
[0143] Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold;
[0144] Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
[0145] According to an embodiment of the present invention, the method for obtaining the sub-pixel edge point set of the original image is as follows:
[0146] Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula:
[0147]
[0148] in, Indicates the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates;
[0149] Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows:
[0150]
[0151] in These are the integer pixel coordinates of the center of the local window;
[0152] By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. And the corresponding normal direction.
[0153] A third aspect of the present invention provides a computer-readable storage medium including a program for a line-circle distance measurement method based on edge guidance and spatial search. When the program for the line-circle distance measurement method based on edge guidance and spatial search is executed by a processor, it implements the steps of the line-circle distance measurement method based on edge guidance and spatial search as described in any of the above claims.
[0154] This invention discloses a method and system for measuring line-circle distance based on edge guidance and spatial search. The method involves acquiring an original image, preprocessing the image, calculating the image gradient and gradient direction based on the Sobel operator to obtain the sub-pixel edge point set of the original image, using probabilistic Hough transform for coarse line localization, and using contour extraction and minimum bounding circle methods for coarse circle localization, resulting in coarse localization results for both the line and the circle. Based on these coarse localization results, a strip-shaped ROI region for the line and a ring-shaped ROI region for the circle are constructed. Within the ring-shaped ROI region... Using sub-pixel edge points as search points, the distance from the search point to the line is calculated through distance field transformation. All sub-pixel edge points within the annular ROI region are traversed to obtain the global minimum distance between the line and the circle and the corresponding nearest point pair. The nearest point pair is then checked for normal direction consistency, and the distance results are statistically verified. The minimum distance between the line and the circle is output, and the line segment corresponding to the minimum distance is visually labeled. This invention can roughly determine the target area through coarse localization and extract some effective sub-pixel edge points to find the correct minimum distance. It can effectively handle complex situations such as partial occlusion, edge blurring, and the presence of interfering elements.
[0155] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0156] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0157] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0158] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0159] Alternatively, if the integrated units of the present invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.
Claims
1. A method for measuring line-circle distance based on edge guidance and spatial search, characterized in that, include: The original image is acquired, preprocessed, and the gradient and gradient direction are calculated on the preprocessed original image based on the Sobel operator to obtain the sub-pixel edge point set of the original image. The probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, thus obtaining the coarse positioning results of the line and the circle. Based on the coarse positioning results of straight lines and circles, a strip-shaped ROI region for straight lines and an annular ROI region for circular processing are constructed respectively. Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. By traversing all sub-pixel edge points within the annular ROI region, the global minimum distance between the line and the circle and the corresponding nearest point pair are obtained. Perform a normal direction consistency check on the nearest point pairs, statistically verify the distance results, output the minimum distance between the line and the circle, and visually label the line segment corresponding to the minimum distance.
2. The line-circle distance measurement method based on edge guidance and spatial search according to claim 1, characterized in that, Acquire the raw image and preprocess it, specifically including: The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image. Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image; The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image. Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold; Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
3. The line-circle distance measurement method based on edge guidance and spatial search according to claim 2, characterized in that, The method for obtaining the sub-pixel edge point set of the original image is as follows: Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula: ; in, Represents the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates; Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows: ; in These are the integer pixel coordinates of the center of the local window; By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. and the corresponding normal direction; In the formula, represents the Zernike moment; n and m represent the order and repetition of the Zernike polynomial, respectively; Represent the complex conjugate of a Zernike polynomial; This represents the sub-pixel coordinates calculated for a single window. This represents the sub-pixel coordinates of the k-th edge point.
4. The line-circle distance measurement method based on edge guidance and spatial search according to claim 3, characterized in that, The radius of the annular ROI region processed by the circle is r0-Δr, and the outer radius is r0+Δr, where Δr is a safety margin. The width of the strip-shaped ROI region of the straight line is a strip-shaped region with a width greater than or equal to 2Δr.
5. The line-circle distance measurement method based on edge guidance and spatial search according to claim 4, characterized in that, Calculate the global minimum distance between a line and a circle and the corresponding nearest point pair, specifically including: Guided by the normal direction of the sub-pixel edge points within the annular ROI region; Starting from the edge of the circle, dynamically search for points within the straight ROI region along the normal direction with a set step size to obtain candidate points; The distance from the candidate point to the line is calculated based on the distance field transformation, and the point corresponding to the local minimum is obtained. The point corresponding to the local minimum is taken as the approximate closest point from the edge of the circle to the line. Traverse all sub-pixel edge points within the circular ROI region, calculate the Euclidean distance from each circular edge point to the point corresponding to the local minimum, and obtain the distance set; Based on the distance set, the edge point of the circle with the minimum Euclidean distance and the point corresponding to the local minimum are selected, and the closest point pair with the global minimum distance from the line to the circle is output.
6. The line-circle distance measurement method based on edge guidance and spatial search according to claim 5, characterized in that, Perform a normal direction consistency check on the nearest point pairs, specifically including: Obtain the normal direction of the edge point of the circle and the normal direction of the nearest point on the straight line based on the sub-pixel edge point set; Verify whether the normal direction of a point on the edge of a circle is approximately collinear with and opposite to the normal direction of the nearest point on a line; If the conditions of approximation collinearity and opposite directions are met, then the edge point of the circle is considered valid; If the approximate collinearity or opposite direction is not satisfied, then the point pair at the edge of the circle is deemed invalid.
7. A straight-to-circle distance measurement system based on edge guidance and spatial search, characterized in that, The system includes: a memory and a processor, wherein the memory includes a program for the line-circle distance measurement method based on edge guidance and spatial search as described in any one of claims 1-6, and when the program for the line-circle distance measurement method based on edge guidance and spatial search is executed by the processor, it performs the following steps: The original image is acquired, preprocessed, and the gradient and gradient direction are calculated on the preprocessed original image based on the Sobel operator to obtain the sub-pixel edge point set of the original image. The probabilistic Hough transform is used to coarsely locate the line, and the contour extraction and minimum enclosing circle method is used to coarsely locate the circle, thus obtaining the coarse positioning results of the line and the circle. Based on the coarse positioning results of straight lines and circles, a strip-shaped ROI region for straight lines and an annular ROI region for circular processing are constructed respectively. Based on the sub-pixel edge points within the annular ROI region as search points, the distance from the search point to the line is calculated through distance field transformation. By traversing all sub-pixel edge points within the annular ROI region, the global minimum distance between the line and the circle and the corresponding nearest point pair are obtained. Perform a normal direction consistency check on the nearest point pairs, statistically verify the distance results, output the minimum distance between the line and the circle, and visually label the line segment corresponding to the minimum distance.
8. The line-circle distance measurement system based on edge guidance and spatial search according to claim 7, characterized in that, Acquire the raw image and preprocess it, specifically including: The original image is acquired, and an adaptive Gaussian filter is used to denoise the original image to obtain the denoised image. Adaptive histogram equalization is performed on the denoised image to obtain a contrast-enhanced image; The gradient in the x-direction and gradient in the y-direction of the contrast-enhanced image are calculated based on the Sobel operator to obtain the gradient magnitude. The gradient magnitude is then normalized to obtain the gradient-enhanced image. Set a gradient magnitude threshold and compare the gradient magnitude with the gradient magnitude threshold; Pixels with gradient magnitudes greater than a gradient magnitude threshold are selected to obtain a preliminary edge point set.
9. The line-circle distance measurement system based on edge guidance and spatial search according to claim 8, characterized in that, The method for obtaining the sub-pixel edge point set of the original image is as follows: Define kernel size as Given a template, calculate the Zernike moments of the image within the template region using the following formula: ; in, Represents the grayscale of the image. Represents the Zernike polynomial. Represents the normalized polar coordinates; Solving the relationship between Zernike moments and the ideal edge model yields the sub-pixel offsets. The sub-pixel coordinates of the edge points are calculated based on the sub-pixel offset as follows: ; in These are the integer pixel coordinates of the center of the local window; By iterating through all candidate edge points, we obtain the sub-pixel edge point set of the entire image. and the corresponding normal direction; In the formula, represents the Zernike moment; n and m represent the order and repetition of the Zernike polynomial, respectively; Represent the complex conjugate of a Zernike polynomial; This represents the sub-pixel coordinates calculated for a single window. This represents the sub-pixel coordinates of the k-th edge point.
Citation Information
Patent Citations
Method for orientating secondary pixel edge of oval-shaped target
CN101465002A
Edge detection method and apparatus, electronic device, and storage medium
WO2023124725A1
