4
This example illustrates how to use cv2.HoughCircles() function.
7
houghcircles.py [<image_name>]
8
image argument defaults to ../data/board.jpg
11
# Python 2/3 compatibility
12
from __future__ import print_function
18
if __name__ == '__main__':
24
fn = "../data/board.jpg"
26
src = cv2.imread(fn, 1)
27
img = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
28
img = cv2.medianBlur(img, 5)
29
cimg = src.copy() # numpy function
31
circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1, 10, np.array([]), 100, 30, 1, 30)
32
a, b, c = circles.shape
34
cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), circles[0][i][2], (0, 0, 255), 3, cv2.LINE_AA)
35
cv2.circle(cimg, (circles[0][i][0], circles[0][i][1]), 2, (0, 255, 0), 3, cv2.LINE_AA) # draw center of circle
37
cv2.imshow("source", src)
38
cv2.imshow("detected circles", cimg)