-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (54 loc) · 1.57 KB
/
main.py
File metadata and controls
75 lines (54 loc) · 1.57 KB
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
import cv2 as cv
import sys
import Slider as core
core.printVersion()
if (len(sys.argv) != 2):
print("Usage: python " + str(sys.argv[0]) + " <imgpath>")
sys.exit()
#cv.namedWindow("Thresholded", cv.WINDOW_NORMAL)
minHue = 0
maxHue = 255
slider = core.Slider(sys.argv[1])
def changeLower(num):
slider.setMin(minHue)
def changeUpper(num):
slider.setMax(maxHue)
cv.namedWindow("Threshold Controls", cv.WINDOW_NORMAL)
cv.createTrackbar("hueMin", "Threshold Controls", minHue, 255, changeLower)
cv.createTrackbar("hueMax", "Threshold Controls", maxHue, 255, changeUpper)
while True:
cv.imshow('image', slider.getImage())
cv.waitKey(1)
cv.destroyWindow('image')
'''
img = cv.imread(sys.argv[1])
img = cv.GaussianBlur(img, (3,3), 1, 1)
cvted = cv.cvtColor(img, cv.COLOR_BGR2HSV)
seperated = cv.split(cvted)
hue = seperated[0]
result = img
def thresh():
a, lower = cv.threshold(hue, minHue, 255, cv.THRESH_BINARY)
b, upper = cv.threshold(hue, maxHue, 255, cv.THRESH_BINARY_INV)
result = lower & upper
return result
#cv.imshow("Thresholded", result)
def changeLower(num):
minHue = num
print("Min Hue: " + str(minHue))
thresh()
def changeUpper(num):
maxHue = num
print("Max Hue: " + str(maxHue))
thresh()
cv.namedWindow("Threshold Controls", cv.WINDOW_NORMAL)
cv.createTrackbar("hueMin", "Threshold Controls", minHue, 255, changeLower)
cv.createTrackbar("hueMax", "Threshold Controls", maxHue, 255, changeUpper)
#cv.namedWindow("Thresholded", cv.WINDOW_NORMAL)
#thresh()
while True:
cv.imshow("Thresholded", result)
result = thresh()
cv.waitKey(1)
cv.waitKey(0)
'''