Circle detection method in complex environment

By combining image preprocessing and contour detection with least squares fitting and three-point circle determination method, the robustness and computational resource requirements of circle detection in complex environments are solved, and fast and accurate circle detection is achieved.

CN120747148APending Publication Date: 2025-10-03TIANJIN UNIV OF TECH & EDUCATION (TEACHER DEV CENT OF CHINA VOCATIONAL TRAINING & GUIDANCE)
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510849233.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-24
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

Existing circle detection algorithms have low robustness and high computational resource requirements in complex environments, especially in weak light sources or noisy conditions, where the detection effect is poor and the computational complexity is high.

Method used

The image preprocessing, contour detection and circle recognition steps, including Gaussian blur, Canny edge detection, contour traversal, least squares fitting and three-point circle determination method, are adopted in combination with self-fitting processing to reduce the amount of calculation and improve the detection speed.

Benefits of technology

It achieves fast and accurate circle detection in weak light or noisy environments, reduces computing resource requirements, and improves detection speed and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120747148A_ABST
    Figure CN120747148A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of machine vision, and relates to a novel circle detection method in a complex environment. The method comprises the following steps: firstly, preprocessing an input color image, converting the color image into a grayscale image, then performing Gaussian blur processing, and applying a Canny edge detection algorithm to obtain an edge image; then, a findContours function of OpenCV is used for detecting a contour in the edge image, and traversal processing is carried out on the contour; secondly, circle detection is conducted on each contour through a findcircle () function, and circle fitting is conducted through a three-point circle determination method or a least square circle fitting method; performing accuracy verification on the fitted circle; and finally outputting the number and parameters of the identified circles, such as circle center coordinates and radiuses. The method is low in operand, can rapidly and accurately detect a circle in a complex environment with a weak light source and noise, does not need to occupy high computing resources, and has high detection speed and precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of machine vision, and in particular to a circle detection method in a complex environment. Background Art

[0002] Circle detection in images is a key technology in machine vision, pattern recognition, and artificial intelligence. Shape detection is a fundamental yet crucial research area in image processing and computer vision. Circle detection, as a prime example of specific shape detection, has garnered significant attention due to its wide range of applications and clear geometric characteristics. The research and development of circle detection algorithms has profoundly impacted numerous practical applications, particularly in autonomous driving, medical image analysis, industrial automation, and object recognition, where it plays a crucial role.

[0003] The existing circle detection algorithms mainly include:

[0004] (1) Hough Circle Transform

[0005] (2) Gradient-based Circle Detection

[0006] (3) RANSAC algorithm (Random Sample Consensus)

[0007] (4) Detection algorithm based on deep learning.

[0008] However, these algorithms all have obvious flaws. Among them, the Hough Circle Transform has high computational complexity, especially when processing large-size images, and the time cost is large; Gradient-based Circle Detection is sensitive to noise and easily interfered by incomplete edges or complex backgrounds; the RANSAC algorithm (Random Sample Consensus) requires multiple iterations to find the best fit, which is computationally intensive; deep learning-based detection algorithms require a large amount of labeled data for training, and the inference process may require high computing resources. Summary of the Invention

[0009] This invention addresses the shortcomings of existing circle detection algorithms, which suffer from low robustness (traditional detection algorithms) and high computational resource requirements (deep learning), by creating a novel, fast circle detection algorithm for complex environments. This algorithm allows detection even in weak light conditions and in the presence of noise; it also improves detection speed without requiring high computational resources.

[0010] The technical solution adopted by the present invention to solve the technical problem is:

[0011] The present invention provides a circle detection method in a complex environment, comprising the following steps:

[0012] Step 1: Image preprocessing, including converting the input color image into a grayscale image, performing Gaussian blur processing on the grayscale image, and applying the Canny edge detection algorithm to obtain an edge image;

[0013] Step 2: Contour detection, using OpenCV's findContours function to detect contours on the edge image and traverse the detected contours;

[0014] Step 3: Circle recognition, use the find_circle() function to detect circles for each contour, including:

[0015] Get the edge points of the contour and filter them according to the number of edge points. If the number of edge points exceeds the set threshold, perform circle fitting.

[0016] Perform circle fitting using one of two methods:

[0017] Three-point circle determination method: select three specific non-collinear points on the contour and calculate the center and radius of the circle;

[0018] Least squares circle fitting method: perform least squares fitting on all points in the contour, solve the circle model with the smallest fitting error, and obtain the center and radius of the circle;

[0019] Step 4: Verify accuracy, including:

