pull/2705/head
Konstantin Matskevich 11 years ago
parent aa76ef9a98
commit d67c9aabff
  1. 38
      modules/contrib/doc/facerec/facerec_api.rst
  2. 4
      modules/contrib/include/opencv2/contrib/contrib.hpp
  3. 39
      modules/contrib/src/facerec.cpp

@ -46,6 +46,15 @@ a unified access to all face recongition algorithms in OpenCV. ::
// Deserializes this object from a given cv::FileStorage. // Deserializes this object from a given cv::FileStorage.
virtual void load(const FileStorage& fs) = 0; virtual void load(const FileStorage& fs) = 0;
// Sets additional information as pairs label - info.
virtual void setLabelsInfo(const std::map<int, string>& labelsInfo) = 0;
// Gets string information by label
virtual string getLabelInfo(int label) const = 0;
// Gets labels by string
virtual vector<int> getLabelsByString(const string& str) = 0;
}; };
@ -70,6 +79,8 @@ Moreover every :ocv:class:`FaceRecognizer` supports the:
* **Loading/Saving** the model state from/to a given XML or YAML. * **Loading/Saving** the model state from/to a given XML or YAML.
* **Setting/Getting labels info**, that is storaged as a string.
.. note:: When using the FaceRecognizer interface in combination with Python, please stick to Python 2. Some underlying scripts like create_csv will not work in other versions, like Python 3. .. note:: When using the FaceRecognizer interface in combination with Python, please stick to Python 2. Some underlying scripts like create_csv will not work in other versions, like Python 3.
Setting the Thresholds Setting the Thresholds
@ -293,6 +304,30 @@ to enable loading the model state. ``FaceRecognizer::load(FileStorage& fs)`` in
turn gets called by ``FaceRecognizer::load(const string& filename)``, to ease turn gets called by ``FaceRecognizer::load(const string& filename)``, to ease
saving a model. saving a model.
FaceRecognizer::setLabelsInfo
-----------------------------
Sets string information about labels into the model.
.. ocv:function:: void FaceRecognizer::setLabelsInfo(const std::map<int, string>& labelsInfo) = 0
Information about the label loads as a pair label-its info.
FaceRecognizer::getLabelInfo
----------------------------
Gets string information by label.
.. ocv:function:: string FaceRecognizer::getLabelInfo(int label) const = 0
If there is no such label in the model or there is no information about the label it will return an empty string.
FaceRecognizer::getLabelsByString
---------------------------------
Gets vector of labels by string.
.. ocv:function:: vector<int> FaceRecognizer::getLabelsByString(const string& str) = 0
If the string contained in a string information for a label, this label will be pushed into the vector.
createEigenFaceRecognizer createEigenFaceRecognizer
------------------------- -------------------------
@ -319,6 +354,7 @@ Model internal data:
* ``mean`` The sample mean calculated from the training data. * ``mean`` The sample mean calculated from the training data.
* ``projections`` The projections of the training data. * ``projections`` The projections of the training data.
* ``labels`` The threshold applied in the prediction. If the distance to the nearest neighbor is larger than the threshold, this method returns -1. * ``labels`` The threshold applied in the prediction. If the distance to the nearest neighbor is larger than the threshold, this method returns -1.
* ``labelsInfo`` The string information about the labels.
createFisherFaceRecognizer createFisherFaceRecognizer
-------------------------- --------------------------
@ -346,6 +382,7 @@ Model internal data:
* ``mean`` The sample mean calculated from the training data. * ``mean`` The sample mean calculated from the training data.
* ``projections`` The projections of the training data. * ``projections`` The projections of the training data.
* ``labels`` The labels corresponding to the projections. * ``labels`` The labels corresponding to the projections.
* ``labelsInfo`` The string information about the labels.
createLBPHFaceRecognizer createLBPHFaceRecognizer
@ -375,3 +412,4 @@ Model internal data:
* ``threshold`` see :ocv:func:`createLBPHFaceRecognizer`. * ``threshold`` see :ocv:func:`createLBPHFaceRecognizer`.
* ``histograms`` Local Binary Patterns Histograms calculated from the given training data (empty if none was given). * ``histograms`` Local Binary Patterns Histograms calculated from the given training data (empty if none was given).
* ``labels`` Labels corresponding to the calculated Local Binary Patterns Histograms. * ``labels`` Labels corresponding to the calculated Local Binary Patterns Histograms.
* ``labelsInfo`` The string information about the labels.

@ -948,8 +948,8 @@ namespace cv
// Deserializes this object from a given cv::FileStorage. // Deserializes this object from a given cv::FileStorage.
virtual void load(const FileStorage& fs) = 0; virtual void load(const FileStorage& fs) = 0;
// Sets additions information as pairs label - info. // Sets additional information as pairs label - info.
virtual void setLabelsInfo(const std::map<int, string>& additionalInfo) = 0; virtual void setLabelsInfo(const std::map<int, string>& labelsInfo) = 0;
// Gets string information by label // Gets string information by label
virtual string getLabelInfo(int label) const = 0; virtual string getLabelInfo(int label) const = 0;

