c4de778f9872f7022e51bfd5dd9f562ca664ed61
[platform/upstream/opencv.git] / modules / contrib / doc / facerec / src / create_csv.py
1 #!/usr/bin/env python
2
3 import sys
4 import os.path
5
6 # This is a tiny script to help you creating a CSV file from a face
7 # database with a similar hierarchie:
8 #
9 #  philipp@mango:~/facerec/data/at$ tree
10 #  .
11 #  |-- README
12 #  |-- s1
13 #  |   |-- 1.pgm
14 #  |   |-- ...
15 #  |   |-- 10.pgm
16 #  |-- s2
17 #  |   |-- 1.pgm
18 #  |   |-- ...
19 #  |   |-- 10.pgm
20 #  ...
21 #  |-- s40
22 #  |   |-- 1.pgm
23 #  |   |-- ...
24 #  |   |-- 10.pgm
25 #
26
27 if __name__ == "__main__":
28
29     if len(sys.argv) != 2:
30         print "usage: create_csv <base_path>"
31         sys.exit(1)
32
33     BASE_PATH=sys.argv[1]
34     SEPARATOR=";"
35
36     label = 0
37     for dirname, dirnames, filenames in os.walk(BASE_PATH):
38         for subdirname in dirnames:
39             subject_path = os.path.join(dirname, subdirname)
40             for filename in os.listdir(subject_path):
41                 abs_path = "%s/%s" % (subject_path, filename)
42                 print "%s%s%d" % (abs_path, SEPARATOR, label)
43             label = label + 1