[0020] Select other points on the contour, calculate their distance to the center of the fitted circle, and compare it with the fitted radius to check whether the circular condition is met;

[0021] Calculate the residuals of all contour points, and calculate the mean and variance of the residuals. If the residual mean is less than the set threshold, it is determined to be a valid circle, otherwise it is eliminated;

[0022] Check whether the radius of the fitted circle is within the preset range to exclude non-target circles;

[0023] Step 5: Self-fitting: For the case where the circular contour is incomplete due to the influence of ambient light, self-fitting is performed. For the case where the same circular contour is broken, the center of each circle is calculated and repeated detection is eliminated by comparing the distance between the center of the circle;

[0024] Step 6: Return the result and output the number of recognized circles and their parameters, including the center coordinates and radius.

[0025] Furthermore, in step 3, a three-point circle determination method is used to perform circle fitting, including:

[0026] Suppose there are three non-collinear points A(x1,y1), B(x2,y2), and C(x3,y3) on the plane;

[0027] Set up the system of equations:

[0028] (x1-h) 2 +(y1-k) 2 =r 2

[0029] (x2-h) 2 +(y2-k) 2 =r 2

[0030] (x3-h) 2 +(y3-k) 2 =r 2

[0031] Elimination radius r 2 , we get the linear equations:

[0032] h(x1-x2)+k(y1-y2)=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2

[0033] h(x2-x3)+k(y2-y3)=(x2 2 -x3 2 +y2 3 -y3 2 ) / 2

[0034] Define a new variable:

[0035] a=x1-x2;

[0036] b = y1 - y2;

[0037] c = x1 - x3;

[0038] d = y1 - y3;

[0039] e=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2;

[0040] f=(x1 2 -x3 2 +y1 2 -y3 2) / 2;

[0041] Solve the linear equations to get the coordinates of the circle center and radius:

[0042] x=(b*fd*e) / (b*ca*d)

[0043] y=(c*ea*f) / (b*ca*d)

[0044] R=(x–x1) 2 +(y–y1) 2 .

[0045] Furthermore, in step 3, a least squares circle fitting method is used to perform circle fitting, including:

[0046] Suppose N edge points (x i ,y i ),i=1,2,...,N;

[0047] Construct the equation of a circle: (x i -h) 2 +(y i -k) 2 =r 2 ;

[0048] Expand it into linear form: i 2 +y i 2 =2hx i +2ky i +(r 2 -h 2 -k 2 );

[0049] make:

[0050] Zi=xi 2 +yi 2

[0051] A=[xi,yi,1]

[0052] θ=[2h,2k,r 2 -h 2 -k 2 ]T

[0053] Solve a linear least-squares problem:

[0054] After solving for θ, we get the coordinates of the circle center and radius:

[0055] h=θ1 / 2

[0056] k=θ2 / 2

[0057]

[0058] Furthermore, the Gaussian blur processing in step 1 has a kernel size of (9×9) and a standard deviation in the X direction of 2, so as to effectively smooth the image and reduce the interference of noise on subsequent edge detection.

[0059] Furthermore, when the Canny edge detection algorithm is applied in step 1, its low threshold and high threshold are 100 and 200 respectively to ensure the accuracy and completeness of edge detection.

[0060] Furthermore, in step 3, when the three-point circle determination method is used for circle fitting, the three specific points selected are three points in the fifth equal division point on the contour to ensure the representativeness of the selected points and improve the accuracy of fitting.

[0061] Furthermore, in step 3, when least squares circle fitting is used for circle fitting, the contour points are first normalized before least squares fitting is performed on all points in the contour to eliminate the influence of different contour sizes on the fitting result and improve the robustness of the fitting.

[0062] Furthermore, in step 4, when verifying the accuracy, the threshold of the residual mean is set to 0.1 to ensure that the screened circles have high accuracy.

[0063] Furthermore, in step 5, for the case where the same circle contour is broken, when the distance between the two circle centers is less than a set threshold (such as 0.1 times the circle radius), it is determined to be a repeated detection and is excluded to avoid repeated counting.

[0064] Furthermore, the algorithm also has real-time optimization, by adopting multi-threading to process the image preprocessing task in step 1, and parallel processing of contour detection, circle recognition, verification accuracy and self-fitting operations in steps 2 to 5, so as to improve the real-time detection performance of the algorithm in complex environments.

[0065] The advantages and positive effects of the present invention are:

[0066] (1) The present invention solves the problem that the traditional Hough transform is greatly affected by ambient light, and can predict and fit the circle in weak light conditions.

