Ask Your Question

How is Facerecognizer model stored?

asked 2012-10-24 11:12:39 -0600

de linne gravatar image

I'm building an application for android that does face authentication. Now I want to store the trained Facerecognizer, I know I can save the model to an XML file. But this file seems to be quite big +10MB. Is there some other way to save the model? And is there some place where I can find more information about how the saving currently works?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-10-24 14:12:34 -0600

updated 2012-10-24 14:17:18 -0600

All face recognition models in OpenCV are derived from the abstract base class cv::FaceRecognizer and need to implement the two pure virtual methods cv::FaceRecognizer::save and cv::FaceRecognizer::load for persisting a model:

class FaceRecognizer : public Algorithm

    // Some other functions here:
    // ...

    // Serializes this object to a given cv::FileStorage.
    virtual void save(FileStorage& fs) const = 0;

    // Deserializes this object from a given cv::FileStorage.
    virtual void load(const FileStorage& fs) = 0;

As you can see, these methods make use of the cv::FileStorage to serialize the data to YAML or XML. For a detailed guide on how to use cv::FileStorage, see the very detailed OpenCV documentation on XML/YAML Persistence at:

The implementation for the cv::FaceRecognizer models then is dead simple, as you can see with the Eigenfaces model for example:

It's basically just reading and writing the matrices and parameters of a model to the cv::FileStorage.

All that said, you are absolutely right. XML and YAML may take up more space, than a binary format probably does. But on the other hand and more importantly, XML or YAML files can be read on any device and almost any operating system available. You said you are using Android, so what I would do as a first attempt to lower the consumed space is to zip the whole thing. I think, that easily compresses it to half the size.

Here's an Eigenfaces model on the AT&T Facedatabase, which has 15 components. The file size was reduced from 4.6M to 1.7M. It may be a little slower to unzip the model before reading it, but... everything in life is a trade-off:

philipp@mango:~/github/libfacerec-build$ du -sh eigenfaces_at.yml
4.6M    eigenfaces_at.yml
philipp@mango:~/github/libfacerec-build$ gzip eigenfaces_at.yml 
philipp@mango:~/github/libfacerec-build$ du -sh eigenfaces_at.yml.gz 
1.7M    eigenfaces_at.yml.gz
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2012-10-24 11:12:39 -0600

Seen: 853 times

Last updated: Oct 24 '12