-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackbars.py
113 lines (98 loc) · 3.14 KB
/
trackbars.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import cv2
import numpy as np
import sys
import os
DIR = os.path.dirname(sys.argv[0])
def nothing(x):
pass
img = cv2.imread(DIR + '/07_hausdorf_metric/plikiHausdorff/Aegeansea.jpg')
cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', 600, 600)
# create trackbars for color change
cv2.createTrackbar('H_low', 'image', 0, 255, nothing)
cv2.createTrackbar('H_high', 'image', 0, 255, nothing)
cv2.createTrackbar('S_low', 'image', 0, 255, nothing)
cv2.createTrackbar('S_high', 'image', 0, 255, nothing)
cv2.createTrackbar('V_low', 'image', 0, 255, nothing)
cv2.createTrackbar('V_high', 'image', 0, 255, nothing)
cv2.setTrackbarPos('H_high', 'image', 255)
cv2.setTrackbarPos('S_high', 'image', 255)
cv2.setTrackbarPos('V_high', 'image', 255)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
while True:
# get current positions of four trackbars
h_low = cv2.getTrackbarPos('H_low', 'image')
s_low = cv2.getTrackbarPos('S_low', 'image')
v_low = cv2.getTrackbarPos('V_low', 'image')
h_high = cv2.getTrackbarPos('H_high', 'image')
s_high = cv2.getTrackbarPos('S_high', 'image')
v_high = cv2.getTrackbarPos('V_high', 'image')
lower = np.array([h_low, s_low, v_low])
upper = np.array([h_high, s_high, v_high])
mask = cv2.inRange(hsv, lower, upper)
cv2.imshow('image', mask)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
# import cv2
# import numpy as np
# import sys
# import os
#
# DIR = os.path.dirname(sys.argv[0])
#
# # from matplotlib import pyplot as plt
#
#
# def nothing(x):
# pass
#
#
# cv2.namedWindow('Colorbars')
#
# hh = 'Max'
# hl = 'Min'
# wnd = 'Colorbars'
#
# cv2.createTrackbar("Max", "Colorbars", 0, 255, nothing)
# cv2.createTrackbar("Min", "Colorbars", 0, 255, nothing)
#
# img = cv2.imread(DIR + '/07_hausdorf_metric/plikiHausdorff/Aegeansea.jpg')
# img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5)
#
# # titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
# # images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
#
# # for i in xrange(6):
# # plt.subplot(2,3,i+1),plt.imshow(images[i],'gray')
# # plt.title(titles[i])
# # plt.xticks([]),plt.yticks([])
#
# # plt.show()
#
# while True:
# hul = cv2.getTrackbarPos("Max", "Colorbars")
# huh = cv2.getTrackbarPos("Min", "Colorbars")
# h_low = cv2.getTrackbarPos('H_low', 'image')
# s_low = cv2.getTrackbarPos('S_low', 'image')
# v_low = cv2.getTrackbarPos('V_low', 'image')
#
# ret, thresh1 = cv2.threshold(img, hul, huh, cv2.THRESH_BINARY)
# ret, thresh2 = cv2.threshold(img, hul, huh, cv2.THRESH_BINARY_INV)
# ret, thresh3 = cv2.threshold(img, hul, huh, cv2.THRESH_TRUNC)
# ret, thresh4 = cv2.threshold(img, hul, huh, cv2.THRESH_TOZERO)
# ret, thresh5 = cv2.threshold(img, hul, huh, cv2.THRESH_TOZERO_INV)
# # cv2.imshow(wnd)
# cv2.imshow("thresh1", thresh1)
# cv2.imshow("thresh2", thresh2)
# cv2.imshow("thresh3", thresh3)
# cv2.imshow("thresh4", thresh4)
# cv2.imshow("thresh5", thresh5)
# k = cv2.waitKey(1) & 0xFF
# if k == ord('m'):
# mode = not mode
# elif k == 27:
# break
#
# cv2.destroyAllWindows()