[0067] (2) The algorithm of the present invention has low computational complexity, which reduces the developer's demand for hardware and improves the detection speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 The figure is a flow chart of the present invention applied to ball measurement.

[0069] Figure 2 This is the contour extraction and preprocessing flow chart of the present invention.

[0070] Figure 3 Flowchart of the core algorithm for high-speed circle measurement

[0071] Figure 4 This is the flow chart of the core algorithm for high-precision circle measurement.

[0072] Figure 5 This is a comparative experimental diagram of circle extraction obtained by and without the algorithm of the present invention.

[0073] Figure 6 The present invention is applied to a circular measurement area. DETAILED DESCRIPTION

[0074] The present invention will be further described in detail below through specific examples. The following examples are only illustrative and not restrictive, and the scope of protection of the present invention cannot be limited thereto.

[0075] The present invention provides a circle detection method in a complex environment, comprising the following steps:

[0076] Step 1: Image preprocessing: First, convert the input color image into a grayscale image to reduce the amount of calculation and facilitate subsequent processing. Secondly, perform Gaussian blur processing on the grayscale image to smooth the image and reduce noise. Finally, apply the Canny edge detection algorithm and adjust the Canny threshold (threshold1, threshold2) according to needs. Detect edges on the blurred image to obtain an edge image.

[0077] Step 2: Contour detection: Use OpenCV's findContours function ( to detect contours on the edge image, traverse the detected contours, and further process each contour.

[0078] Step 3: Circle detection: Use the find_circle() function to detect circles. For each contour, first obtain its edge points and filter them based on the number of edge points. If the number of edge points exceeds the set threshold (edge_length), a circle fitting is performed.

[0079] There are two methods for circle fitting

[0080] 1) Three-point circle determination method (high-speed circle determination): By selecting specific points on the contour (such as three points in the fifth division), the center and radius of the circle are calculated.

[0081] 2) Least squares circle fitting method (high-precision circle fitting): Perform least squares fitting on all points in the contour and improve accuracy by solving the circle model with the smallest fitting error.

[0082] Step 4: Verify the accuracy: To verify the accuracy of the fitted circle, select other points on the contour (such as the point near the starting point and the middle point), calculate their distance to the center of the fitted circle, and compare them with the fitted radius to check whether the circular condition is met. For the fitted circle, the accuracy is confirmed by verifying whether other points on the contour meet the circular geometric constraints (the distance from the point to the center is close to the radius); calculate the residuals of all contour points Calculate the mean and variance; if the residual mean is less than the set threshold, it is determined to be a valid circle, otherwise it is eliminated; at the same time, check whether the radius of the fitted circle is within the preset interval [min_R, max_R] to exclude non-target circles.

[0083] Step 5: Self-fitting: Self-fitting is performed for circular contours that are not fully affected by ambient light. For the same circular contour breaks, the center of each circle is calculated and repeated detection is performed by comparing the center distance to eliminate duplicates.

[0084] Step 6 returns the result: output the number of circles recognized and their parameters (center coordinates and radius)

[0085] The three-point circle determination method is specifically as follows:

[0086] Assume that there are three non-collinear points A(x1,y1), B(x2,y2), and C(x3,y3) on a plane. These points can be used to determine a circle with center (h,k) and radius r. Its equation is: (xh) 2 +(yk) 2 =r 2

[0087] 1. Establish a system of equations:

[0088] The equation of the circle requires that the three points A, B, and C are all on the circle, so substituting them into the equation of the circle, we get three equations:

[0089] (x1-h) 2 +(y1-k) 2 =r 2

[0090] (x2-h) 2 +(y2-k) 2 =r 2

[0091] (x3-h) 2 +(y3-k) 2 =r 2

[0092] 2. Eliminate the radius r 2 The following linear equations are obtained:

[0093] h(x1-x2)+k(y1-y2)=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2

[0094] h(x2-x3)+k(y2-y3)=(x2 2 -x3 2 +y2 3 -y3 2 ) / 2

[0095] To simplify further, define new variables:

[0096] a=x1-x2;

[0097] b = y1 - y2;

[0098] c = x1 - x3;

[0099] d = y1 - y3;

[0100] e=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2;

[0101] f=(x1 2 -x3 2 +y1 2 -y3 2 ) / 2;

[0102] 3. Solve the system of equations:

[0103] By solving these two linear equations, we can obtain .

[0104] Center of circle:

[0105] x=(b*fd*e) / (b*ca*d)

[0106] y=(c*ea*f) / (b*ca*d)

[0107] radius:

[0108] R=(x–x1) 2 +(y–y1) 2

[0109] 4. Substitution verification

