forked from ahmetozlu/face_recognition_crop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_csv.py
45 lines (40 loc) · 1.11 KB
/
create_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
#----------------------------------------------
#--- Author : Ahmet Ozlu
#--- Mail : [email protected]
#--- Date : 21st September 2017
#----------------------------------------------
import sys
import os.path
import csv
# This is a tiny script to help you creating a CSV file from a face database with a similar hierarchie:
# .
# |-- README
# |-- s1
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# |-- s2
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
# ...
# |-- s40
# | |-- 1.pgm
# | |-- ...
# | |-- 10.pgm
#
def CreateCsv(csvLine):
BASE_PATH=csvLine
SEPARATOR=","
label = 0
with open("face_dataset.csv", "w") as file:
writer = csv.writer(file)
for dirname, dirnames, filenames in os.walk(BASE_PATH):
for subdirname in dirnames:
subject_path = os.path.join(dirname, subdirname)
for filename in os.listdir(subject_path):
abs_path = "%s/%s" % (subject_path, filename)
csv_line = "%s%s%d" % (abs_path, SEPARATOR, label)
print csv_line
writer.writerows([csv_line.split(',')])
label = label + 1