-
Notifications
You must be signed in to change notification settings - Fork 11
/
convert_label_tool.py
58 lines (42 loc) · 1.62 KB
/
convert_label_tool.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
import cv2
import numpy as np
import glob
import os
def nothing(*arg):
pass
if __name__ == '__main__':
icol = (28, 0, 0, 56, 255, 255) # Green
cv2.namedWindow('colorTest')
# Lower range colour sliders.
cv2.createTrackbar('lowHue', 'colorTest', icol[0], 255, nothing)
cv2.createTrackbar('lowSat', 'colorTest', icol[1], 255, nothing)
cv2.createTrackbar('lowVal', 'colorTest', icol[2], 255, nothing)
# Higher range colour sliders.
cv2.createTrackbar('highHue', 'colorTest', icol[3], 255, nothing)
cv2.createTrackbar('highSat', 'colorTest', icol[4], 255, nothing)
cv2.createTrackbar('highVal', 'colorTest', icol[5], 255, nothing)
# img_name = "test.png"
srcImageName = glob.glob("./labelled_input/*.png")
for imgName in srcImageName:
lowHue = cv2.getTrackbarPos('lowHue', 'colorTest')
lowSat = cv2.getTrackbarPos('lowSat', 'colorTest')
lowVal = cv2.getTrackbarPos('lowVal', 'colorTest')
highHue = cv2.getTrackbarPos('highHue', 'colorTest')
highSat = cv2.getTrackbarPos('highSat', 'colorTest')
highVal = cv2.getTrackbarPos('highVal', 'colorTest')
frame = cv2.imread(imgName)
name = os.path.basename(imgName)
print(name)
frameHSV = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
colorLow = np.array([lowHue, lowSat, lowVal])
colorHigh = np.array([highHue, highSat, highVal])
mask = cv2.inRange(frameHSV, colorLow, colorHigh)
# Show the mask and the image
cv2.imshow('Threshoding', mask)
cv2.imshow('Input', frame)
# Write label
cv2.imwrite("./bw_label/" + name, mask)
k = cv2.waitKey(5) & 0XFF
if k == 27:
break
cv2.destroyAllWindows()