-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball_detection.py
More file actions
33 lines (23 loc) · 863 Bytes
/
ball_detection.py
File metadata and controls
33 lines (23 loc) · 863 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
27
28
29
30
31
32
33
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
print('OpenCV',cv2.__version__)
while(1):
ret, frame = cap.read()
frame_blur = cv2.medianBlur(frame, 5)
frame_gray = cv2.cvtColor(frame_blur, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(frame_gray, cv2.HOUGH_GRADIENT, 1, 20,
param1=50, param2=30, minRadius=50, maxRadius=100)
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
# draw the outer circle
cv2.circle(frame, (i[0], i[1]), i[2], (0, 255, 0), 2)
# draw the center of the circle
cv2.circle(frame, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imshow('frame', frame)
cv2.imshow('frame_blur', frame_blur)
cv2.imshow('frame_gray', frame_gray)
if cv2.waitKey(0) & 0xff == ord('q'):
break
cap.release()
cv2.destroyAllWindows()