Sunday, August 16, 2009

Converting the Yale database to a format that OpenCV 1.1.1 can read

The Yale face database, http://cvc.yale.edu/projects/yalefaces/yalefaces.html, is a collection of 165 faces. This is a useful source of data for training a face recognizer. I know that OpenCV already comes with trained trainers, but where is the fun in that? My trying to own face recognizer myself, I'll find out about some missing steps.

For example, the Yale Face Database files are all GIF's. OpenCV 1.1.1 does not read GIF's. They must be converted to some format that OpenCV can read. I chose to use png. but what is the easy way to convert these gif's to png's?

I used the Python Image Library and some 1-liner bash scripting magic to convert all gif's to png's.

First, I renamed all the database files to have a suffix ".gif"; The files in the Yale database don't have a suffix. I ran tests and perhaps this was not necessary but I didn't want to run into a problem with one of the files. This is the conversion I used in the directory that contains all the Yale database files:

for i in `lsxargs`;do pilconvert.py $i $i.png; done

If you see the string "lsxargs" above, this is wrong. There is a vertical bar between ls and xargs. I don't know why Blogger doesn't allow the pipe symbol.

pilconvert.py is a script that comes with the Python Image Library.

Now, if only the task of creating the rectangle for the ROI, region of interest, was just as easy.

No comments: