-
Notifications
You must be signed in to change notification settings - Fork 22
/
mask.py
65 lines (56 loc) · 2.02 KB
/
mask.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#############################################
# Universidad Tecnica Particular de Loja #
#############################################
# Professor: #
# Rodrigo Barba [email protected] #
#############################################
# Students: #
# Marcelo Bravo [email protected] #
# Galo Celly [email protected] #
# Nicholas Earley [email protected] #
#############################################
#!/bin/hbpython
#import libraries
import cv2
import numpy as np
#We define the mask
def mkmask(img, roi_corners):
mask = np.zeros(img.shape, dtype=np.uint8)
# roi_corners = np.array([[(10,10), (300,300), (10,300)]], dtype=np.int32)
white = (255, 255, 255)
cv2.fillPoly(mask, roi_corners, white)
return mask
#We define the mask
def mkmask(w, h, c, roi_corners):
mask = np.zeros((h, w, c), dtype=np.uint8)
# roi_corners = np.array([[(10,10), (300,300), (10,300)]], dtype=np.int32)
white = (255, 255, 255)
cv2.fillPoly(mask, roi_corners, white)
return mask
#We define the mask
def mkmask(w, h, roi_corners):
mask = np.zeros((h, w), dtype=np.uint8)
# roi_corners = np.array([[(10,10), (300,300), (10,300)]], dtype=np.int32)
white = (255, 255, 255)
cv2.fillPoly(mask, roi_corners, white)
return mask
def applymask(img, msk):
return cv2.bitwise_and(img, msk)
#we define the mask (video)
#for exit or continued the detecction, prees q
if __name__ == "__main__":
camera = cv2.VideoCapture(0)
(grabbed, frame) = camera.read()
if not grabbed:
exit(0)
msk = mkmask(frame, np.array([[(200, 100), (500, 100), (700, 300), (500, 700)]], dtype=np.int32))
while True:
(grabbed, frame) = camera.read()
if not grabbed:
exit(0)
cv2.imshow("Video - Original", frame)
mskd = applymask(frame, msk)
cv2.imshow("Video - Masked", mskd)
cv2.imshow("Mask", msk)
if cv2.waitKey(1) & 0xFF == ord("q"):
break