-
Notifications
You must be signed in to change notification settings - Fork 0
/
lol.py
41 lines (32 loc) · 1.11 KB
/
lol.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
import cv2 as cv
import numpy as np
def nothing(x):
pass
cap = cv.VideoCapture(0)
cap.set(3, 500)
cap.set(4, 500)
cv.namedWindow('cam')
cv.createTrackbar('l_h', 'cam', 0, 179, nothing) # Hue range is 0-179
cv.createTrackbar('l_s', 'cam', 0, 255, nothing)
cv.createTrackbar('l_v', 'cam', 0, 255, nothing)
cv.createTrackbar('u_h', 'cam', 179, 179, nothing)
cv.createTrackbar('u_s', 'cam', 255, 255, nothing)
cv.createTrackbar('u_v', 'cam', 255, 255, nothing)
while True:
ret, frame = cap.read()
frame_hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
lh = cv.getTrackbarPos('l_h', 'cam')
ls = cv.getTrackbarPos('l_s', 'cam')
lv = cv.getTrackbarPos('l_v', 'cam')
uh = cv.getTrackbarPos('u_h', 'cam')
us = cv.getTrackbarPos('u_s', 'cam')
uv = cv.getTrackbarPos('u_v', 'cam')
lb = np.array([lh, ls, lv])
ub = np.array([uh, us, uv])
mask = cv.inRange(frame_hsv, lb, ub)
res = cv.bitwise_and(frame, frame, mask=mask)
cv.imshow('cam', res)
if cv.waitKey(1) & 0xFF == ord('q'): # Exit the loop when 'q' is pressed
break
cap.release()
cv.destroyAllWindows()