-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_filter.py
55 lines (39 loc) · 1.64 KB
/
set_filter.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
import cv2
import numpy as np
import imutils
if __name__ == "__main__":
def nothing(*arg):
pass
cv2.namedWindow("result") # главное окно
cv2.namedWindow("settings") # окно настроек
# создаем 6 бегунков для настроек параметров HLS
cv2.createTrackbar("h1", "settings", 0, 255, nothing)
cv2.createTrackbar("s1", "settings", 0, 255, nothing)
cv2.createTrackbar("v1", "settings", 0, 255, nothing)
cv2.createTrackbar("h2", "settings", 255, 255, nothing)
cv2.createTrackbar("s2", "settings", 255, 255, nothing)
cv2.createTrackbar("v2", "settings", 255, 255, nothing)
crange = [0,0,0,0,0,0]
while True:
img = cv2.imread(r"C:\CREESTL\Programming\PythonCoding\semestr_3\green.jpg")
img = imutils.resize(img, width = 800)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# считываем значения бегунков
h1 = cv2.getTrackbarPos("h1", "settings")
s1 = cv2.getTrackbarPos("s1", "settings")
v1 = cv2.getTrackbarPos("v1", "settings")
h2 = cv2.getTrackbarPos("h2", "settings")
s2 = cv2.getTrackbarPos("s2", "settings")
v2 = cv2.getTrackbarPos("v2", "settings")
# формируем начальный и конечный цвет фильтра
h_min = np.array((h1, s1, v1), np.uint8)
#h_min = np.uint8([h1, s1, v1])
h_max = np.array((h2, s2, v2), np.uint8)
#h_max = np.uint8([h2, s2, v2])
# накладываем фильтр на кадр в модели HSV
thresh = cv2.inRange(hsv, h_min, h_max)
cv2.imshow("result", thresh)
ch = cv2.waitKey(5)
if ch == ord("q"):
break
cv2.destroyAllWindows()