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

asked 2014-03-01 02:59:02 -0600

ema gravatar image

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: [email protected]:~/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:

#

[email protected]:~/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
edit retag flag offensive close merge delete

Comments

so, how did you call it and what went wrong ?

berak gravatar imageberak ( 2014-03-01 03:07:00 -0600 )edit

i have python 2.7 installed in the system, when I run this script I get

>>> ================================ RESTART ================================ >>> usage: create_csv <base_path> >>>

and then program terminates.

ema gravatar imageema ( 2014-03-01 03:18:32 -0600 )edit
1

if your att faces are in d:/ema/att, you'd call it like this:

python create_csv.py d:/ema/att

(well, this will print the filenames/labels to console output, so you want to redirect that into a textfile:)

python create_csv.py d:/ema/att > att_faces.csv

berak gravatar imageberak ( 2014-03-01 03:24:41 -0600 )edit

Where should I insert this command " python create_csv.py d:/ema/att " in the GUI of the python or in windows command line(cmd.exe) ?

ema gravatar imageema ( 2014-03-01 03:27:17 -0600 )edit
1

ah, try from cmdline first

berak gravatar imageberak ( 2014-03-01 03:32:06 -0600 )edit

Thanks!!! Its working now.

ema gravatar imageema ( 2014-03-01 05:05:04 -0600 )edit

How do you do this in the cmdline? i tried some thing like " python create_csv.py c;/location/att_faces " but it just gives me ' python ' is not recognized as an internal or external command?

Raymund_Ocaba gravatar imageRaymund_Ocaba ( 2014-03-19 08:02:39 -0600 )edit

@Raymund_Ocaba if you haven't got python installed, you can't run python scripts. full-stop.

just get creative - the required csv file jus consists of lines like:

full_path_to_image semicolon label_id

(really, there's no magic involved here)

berak gravatar imageberak ( 2014-03-19 08:07:38 -0600 )edit

i did install python 3.3 and still won't recognized it

Raymund_Ocaba gravatar imageRaymund_Ocaba ( 2014-03-19 08:30:54 -0600 )edit

it's probably expecting python2.7 (but such a simple thing should not make any difference, imho)

no idea now, sorry

berak gravatar imageberak ( 2014-03-19 08:42:15 -0600 )edit