OpenCV霍夫圆检测原理

Here I’ll tell you how to detect circles (which are quite important in computer vision application) using a technique similar to the standard Hough transform. This article assumes you know how the Hough transform works, or you’ve understood the previous articles in this series (The Hough Transform).
The parameterization
A circle can be described completely with three pieces of information: the center (a, b) and the radius. (The center consists of two parts, hence a total of three)
x = a + Rcosθ
y = b + Rsinθ
When the θ varies from 0 to 360, a complete circle of radius R is generated.
So with the Circle Hough Transform, we expect to find triplets of (x, y, R) that are highly probably circles in the image. That is, we want to find three parameters. Thus, the parameter space is 3D… meaning things can get ugly if you don’t tread slowly. Out of memory errors are common even if your programming language uses virtual memory.
So we’ll start simple.
Assuming R is known
To begin, we’ll start with the assumption that you’re looking for circles of a particular radius, that is, R is known. The equation of each circle is:
x = a + Rcosθ
y = b + Rsinθ
So, every point in the xy space will be equivalent to a circle in the ab space (R isn’t a parameter, we already know it). This is because on rearranging the equations, we get:
a = x1 – Rcosθ
b = y1 – Rsinθ
for a particular point (x1, y1). And θ sweeps from 0 to 360 degrees.
So, the flow of events is something like this:
Load an image
Detect edges and generate a binary image
For every ‘edge’ pixel, generate a circle in the ab space
For every point on the circle in the ab space, cast ‘votes’ in the accumulator cells
The cells with greater number of votes are the centers
When R is not known
When the radius is not known, the simplest solution is to just guess. Assume R = 1, and then run the same algorithm. Then assume R = 2, and run it again. Assume R = 3…. and so on.
Whats the upper limit of R? A safe limit would be the length of the diagonal of the image. No possible circle on the image can have a radius greater than or equal to the diagonal.

猜你喜欢

转载自blog.csdn.net/qq_35759050/article/details/71158200