create_csv.py 955 B

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