-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest2.py
43 lines (34 loc) · 1.36 KB
/
test2.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import cv2
import numpy as np
cap = cv2.VideoCapture(1)
lower_green = np.array([45,140,50])
upper_green = np.array([75,255,255])
lower_red = np.array([160,140,50])
upper_red = np.array([180,255,255])
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
foundred = False
while(True):
success,frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
hsv = cv2.medianBlur(hsv,5)
imgThreshHighred = cv2.inRange(hsv, lower_red, upper_red)
imgThreshHighgreen = cv2.inRange(hsv, lower_green, upper_green)
imgThreshHighblue = cv2.inRange(hsv, lower_blue, upper_blue)
circlesred = cv2.HoughCircles(imgThreshHighred,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
circlesblue = cv2.HoughCircles(imgThreshHighblue,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
circlesgreen = cv2.HoughCircles(imgThreshHighgreen,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)
if circlesred is not None:
print("found red")
# print circlesred
if circlesgreen is not None:
print ("found green")
# print circlesgreen
if circlesblue is not None:
print("found blue")
# print circlesblue
else:
print("no ball")
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()