-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_balls.py
More file actions
26 lines (22 loc) · 925 Bytes
/
detect_balls.py
File metadata and controls
26 lines (22 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import cv2
import numpy as np
# params:
# frame - input grayscale image
# returns:
# circles - detected circles
def find_circles(img):
# smoothing
frame = cv2.GaussianBlur(img, (5, 5), 0)
# grayscale
#frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# circle detection
dp = 1 # inverse ratio of accumulator resolution to image resolution
min_dist = 30 # minimum distance between circle centers
edge_grad = 100 # gradient value for edge detection
acc_thresh = 20 # accumulator threshold (increase to get less circles)
min_r = 10 # minimum circle radius
max_r = 50 # maximum circle radius
circles = cv2.HoughCircles(frame, cv2.HOUGH_GRADIENT, dp, min_dist, param1=edge_grad, param2=acc_thresh, minRadius=min_r, maxRadius=max_r)
if circles is not None:
circles = np.uint16(np.around(circles))
return circles