Circle Positioning Algorithm Based on Two-Dimensional Edge Measurement and Least Squares Principle
Through the circular positioning algorithm based on two-dimensional edge measurement and least squares principle, the problem of complex, time-consuming and low accuracy in the current technology is solved, and the rapid and high-precision circular positioning is achieved to adapt to industry Real-time and accuracy requirements on site.
Patent Information
- Application Number
- CN202110451209.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-25
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2041-04-25
AI Technical Summary
The existing circular object detection methods are complex in the industry, time-consuming and low accuracy, making it difficult to meet the real-time and accuracy requirements of industrial sites.
Using a circular positioning algorithm based on two-dimensional edge measurement and least squares principle, select the appropriate one by obtaining an edge point array and performing circle fitting, including setting the detection circle domain, calculating pixel values, performing Gaussian smoothing and differential, parabolic interpolation, and selecting the appropriate one. Fitting the method (algebraic or geometric fitting) to solve the parameters of the circle, combining Huber and Tukey functions to enhance robustness.
It realizes fast and high-precision circular positioning, adapts to the complex and changeable needs of industrial sites, meets real-time and accuracy requirements, and improves the adaptability and robustness of the algorithm.
Smart Images

Figure CN113192120B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of industrial machine vision positioning, and in particular to a circle positioning algorithm based on two-dimensional edge measurement and the least squares principle. Background Art
[0002] Machine vision mainly uses computers to simulate human visual functions for actual detection, measurement and control. In machine vision systems, visual positioning plays a very important role. Visual positioning technology has been increasingly widely used in industry, greatly improving production efficiency and the degree of automation of production. Among them, the positioning needs of circular targets often appear in industrial inspections.
[0003] Commonly used circular target detection methods include template matching, Hough transform, wavelet transform and other methods. These methods can accurately detect targets and have good robustness to noise, but they are computationally complex, time-consuming and have low accuracy.
[0004] Therefore, a technology is urgently needed to solve this problem. Summary of the invention
[0005] The purpose of the present invention is to overcome the problems of the above-mentioned prior art. According to the requirements of industrial sites for real-time and accuracy, a circle positioning algorithm based on two-dimensional edge measurement and the least squares principle is provided, including obtaining an edge point array and performing circle fitting on the edge point array. The algorithm can adapt to the complex and changeable application requirements of industrial sites, open up multiple parameters of the algorithm, and has good adaptability, fast speed and high accuracy.
[0006] The above objectives are achieved through the following technical solutions:
[0007] The circle positioning algorithm based on two-dimensional edge measurement and the least squares principle includes: obtaining an edge point array and performing circle fitting on the edge point array:
[0008] The obtaining of the edge point array comprises: setting a detection annular region at the target circle, determining the number and width of scanning lines according to the annular region, and obtaining a scanning rectangle, that is, determining the number, width and height of the scanning rectangle;
[0009] Calculating the coordinates of each position in each scanning rectangle according to the number, width and height of the scanning rectangle;
[0010] Calculating the pixel value of each coordinate in each scanning rectangle by bilinear interpolation method;
[0011] Calculate the mean of the pixel values in each column according to the pixel values of each coordinate to obtain a mean pixel value array;
[0012] Performing Gaussian smoothing on the mean pixel value array to obtain a smoothed pixel value array;
[0013] Differentiating the smoothed pixel value array to obtain a change rate array;
[0014] Select appropriate data in the change rate array according to edge polarity and edge order to form a new change rate array;
[0015] Performing parabolic interpolation on the new change rate array, calculating edge points, and obtaining an edge point array;
[0016] The circle fitting comprises:
[0017] If the data of the edge point array has no outliers, a circle fitting is performed on the edge point array using an algebraic fitting method;
[0018] If the data of the edge point array contains outliers, a geometric fitting method is used to perform circle fitting on the edge point array.
[0019] Furthermore, a detection annular region is set at the target circle, and the center of the annular region and the radii of the inner and outer circles are adjustable to ensure that the edge of the target circle is within the annular region.
[0020] Furthermore, in performing Gaussian smoothing on the mean pixel value array, a standard deviation parameter of the Gaussian smoothing is open and adjustable so as to handle different noise levels.
[0021] Furthermore, in selecting appropriate data in the change rate array to form a new change rate array through edge polarity and edge order, the edge polarity includes: black to white, white to black and random; the edge order includes: best, first and last.
[0022] Furthermore, the algebraic fitting method is based on the algebraic equation of a circle, as follows:
[0023] A(x 2 +y 2 )+Bx+Cy+D=0
[0024] Where A=(A,B,C,D) T is a 4-parameter vector, A, B, C, D are the four parameters of the equation, and (x, y) are the data points used to fit the circle;
[0025] By minimizing all points {(x i ,y i )} solves the parameter vector by minimizing the following function, subject to the constraint A T NA=1, the formula is as follows:
[0026]
[0027] in, {(xi ,y i )} is the data point, n is the number of data points, then:
[0028]
[0029] Where X and M are data matrices, N is the constraint matrix,
[0030] The solution A is the generalized eigenvector of the matrix pair (M, N); after the solution of the algebraic equation is obtained, the center and radius of the fitting circle are obtained by the conversion formula, and the conversion formula is: Where (a, b) is the center of the circle and R is the radius.
[0031] The geometric fitting method is based on the standard equation of a circle, as follows:
[0032] (x) 2 +(yb) 2 =R 2
[0033] Where (a, b) is the center of the circle and R is the radius.
[0034] Furthermore, it also includes increasing the robustness of the algorithm, specifically:
[0035] By minimizing the objective function To solve the parameter a = (a, b, R), where It is the orthogonal distance from a single edge point to the target circle. The weight function includes Huber function and Tukey function, as shown below:
[0036]
[0037] Among them, k is the Choper factor.
[0038] Beneficial Effects
[0039] The present invention provides a circle positioning algorithm based on two-dimensional edge measurement and the least squares principle, which includes obtaining an edge point array and performing circle fitting on the edge point array. It provides multiple parameters for selection and can adapt to different circle target positioning requirements. The algorithm runs fast and has high precision, and can meet the real-time and accuracy requirements of industrial production sites. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 It is a flow chart of the circle positioning algorithm based on two-dimensional edge measurement and least squares principle of the present invention;
[0041] Figure 2The circle positioning algorithm based on two-dimensional edge measurement and least squares principle of the present invention is applied to the original image of the PCB board with circular Mark points;
[0042] Figure 3 This is a diagram showing the effect of applying the circle positioning algorithm based on two-dimensional edge measurement and least squares principle described in the present invention to a PCB board with circular Mark points;
[0043] Figure 4 This is a fitting result diagram of the circle positioning algorithm based on two-dimensional edge measurement and least squares principle described in the present invention applied to a PCB board with circular Mark points;
[0044] Figure 5 The original image of the circle positioning algorithm based on two-dimensional edge measurement and least squares principle of the present invention applied to a mold with a circular contour;
[0045] Figure 6 This is a rendering of the circle positioning algorithm based on two-dimensional edge measurement and least squares principle of the present invention applied to a mold with a circular contour;
[0046] Figure 7 This is a fitting result diagram of the circle positioning algorithm based on two-dimensional edge measurement and least squares principle described in the present invention applied to a mold with a circular contour. DETAILED DESCRIPTION
[0047] The present invention is further described in detail below based on the accompanying drawings and embodiments.
[0048] like Figure 1 As shown, a circle positioning algorithm based on two-dimensional edge measurement and least squares principle includes the following two steps:
[0049] (1) Get edge point array;
[0050] (2) performing circle fitting on the edge point array;
[0051] Step (1) obtaining an edge point array specifically includes: setting a detection annular region at the target circle, determining the number and width of scanning lines according to the annular region, and obtaining a scanning rectangle, that is, determining the number, width and height of the scanning rectangle;
[0052] Calculating the coordinates of each position in each scanning rectangle according to the number, width and height of the scanning rectangle;
[0053] Calculating the pixel value of each coordinate in each scanning rectangle by bilinear interpolation method;
[0054] Calculate the mean of the pixel values in each column according to the pixel values of each coordinate to obtain a mean pixel value array;
[0055] Performing Gaussian smoothing on the mean pixel value array to obtain a smoothed pixel value array;
[0056] Differentiating the smoothed pixel value array to obtain a change rate array;
[0057] Select appropriate data in the change rate array according to edge polarity and edge order to form a new change rate array;
[0058] Performing parabolic interpolation on the new change rate array, calculating edge points, and obtaining an edge point array;
[0059] Step (2) circle fitting, specifically includes:
[0060] If the data of the edge point array has no outliers, a circle fitting is performed on the edge point array using an algebraic fitting method;
[0061] If the data of the edge point array contains outliers, a geometric fitting method is used to perform circle fitting on the edge point array.
[0062] As an optimization of the technical solution, a detection annular domain is set at the target circle, and the center of the annular domain and the radii of the inner and outer circles are adjustable to ensure that the edge of the target circle is within the annular domain.
[0063] In performing Gaussian smoothing on the mean pixel value array, a standard deviation parameter of the Gaussian smoothing is open and adjustable so as to handle different noise levels.
[0064] In forming a new change rate array by selecting appropriate data in the change rate array through edge polarity and edge order, the edge polarity includes: black to white, white to black and random; the edge order includes: best, first and last.
[0065] As a specific description of the algebraic fitting method and the geometric fitting method in step (2), wherein:
[0066] The algebraic fitting method is specifically:
[0067] The algebraic fitting method is based on the algebraic equation of a circle, as follows:
[0068] A(x 2 +y 2 )+Bx+Cy+D=0
[0069] Where A=(A,B,C,D) T is a 4-parameter vector, A, B, C, D are the four parameters of the equation, and (x, y) are the data points used to fit the circle;
[0070] By minimizing all points {(x i ,y i)} solves the parameter vector by minimizing the following function, subject to the constraint A T NA=1, the formula is as follows:
[0071]
[0072] in, {(x i ,y i )} is the data point, n is the number of data points, then:
[0073]
[0074] Where X and M are data matrices, N is the constraint matrix,
[0075] The solution A is the generalized eigenvector of the matrix pair (M, N); after the solution of the algebraic equation is obtained, the center and radius of the fitting circle are obtained by the conversion formula, and the conversion formula is: Where (a, b) is the center of the circle and R is the radius.
[0076] The geometric fitting method is specifically:
[0077] The geometric fitting method is based on the standard equation of a circle, as follows:
[0078] (x) 2 +(yb) 2 =R 2
[0079] Where (a, b) is the center of the circle and R is the radius.
[0080] It also includes increasing the robustness of the algorithm, specifically:
[0081] By minimizing the objective function To solve the parameter a = (a, b, R), where It is the orthogonal distance from a single edge point to the target circle. The weight function includes Huber function and Tukey function, as shown below:
[0082]
[0083] Among them, k is the Choper factor.
[0084] In the above scheme, the objective function is solved by the gradient descent method, and the initial values of the parameters required by the gradient descent method are given by the algebraic method. Among them, the circle fitting method is open, including the algebraic fitting method and the geometric fitting method; the outlier suppression method in the geometric fitting method is open, including Huber and Tukey, which can be selected according to specific needs.
[0085] Example 1
[0086] like Figure 2 As shown in the figure, a PCB board with a circular Mark point is shown. Since the purpose of obtaining the center of the Mark point is to calibrate, the positioning accuracy is required to be high. The specific steps of using this technical solution are as follows:
[0087] Step (1) obtains the edge point array, specifically:
[0088] (a) Set a circular ring at the circular mark point. The center of the circular ring can be near the center of the circular mark point, and the width of the circular ring can ensure that the edge of the circular mark point is within it. Figure 1 The inner circular mark point is broken. 50 scan lines are set, and the scan width of each scan line is 5 pixels. The purpose is to obtain enough edge points to improve the fitting accuracy. In this way, the number, width and height of the scan rectangle are determined.
[0089] (b) For each scanned rectangle, first calculate the coordinates of each position in the rectangle, then calculate the pixel value at each coordinate in the rectangle by the bilinear interpolation method, and then calculate the mean of the pixel values in each column to obtain an array of mean pixel values; in order to reduce the influence of noise points, Gaussian smoothing is performed on the array to obtain a smoothed pixel value array. The Gaussian kernel is 1*5 and the standard deviation is set to 1. Then, the array is differentiated to obtain a change rate array.
[0090] (c) Because we want to obtain the edge points at the outer edge of the circular Mark point, we need to set the edge polarity to black to white, the edge order to the last, and the edge threshold to 5. In this way, we get the rate of change array that meets the conditions, and then perform parabolic interpolation on it to get the edge points we expect (see the processing effect). Figure 3 ).
[0091] Step (2) circle fitting, specifically:
[0092] Because the edges of the circular Mark points are broken and the edge points are unevenly distributed, a geometric method including Tukey outlier suppression is selected for circle fitting.
[0093] First, the Kasa algebra method is used to obtain the initial value of the fitting circle (a0, b0, R0) = (1121.321, 508.791, 52.786), the Xiao Bo factor is calculated to be k = 1.919, and the final fitting result is (a, b, R) = (1120.681, 507.484, 52.784). The fitting effect is as follows: Figure 4 shown.
[0094] Example 2
[0095] like Figure 5As shown in the figure, there is a mold with a circular outline. Our goal is to fit the circle in the middle of the mold and then calculate several points on the circle to facilitate the robot to follow the trajectory. The specific steps are as follows:
[0096] Step (1) obtains the edge point array, specifically:
[0097] (a) A circular ring domain is set at the circular contour in the middle of the mold. The center of the circular ring domain can be near the center of the circular contour, and the width of the circular ring domain must ensure that the edge of the circular contour is within it. Since the circular contour has a good imaging effect, 20 scanning lines are set, and the scanning width of each scanning line is 5 pixels. In this way, the number, width and height of the scanning rectangle are determined.
[0098] (b) For each scanned rectangle, first calculate the coordinates of each position in the rectangle, then calculate the pixel value at each coordinate in the rectangle by the bilinear interpolation method, and then calculate the mean of the pixel values in each column to obtain an array of mean pixel values. In order to reduce the influence of noise points, Gaussian smoothing is performed on the array to obtain a smoothed pixel value array. The Gaussian kernel is 1*5 and the standard deviation is set to 1. Then the array is differentiated to obtain a change rate array.
[0099] (c) Because we want to obtain the edge point at the outer edge of the circular contour in the middle of the mold, we need to set the edge polarity to black to white, the edge order to the first, and the edge threshold to 10. In this way, we get a rate of change array that meets the conditions. Then we perform parabolic interpolation on it to get the edge point we expect. The processing effect is as follows: Figure 6 shown.
[0100] Step (2) circle fitting, specifically:
[0101] Since the edge points obtained in this embodiment are evenly distributed and have no noise points, the Taubin algebra method is selected to fit the circle.
[0102] The data matrices X and M and the constraint matrix N result as follows:
[0103]
[0104]
[0105]
[0106] The final fitting circle result is (a, b, R) = (511.55, 548.117, 117.186). The fitting effect is as follows Figure 7 shown.
[0107] The above description is only for illustrating the implementation mode of the present invention and is not intended to limit the present invention. For those skilled in the art, any modification, equivalent substitution, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A circle positioning algorithm based on two-dimensional edge measurement and least squares principle, characterized in that: Get edge point array and perform circle fitting on the edge point array: The obtaining of the edge point array comprises: setting a detection annular region at the target circle, determining the number and width of scanning lines according to the annular region, and obtaining a scanning rectangle, that is, determining the number, width and height of the scanning rectangle; Calculating the coordinates of each position in each scanning rectangle according to the number, width and height of the scanning rectangle; Calculating the pixel value of each coordinate in each scanning rectangle by bilinear interpolation method; Calculate the mean of the pixel values in each column according to the pixel values of each coordinate to obtain a mean pixel value array; Performing Gaussian smoothing on the mean pixel value array to obtain a smoothed pixel value array; Differentiating the smoothed pixel value array to obtain a change rate array; Selecting data in the change rate array to form a new change rate array according to edge polarity and edge order; Performing parabolic interpolation on the new change rate array, calculating edge points, and obtaining an edge point array; The circle fitting comprises: If the data of the edge point array has no outliers, a circle fitting is performed on the edge point array using an algebraic fitting method; If the data of the edge point array contains outliers, a geometric fitting method is used to perform circle fitting on the edge point array.
2. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 1 is characterized in that: A detection annular region is set at the target circle, and the center of the annular region and the radii of the inner and outer circles are adjustable to ensure that the edge of the target circle is within the annular region.
3. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 1 is characterized in that: In performing Gaussian smoothing on the mean pixel value array, a standard deviation parameter of the Gaussian smoothing is open and adjustable so as to handle different noise levels.
4. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 1 is characterized in that: In selecting appropriate data in the change rate array to form a new change rate array through edge polarity and edge order, the edge polarity includes: black to white, white to black and random; the edge order includes: best, first and last.
5. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 1 is characterized in that: The algebraic fitting method is based on the algebraic equation of a circle, as follows: A(x 2 +y 2 )+Bx+Cy+D=0 Where G = (A, B, C, D) T is a 4-parameter vector, A, B, C, D are the four parameters of the equation, and (x, y) are the data points used to fit the circle; By minimizing all points {(x i ,y i )} solves the parameter vector by minimizing the following function, subject to the constraint G T NG=1, the formula is as follows: in, {(x i ,y i )} is the data point, n is the number of data points, then: Where X and M are data matrices, N is the constraint matrix, The solution G is the generalized eigenvector of the matrix pair (M, N); after the solution of the algebraic equation is obtained, the center and radius of the fitting circle are obtained by the conversion formula, which is: Where (a, b) is the center of the circle and R is the radius.
6. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 1 is characterized in that: The geometric fitting method is based on the standard equation of a circle, as follows: (x-a) 2 +(y-b) 2 =R 2 Where (a, b) is the center of the circle and R is the radius.
7. The circle positioning algorithm based on two-dimensional edge measurement and least squares principle according to claim 6 is characterized in that: It also includes increasing the robustness of the algorithm, specifically: By minimizing the objective function To solve the parameter h = (a, b, R), where It is the orthogonal distance from a single edge point to the target circle. The weight function includes Huber function and Tukey function, as shown below: Among them, k is the Choper factor.
