-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_data_csv.py
45 lines (34 loc) · 1.14 KB
/
create_data_csv.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
import glob
import csv
row_data = [
['left_eye_img', 'x_coord']
]
def get_id(file):
if 'cursor' in file:
return file.split('-')[1]
else:
return file.split('-')[0].split('/')[1]
def get_x_value_cursor(file):
return int(file.split('-')[2])
def get_y_value_cursor(file):
return int(file.split('-')[3].replace('.txt', ''))
data_temp = {}
for filepath in glob.iglob('data-3700/*.*'):
if 'head' not in filepath:
if '-1.jpg' not in filepath:
id = get_id(filepath)
if 'cursor' in filepath:
filepath = get_x_value_cursor(filepath)
else:
filepath = filepath.replace('data-3700/', '')
if id not in data_temp:
data_temp[id] = [filepath]
else:
data_temp[id].append(filepath)
for x, y in data_temp.items():
x_coord_value = y[0] if isinstance(y[0], int) else y[1]
left_eye_img = y[1] if isinstance(y[0], int) else y[0]
row_data.append([left_eye_img, x_coord_value])
with open('dataset-3700.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(row_data)