-
Notifications
You must be signed in to change notification settings - Fork 0
/
CriarTrackbar BGR.py
48 lines (33 loc) · 1.22 KB
/
CriarTrackbar BGR.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
import cv2
import numpy as np
def nothing(x):
pass
#cap = cv2.VideoCapture('imagens/carros.mp4');
cv2.namedWindow("Tracking")
cv2.createTrackbar("LB", "Tracking", 0, 255, nothing)
cv2.createTrackbar("LG", "Tracking", 0, 255, nothing)
cv2.createTrackbar("LR", "Tracking", 0, 255, nothing)
cv2.createTrackbar("UB", "Tracking", 255, 255, nothing)
cv2.createTrackbar("UG", "Tracking", 255, 255, nothing)
cv2.createTrackbar("UR", "Tracking", 255, 255, nothing)
while True:
frame = cv2.imread('imagens/Carros.jpg')
#_, frame = cap.read()
l_h = cv2.getTrackbarPos("LB", "Tracking")
l_s = cv2.getTrackbarPos("LG", "Tracking")
l_v = cv2.getTrackbarPos("LR", "Tracking")
u_h = cv2.getTrackbarPos("UB", "Tracking")
u_s = cv2.getTrackbarPos("UG", "Tracking")
u_v = cv2.getTrackbarPos("UR", "Tracking")
l_b = np.array([l_h, l_s, l_v])
u_b = np.array([u_h, u_s, u_v])
mask = cv2.inRange(frame, l_b, u_b)
res = cv2.bitwise_and(frame, frame, mask=mask)
cv2.imshow("frame", frame)
cv2.imshow("mask", mask)
cv2.imshow("res", res)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()