Ask Your Question

Revision history [back]

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:

// 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

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
{
public:

    // 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

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
{
public:

    // 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, 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