-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (20 loc) · 616 Bytes
/
Copy pathmain.py
File metadata and controls
30 lines (20 loc) · 616 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
import cv2
from PIL import Image
from util import get_limits
green = [0, 255, 0]
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
hsvImage=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lowerLimit, upperLimit = get_limits(color=green)
mask = cv2.inRange(hsvImage, lowerLimit, upperLimit)
mask_= Image.fromarray(mask)
bbox=mask_.getbbox()
if bbox is not None:
x1, y1, x2, y2 = bbox
cv2.rectangle(frame, (x1,y1), (x2,y2),(0,255,0),5)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()