[0110] The least squares circle fitting method is specifically:

[0111] In order to improve the accuracy and robustness of circle fitting, especially under the conditions of uneven distribution, noisy or incomplete edge points, the present invention further introduces a circle fitting method based on least squares to fit the contour points as a whole, minimize the geometric error from point to circle, and thus obtain the global optimal circle center and radius.

[0112] Suppose N edge points (x i ,y i ), i = 1, 2, ..., N, the goal is to find the center (h, k) and radius r so that these points satisfy the circle equation as much as possible:

[0113] (x i -h) 2 +(y i -k) 2 =r 2

[0114] Expand it into linear form:

[0115] x i 2 +y i 2 =2hx i +2ky i +(r 2 -h 2 -k 2 )

[0116] make:

[0117] Zi=xi 2 +yi 2

[0118] A=[xi,yi,1]

[0119] θ=[2h,2k,r 2 -h 2 -k 2 ]T

[0120] The objective is transformed into a linear least squares problem:

[0121]

[0122] After solving for θ, we can find the coordinates of the center and radius of the circle:

[0123] h=θ1 / 2

[0124] k=θ2 / 2

[0125]

[0126] 4. Substitution verification

[0127] Press the ball Figure 1 The detection steps were performed and the measurement data were shown in Table 1, Table 2, Table 3 and Table 4. As can be seen from the table, the detection rate of the algorithm of the present invention was maintained at 100% in the experimental environment, the detection error was basically within 0.28, and the average error was less than 0.2.

[0128] Table 1 Figure 5 (A, B) Experiment

[0129]

[0130] Table 2 Figure 5 (C, D) Experiment

[0131]

[0132] Table 3 Figure 5 (E, F) Experiment

[0133]

[0134]

[0135] Table 4 Figure 5 (G, J) Experiment

[0136]

[0137] from Figure 5 The experimental results can be used to draw the following analysis:

[0138] Note that threshold1 and threshold2 are the Canny thresholds 1 and 2 in step 1 above.

[0139] (A, B) When threshold1 is set to 120 and threshold2 is set to 150, the extracted circular contour is in a three-segment split state due to the influence of ambient light. Experimental results show that the algorithm of the present invention can quickly detect circles and eliminate duplicated circles. However, the traditional Hough transform cannot detect circles due to the broken contours.

[0140] (C, D) When threshold1 is set to 70 and threshold2 is set to 110, the circular contour extracted is in a severely incomplete state due to the influence of ambient light. At this time, the present invention can use the existing contour to complete the circle, while the traditional Hough transform does not have the function of fitting the circle and therefore cannot detect the circle.

[0141] (E, F) When threshold1 is set to 50 and threshold2 is set to 110, the extracted circular contour is severely incomplete due to the influence of ambient light and external occlusion interference. At this time, the present invention can eliminate interference and accurately find the circle, while the traditional Hough transform cannot detect the circle.

[0142] (G, J) When threshold1 is set to 80 and threshold2 is set to 110, when multiple spheres appear, the Hough transform cannot detect all the circles because the shadows of the spheres block each other, while the algorithm of the present invention can detect them quickly and accurately.

[0143] The above description is only a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several modifications and improvements without departing from the inventive concept, and these all fall within the scope of protection of the present invention.

Claims

1. A circle detection method in a complex environment, characterized in that: The following steps are involved: Step 1: Image preprocessing, including converting the input color image into a grayscale image, performing Gaussian blur processing on the grayscale image, and applying the Canny edge detection algorithm to obtain an edge image; Step 2: Contour detection, using OpenCV's findContours function to detect contours on the edge image and traverse the detected contours; Step 3: Circle recognition, use the find_circle() function to detect circles for each contour, including: Get the edge points of the contour and filter them according to the number of edge points. If the number of edge points exceeds the set threshold, perform circle fitting. Perform circle fitting using one of two methods: Three-point circle determination method: select three specific non-collinear points on the contour and calculate the center and radius of the circle; Least squares circle fitting method: perform least squares fitting on all points in the contour, solve the circle model with the smallest fitting error, and obtain the center and radius of the circle; Step 4: Verify accuracy, including: Select other points on the contour, calculate their distance to the center of the fitted circle, and compare it with the fitted radius to check whether the circular condition is met; Calculate the residuals of all contour points, and calculate the mean and variance of the residuals. If the residual mean is less than the set threshold, it is determined to be a valid circle, otherwise it is eliminated; Check whether the radius of the fitted circle is within the preset range to exclude non-target circles; Step 5: Self-fitting: For the case where the circular contour is incomplete due to the influence of ambient light, self-fitting is performed. For the case where the same circular contour is broken, the center of each circle is calculated and repeated detection is eliminated by comparing the distance between the center of the circle; Step 6: Return the result and output the number of recognized circles and their parameters, including the center coordinates and radius.