@ -182,10 +182,10 @@ public:
// See FaceRecognizer::save. // See FaceRecognizer::save.
void save(FileStorage& fs) const; void save(FileStorage& fs) const;
// Sets additions information as pairs label - info. // Sets additional information as pairs label - info.
void setLabelsInfo(const std::map<int,string>& labelsInfo); void setLabelsInfo(const std::map<int,string>& labelsInfo);
// Gets additional information by label // Gets string information by label
string getLabelInfo(int label) const; string getLabelInfo(int label) const;
// Gets labels by string // Gets labels by string
@ -247,10 +247,10 @@ public:
// See FaceRecognizer::save. // See FaceRecognizer::save.
void save(FileStorage& fs) const; void save(FileStorage& fs) const;
// Sets additions information as pairs label - info. // Sets additional information as pairs label - info.
void setLabelsInfo(const std::map<int,string>& labelsInfo); void setLabelsInfo(const std::map<int,string>& labelsInfo);
// Gets additional information by label // Gets string information by label
string getLabelInfo(int label) const; string getLabelInfo(int label) const;
// Gets labels by string // Gets labels by string
@ -342,10 +342,10 @@ public:
// See FaceRecognizer::save. // See FaceRecognizer::save.
void save(FileStorage& fs) const; void save(FileStorage& fs) const;
// Sets additions information as pairs label - info. // Sets additional information as pairs label - info.
void setLabelsInfo(const std::map<int,string>& labelsInfo); void setLabelsInfo(const std::map<int,string>& labelsInfo);
// Gets additional information by label // Gets string information by label
string getLabelInfo(int label) const; string getLabelInfo(int label) const;
// Gets labels by string // Gets labels by string
@ -487,7 +487,7 @@ void Eigenfaces::load(const FileStorage& fs) {
// read sequences // read sequences
readFileNodeList(fs["projections"], _projections); readFileNodeList(fs["projections"], _projections);
fs["labels"] >> _labels; fs["labels"] >> _labels;
const FileNode& fn = fs["info"]; const FileNode& fn = fs["labelsInfo"];
if (fn.type() == FileNode::SEQ) if (fn.type() == FileNode::SEQ)
{ {
_labelsInfo.clear(); _labelsInfo.clear();
@ -509,7 +509,7 @@ void Eigenfaces::save(FileStorage& fs) const {
// write sequences // write sequences
writeFileNodeList(fs, "projections", _projections); writeFileNodeList(fs, "projections", _projections);
fs << "labels" << _labels; fs << "labels" << _labels;
fs << "info" << "["; fs << "labelsInfo" << "[";
for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
fs << LabelInfo(it->first, it->second); fs << LabelInfo(it->first, it->second);
fs << "]"; fs << "]";
@ -522,9 +522,8 @@ void Eigenfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
string Eigenfaces::getLabelInfo(int label) const string Eigenfaces::getLabelInfo(int label) const
{ {
if(_labelsInfo.count(label) > 0) std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
return _labelsInfo.at(label); return iter != _labelsInfo.end() ? iter->second : "";
return "";
} }
vector<int> Eigenfaces::getLabelsByString(const string& str) vector<int> Eigenfaces::getLabelsByString(const string& str)
@ -647,7 +646,7 @@ void Fisherfaces::load(const FileStorage& fs) {
// read sequences // read sequences
readFileNodeList(fs["projections"], _projections); readFileNodeList(fs["projections"], _projections);
fs["labels"] >> _labels; fs["labels"] >> _labels;
const FileNode& fn = fs["info"]; const FileNode& fn = fs["labelsInfo"];
if (fn.type() == FileNode::SEQ) if (fn.type() == FileNode::SEQ)
{ {
_labelsInfo.clear(); _labelsInfo.clear();
@ -670,7 +669,7 @@ void Fisherfaces::save(FileStorage& fs) const {
// write sequences // write sequences
writeFileNodeList(fs, "projections", _projections); writeFileNodeList(fs, "projections", _projections);
fs << "labels" << _labels; fs << "labels" << _labels;
fs << "info" << "["; fs << "labelsInfo" << "[";
for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
fs << LabelInfo(it->first, it->second); fs << LabelInfo(it->first, it->second);
fs << "]"; fs << "]";
@ -683,9 +682,8 @@ void Fisherfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
string Fisherfaces::getLabelInfo(int label) const string Fisherfaces::getLabelInfo(int label) const
{ {
if(_labelsInfo.count(label) > 0) std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
return _labelsInfo.at(label); return iter != _labelsInfo.end() ? iter->second : "";
return "";
} }
vector<int> Fisherfaces::getLabelsByString(const string& str) vector<int> Fisherfaces::getLabelsByString(const string& str)
@ -885,7 +883,7 @@ void LBPH::load(const FileStorage& fs) {
//read matrices //read matrices
readFileNodeList(fs["histograms"], _histograms); readFileNodeList(fs["histograms"], _histograms);
fs["labels"] >> _labels; fs["labels"] >> _labels;
const FileNode& fn = fs["info"]; const FileNode& fn = fs["labelsInfo"];
if (fn.type() == FileNode::SEQ) if (fn.type() == FileNode::SEQ)
{ {
_labelsInfo.clear(); _labelsInfo.clear();
@ -907,7 +905,7 @@ void LBPH::save(FileStorage& fs) const {
// write matrices // write matrices
writeFileNodeList(fs, "histograms", _histograms); writeFileNodeList(fs, "histograms", _histograms);
fs << "labels" << _labels; fs << "labels" << _labels;
fs << "info" << "["; fs << "labelsInfo" << "[";
for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++) for (std::map<int, string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
fs << LabelInfo(it->first, it->second); fs << LabelInfo(it->first, it->second);
fs << "]"; fs << "]";
@ -920,9 +918,8 @@ void LBPH::setLabelsInfo(const std::map<int,string>& labelsInfo)
string LBPH::getLabelInfo(int label) const string LBPH::getLabelInfo(int label) const
{ {
if(_labelsInfo.count(label) > 0) std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
return _labelsInfo.at(label); return iter != _labelsInfo.end() ? iter->second : "";
return "";
} }
vector<int> LBPH::getLabelsByString(const string& str) vector<int> LBPH::getLabelsByString(const string& str)

Loading…
Cancel
Save