霍夫圓
- 目标
- 原理說明
- python接口說明
-
- Note重要提示
- Parameters名額說明
目标
use Hough Transform to find circles in an image
通過霍夫變換找到圖檔裡的圓們
原理說明
- A circle is represented mathematically as (x−xcenter)2+(y−ycenter)2=r2 where (xcenter,ycenter) is the center of the circle, and r is the radius of the circle. From equation, we can see we have 3 parameters, so we need a 3D accumulator for hough transform, which would be highly ineffective. So OpenCV uses more trickier method, Hough Gradient Method which uses the gradient information of edges.
- 一個圓的數學表現是(x−xcenter)2+(y−ycenter)2=r2, 其中Xcenter,Ycenter是圓的中心坐标,r是圓的半徑。通過這個問題,我們有三個參數,是以我們需要一個3D累加器來進行霍夫變換,這樣的情況大多是無效的。Opencv使用了更為巧妙的方法,霍夫梯度方法使用了邊緣的梯度資訊。
python接口說明
Note重要提示
Usually the function detects the centers of circles well. However, it may fail to find correct radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if you know it. Or, you may set maxRadius to a negative number to return centers only without radius search, and find the correct radius using an additional procedure.
通常使用這個方案來識别圓的圓心是比較好的。然而,它并不适合來找到正确的半徑。你可以通過制定若你已知的半徑範圍(最小半徑、最大半徑)來輔助這個方法。或者,你可設定最大半徑到一個負數來僅傳回中心并不進行半徑搜尋,進而使用附加的處理來找到正确的半徑。
Parameters名額說明
image 8-bit, single-channel, grayscale input image.
circles Output vector of found circles. Each vector is encoded as 3 or 4 element floating-point vector (x,y,radius) or (x,y,radius,votes) .
method Detection method, see HoughModes. Currently, the only implemented method is HOUGH_GRADIENT
dp Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height.
minDist Minimum distance between the centers of the detected circles. If the parameter is too small, multiple neighbor circles may be falsely detected in addition to a true one. If it is too large, some circles may be missed.
param1 First method-specific parameter. In case of HOUGH_GRADIENT , it is the higher threshold of the two passed to the Canny edge detector (the lower one is twice smaller).
param2 Second method-specific parameter. In case of HOUGH_GRADIENT , it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
minRadius Minimum circle radius.
maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns centers without finding the radius.