2. The circle detection method in a complex environment according to claim 1, characterized in that: In step 3, a three-point circle determination method is used to perform circle fitting, including: Suppose there are three non-collinear points A(x1,y1), B(x2,y2), and C(x3,y3) on the plane; Set up the system of equations: (x1-h) 2 +(y1-k) 2 =r 2 (x2-h) 2 +(y2-k) 2 =r 2 (x3-h) 2 +(y3-k) 2 =r 2 Elimination radius r 2 , we get the linear equations: h(x1-x2)+k(y1-y2)=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2 <h2 style=";text-align:left;direction:ltr">h(x2-x3)+k(y2-y3)=(x2<h2 style=";text-align:left;direction:ltr"> 2 <h2 style=";text-align:left;direction:ltr"> -x3<h2 style=";text-align:left;direction:ltr"> 2 <h2 style=";text-align:left;direction:ltr"> +y2<h2 style=";text-align:left;direction:ltr"> 3 <h2 style=";text-align:left;direction:ltr"> -y3<h2 style=";text-align:left;direction:ltr"> 2 <h2 style=";text-align:left;direction:ltr"> ) / 2 Define a new variable: a=x1-x2; b = y1 - y2; c = x1 - x3; d = y1 - y3; e=(x1 2 -x2 2 +y1 2 -y2 2 ) / 2; f=(x1 2 -x3 2 +y1 2 -y3 2 ) / 2; Solve the linear equations to get the coordinates of the circle center and radius: x=(b*fd*e) / (b*ca*d) y=(c*ea*f) / (b*ca*d) R=(x–x1) 2 +(y–y1) 2 。 3. The circle detection method in a complex environment according to claim 1, characterized in that: In step 3, the least squares circle fitting method is used to perform circle fitting, including: Suppose N edge points (x i ,y i ),i=1,2,...,N; Construct the equation of a circle: (x i -h) 2 +(y i -k) 2 =r 2 ; Expand it into linear form: i 2 +y i 2 =2hx i +2ky i +(r 2 -h 2 -k 2 ); make: Zi=xi 2 +yi 2 A=[xi,yi,1] θ=[2h,2k,r 2 -h 2 -k 2 ]T Solve a linear least-squares problem: After solving for θ, we get the coordinates of the circle center and radius: h=θ1 / 2 k=θ2 / 2 4. The circle detection method in a complex environment according to claim 1, characterized in that: The Gaussian blur processing in step 1 has a kernel size of 9×9 and a standard deviation of 2 in the X direction, so as to effectively smooth the image and reduce the interference of noise on subsequent edge detection.

5. The circle detection method in a complex environment according to claim 1, characterized in that: When the Canny edge detection algorithm is applied in step 1, the low threshold and the high threshold are 100 and 200 respectively to ensure the accuracy and completeness of the edge detection.

6. The circle detection method in a complex environment according to claim 1, characterized in that: In step 3, when the three-point circle determination method is used to perform circle fitting, the three specific points selected are three points in the fifth equal division point on the contour to ensure the representativeness of the selected points and improve the accuracy of fitting.

7. The circle detection method in a complex environment according to claim 1, characterized in that: In step 3, when the least squares circle fitting method is used for circle fitting, the contour points are first normalized before the least squares fitting is performed on all points in the contour to eliminate the influence of different contour sizes on the fitting result and improve the robustness of the fitting.

8. The circle detection method in a complex environment according to claim 1, characterized in that: In step 4, when verifying the accuracy, the threshold of the residual mean is set to 0.1 to ensure that the screened circles have high accuracy.

9. The circle detection method in a complex environment according to claim 1, characterized in that: In step 5, for the case where the same circle contour is broken, when the distance between the two circle centers is less than a set threshold, it is determined to be a repeated detection and is excluded to avoid repeated counting.

10. The circle detection method in a complex environment according to claim 1, characterized in that: The algorithm also features real-time optimization by using multithreading to process image preprocessing tasks in step 1, and parallel processing of contour detection, circle recognition, verification accuracy, and self-fitting in steps 2 to 5, to improve the algorithm's real-time detection performance in complex environments.

Citation Information

Cited By

  • Target displacement measurement method based on machine vision

    CN121829330A

  • Visual detection method and system for printing defects and number of circular self-adhesive labels

    CN122115489A