Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to create CSV file in windows (face recognition) ?

Hi, I am new to python and open CV. I have at & t database and want to create a CSV so that I can train and run the face recognition code "http://docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html"

I am using windows, my question is, how to run this below python script in windows / call this function and create a CSV file, as per the given guidelines " simply call create_csv.py with the path to the folder, just like this and you could save the output: philipp@mango:~/facerec/data$ python create_csv.py "

I am unable to do this in windows, please help. Thanks!!!


!/usr/bin/env python

import sys import os.path

This is a tiny script to help you creating a CSV file from a face

database with a similar hierarchie:

#

philipp@mango:~/facerec/data/at$ tree

.

|-- README

|-- s1

| |-- 1.pgm

| |-- ...

| |-- 10.pgm

|-- s2

| |-- 1.pgm

| |-- ...

| |-- 10.pgm

...

|-- s40

| |-- 1.pgm

| |-- ...

| |-- 10.pgm

#

if __name__ == "__main__":

if len(sys.argv) != 2:
    print "usage: create_csv <base_path>"
    sys.exit(1)

BASE_PATH=sys.argv[1]
SEPARATOR=";"

label = 0
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)
            print "%s%s%d" % (abs_path, SEPARATOR, label)
        label = label + 1