-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimg_classifier.py
More file actions
89 lines (61 loc) · 1.95 KB
/
Copy pathimg_classifier.py
File metadata and controls
89 lines (61 loc) · 1.95 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import cv2 # Import the OpenCV library
import pandas as pd # Import Pandas library
import sys # Enables the passing of arguments
""" A tool to manually classify situations
Use auto_plot to generate images before running this script
Requirements:
- OpenCV (used in conjunction with conda and python 3.6.13) """
overwrite = False
try:
csv_file = sys.argv[1]
except:
csv_file = 'rstudio.csv'
print("Assuming name of file: ", csv_file)
df = pd.read_csv(csv_file, sep=';')
print(df)
if 'img_class' not in df:
df['img_class'] = ""
list_of_files = df.img_name.to_list()
img_class = df.img_class.to_list()
print(list_of_files)
IMAGE_NAME = list_of_files[0]
print("Controls \nt: True \nf: False \nu: Undo previous classification \nq: quit and save \nesc:quit without saving")
for i, INPUT_IMAGE in enumerate(list_of_files):
if pd.isnull(INPUT_IMAGE):
continue
print("Nr:", i, " ", INPUT_IMAGE, str(img_class[i]))
if str(img_class[i]) != 'nan' and not overwrite:
continue
image = cv2.imread(INPUT_IMAGE, -1)
quit_viewing = False
img_done = False
while True:
# Show image 'Image mouse':
cv2.imshow("Case", image)
# Continue until 'q' is pressed:
k = cv2.waitKey(0)
if k == 27: # esc
exit()
if k == ord('q'):
quit_viewing = True
img_done = True
if k == ord('t'):
img_class[i] = 'True'
img_done = True
if k == ord('f'):
img_class[i] = 'False'
img_done = True
if k == ord('u') and i > 0:
img_class[i-1] = 'nan'
print("Undid:", list_of_files[i-1], " restart to re-classify")
if img_done:
cv2.destroyAllWindows()
break
if quit_viewing:
cv2.destroyAllWindows()
break
cv2.destroyAllWindows()
df['img_class'] = img_class
print(df)
df.to_csv(csv_file, index=None, sep=';')
exit()