-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_test2.py
More file actions
36 lines (27 loc) · 785 Bytes
/
function_test2.py
File metadata and controls
36 lines (27 loc) · 785 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
34
35
import cv2
import numpy as np
cap = cv2.VideoCapture(1)
while(1):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray,(5,5),0)
gray = cv2.medianBlur(gray, 5)
rows = gray.shape[0]
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, rows/8,
param1=100, param2=20, minRadius=10, maxRadius=40)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
center = (i[0], i[1])
# circle center
cv2.circle(frame, center, 1, (0, 100, 100), 3)
# circle outline
radius = i[2]
cv2.circle(frame, center, radius, (255, 0, 255), 3)
print(circles)
cv2.imshow("detected circles", frame)
k = cv2.waitKey(5)
if k==27:
break
cap.release()
cv2.destroyAllWindows()