-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
39 lines (26 loc) · 848 Bytes
/
main.py
File metadata and controls
39 lines (26 loc) · 848 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
36
37
38
39
import numpy as np
import cv2 as cv
from PIL import Image
from util import get_limits
red = [0, 0, 255] # Red color in BGR colors
cap = cv.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Convert BGR Color to RSV color
hsvImage = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
lowerLimits, upperLimits = get_limits(color=red)
# Getting the mask of all the pixels that belongs to the color we want to detect
mask = cv.inRange(hsvImage, lowerLimits, upperLimits)
mask_ = Image.fromarray(mask)
bbox = mask_.getbbox()
print(bbox)
if bbox is not None:
x1, y1, x2, y2 = bbox
frame = cv.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 5)
cv.imshow('frame', frame)
if cv.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv.destroyAllWindows()