-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsv.py
46 lines (30 loc) · 1.01 KB
/
hsv.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
import cv2 as cv
import numpy as np
def nothing(x):
pass
cap = cv.VideoCapture(0)
cv.namedWindow('cam')
cv.createTrackbar('l_h','cam',0,255,nothing)
cv.createTrackbar('l_s','cam',0,255,nothing)
cv.createTrackbar('l_v','cam',0,255,nothing)
cv.createTrackbar('u_h','cam',0,179,nothing)
cv.createTrackbar('u_s','cam',0,255,nothing)
cv.createTrackbar('u_v','cam',0,255,nothing)
while (cap.isOpened()):
flag,frame =cap.read()
frame1=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(frame1,lb,ub)
res = cv.bitwise_and(frame, frame, mask=mask)
cv.imshow('cam',res)
if cv.waitKey(1) & 0xFF == ord('q') :
break
cap.release()
cv.destroyAllWindows()