-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircles.py
24 lines (22 loc) · 936 Bytes
/
circles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import cv2
"""Get Hough detected circles in frame
args: gray_frame - Grayscale frame
returns list of detected circles
"""
def get_circles(gray_frame):
return cv2.HoughCircles(gray_frame, cv2.HOUGH_GRADIENT, 1.3, 50, param2=95)
"""Draw circles on frame
args: circles_list - List of circles
img - Frame to draw on
"""
def draw_circles(circles_list, img):
if circles_list is not None:
# convert the (x, y) coordinates and radius of the circles to integers
circles_list = np.round(circles_list[0, :]).astype("int")
# loop over the (x, y) coordinates and radius of the circles
for (x, y, r) in circles_list:
# draw the circle in the output image, then draw a rectangle
# corresponding to the center of the circle
cv2.circle(img, (x, y), r, (0, 255, 0), 4)
cv2.rectangle(img, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)