virtual void load(const FileStorage& fs) = 0;
// Sets additional information as pairs label - info.
- virtual void setLabelsInfo(const std::map<int, string>& labelsInfo) = 0;
+ void setLabelsInfo(const std::map<int, string>& labelsInfo);
// Gets string information by label
- virtual string getLabelInfo(int label) const = 0;
+ string getLabelInfo(const int &label);
// Gets labels by string
- virtual vector<int> getLabelsByString(const string& str) = 0;
+ vector<int> getLabelsByString(const string& str);
};
-----------------------------
Sets string information about labels into the model.
-.. ocv:function:: void FaceRecognizer::setLabelsInfo(const std::map<int, string>& labelsInfo) = 0
+.. ocv:function:: void FaceRecognizer::setLabelsInfo(const std::map<int, string>& labelsInfo)
Information about the label loads as a pair "label id - string info".
----------------------------
Gets string information by label.
-.. ocv:function:: string FaceRecognizer::getLabelInfo(int label) const = 0
+.. ocv:function:: string FaceRecognizer::getLabelInfo(const int &label)
If an unknown label id is provided or there is no label information assosiated with the specified label id the method returns an empty string.
---------------------------------
Gets vector of labels by string.
-.. ocv:function:: vector<int> FaceRecognizer::getLabelsByString(const string& str) = 0
+.. ocv:function:: vector<int> FaceRecognizer::getLabelsByString(const string& str)
The function searches for the labels containing the specified substring in the associated string info.
* ``mean`` The sample mean calculated from 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.
-* ``labelsInfo`` The string information about the labels.
createFisherFaceRecognizer
--------------------------
* ``mean`` The sample mean calculated from the training data.
* ``projections`` The projections of the training data.
* ``labels`` The labels corresponding to the projections.
-* ``labelsInfo`` The string information about the labels.
createLBPHFaceRecognizer
* ``threshold`` see :ocv:func:`createLBPHFaceRecognizer`.
* ``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.
-* ``labelsInfo`` The string information about the labels.
return elems;
}
+// This class was introduced to avoid an addition of new virtual functions in FaceRecognizer class.
+// It is safe for a binary compatibility.
+class FaceRecognizerBase : public FaceRecognizer
+{
+protected:
+ // Stored pairs "label id - string info"
+ std::map<int, string> _labelsInfo;
+
+public:
+ // Sets additional information as pairs label - info.
+ virtual void setLabelsInfo(const std::map<int, string>& labelsInfo);
+
+ // Gets string information by label
+ virtual string getLabelInfo(int label) const;
+
+ // Gets labels by string
+ virtual vector<int> getLabelsByString(const string& str);
+};
+
+void FaceRecognizerBase::setLabelsInfo(const std::map<int,string>& labelsInfo)
+{
+ _labelsInfo = labelsInfo;
+}
+
+string FaceRecognizerBase::getLabelInfo(int label) const
+{
+ std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
+ return iter != _labelsInfo.end() ? iter->second : "";
+}
+
+vector<int> FaceRecognizerBase::getLabelsByString(const string& str)
+{
+ vector<int> labels;
+ for(std::map<int,string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
+ {
+ size_t found = (it->second).find(str);
+ if(found != string::npos)
+ labels.push_back(it->first);
+ }
+ return labels;
+}
+
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
// Cognitive Neuroscience 3 (1991), 71–86.
-class Eigenfaces : public FaceRecognizer
+class Eigenfaces : public FaceRecognizerBase
{
private:
int _num_components;
Mat _eigenvectors;
Mat _eigenvalues;
Mat _mean;
- std::map<int, string> _labelsInfo;
public:
using FaceRecognizer::save;
// See FaceRecognizer::save.
void save(FileStorage& fs) const;
- // Sets additional information as pairs label - info.
- void setLabelsInfo(const std::map<int,string>& labelsInfo);
-
- // Gets string information by label
- string getLabelInfo(int label) const;
-
- // Gets labels by string
- std::vector<int> getLabelsByString(const string& str);
-
AlgorithmInfo* info() const;
};
// faces: Recognition using class specific linear projection.". IEEE
// Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997),
// 711–720.
-class Fisherfaces: public FaceRecognizer
+class Fisherfaces: public FaceRecognizerBase
{
private:
int _num_components;
Mat _mean;
vector<Mat> _projections;
Mat _labels;
- std::map<int, string> _labelsInfo;
public:
using FaceRecognizer::save;
// See FaceRecognizer::save.
void save(FileStorage& fs) const;
- // Sets additional information as pairs label - info.
- void setLabelsInfo(const std::map<int,string>& labelsInfo);
-
- // Gets string information by label
- string getLabelInfo(int label) const;
-
- // Gets labels by string
- std::vector<int> getLabelsByString(const string& str);
-
AlgorithmInfo* info() const;
};
// patterns: Application to face recognition." IEEE Transactions on Pattern
// Analysis and Machine Intelligence, 28(12):2037-2041.
//
-class LBPH : public FaceRecognizer
+class LBPH : public FaceRecognizerBase
{
private:
int _grid_x;
vector<Mat> _histograms;
Mat _labels;
- std::map<int, string> _labelsInfo;
// Computes a LBPH model with images in src and
// corresponding labels in labels, possibly preserving
// old model data.
void train(InputArrayOfArrays src, InputArray labels, bool preserveData);
-
public:
using FaceRecognizer::save;
using FaceRecognizer::load;
// See FaceRecognizer::save.
void save(FileStorage& fs) const;
- // Sets additional information as pairs label - info.
- void setLabelsInfo(const std::map<int,string>& labelsInfo);
-
- // Gets string information by label
- string getLabelInfo(int label) const;
-
- // Gets labels by string
- std::vector<int> getLabelsByString(const string& str);
-
// Getter functions.
int neighbors() const { return _neighbors; }
int radius() const { return _radius; }
fs.release();
}
+void FaceRecognizer::setLabelsInfo(const std::map<int, string>& labelsInfo)
+{
+ FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
+ CV_Assert(base != 0);
+ base->setLabelsInfo(labelsInfo);
+}
+
+string FaceRecognizer::getLabelInfo(const int &label)
+{
+ FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
+ CV_Assert(base != 0);
+ return base->getLabelInfo(label);
+}
+
+vector<int> FaceRecognizer::getLabelsByString(const string& str)
+{
+ FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
+ CV_Assert(base != 0);
+ return base->getLabelsByString(str);
+}
+
//------------------------------------------------------------------------------
// Eigenfaces
//------------------------------------------------------------------------------
fs << "]";
}
-void Eigenfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
-{
- _labelsInfo = labelsInfo;
-}
-
-string Eigenfaces::getLabelInfo(int label) const
-{
- std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
- return iter != _labelsInfo.end() ? iter->second : "";
-}
-
-vector<int> Eigenfaces::getLabelsByString(const string& str)
-{
- vector<int> labels;
- for(std::map<int,string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
- {
- size_t found = (it->second).find(str);
- if(found != string::npos)
- labels.push_back(it->first);
- }
- return labels;
-}
-
//------------------------------------------------------------------------------
// Fisherfaces
//------------------------------------------------------------------------------
fs << "]";
}
-void Fisherfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
-{
- _labelsInfo = labelsInfo;
-}
-
-string Fisherfaces::getLabelInfo(int label) const
-{
- std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
- return iter != _labelsInfo.end() ? iter->second : "";
-}
-
-vector<int> Fisherfaces::getLabelsByString(const string& str)
-{
- vector<int> labels;
- for(std::map<int,string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
- {
- size_t found = (it->second).find(str);
- if(found != string::npos)
- labels.push_back(it->first);
- }
- return labels;
-}
-
//------------------------------------------------------------------------------
// LBPH
//------------------------------------------------------------------------------
fs << "]";
}
-void LBPH::setLabelsInfo(const std::map<int,string>& labelsInfo)
-{
- _labelsInfo = labelsInfo;
-}
-
-string LBPH::getLabelInfo(int label) const
-{
- std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
- return iter != _labelsInfo.end() ? iter->second : "";
-}
-
-vector<int> LBPH::getLabelsByString(const string& str)
-{
- vector<int> labels;
- for(std::map<int,string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
- {
- size_t found = (it->second).find(str);
- if(found != string::npos)
- labels.push_back(it->first);
- }
- return labels;
-}
-
void LBPH::train(InputArrayOfArrays _in_src, InputArray _in_labels) {
this->train(_in_src, _in_labels, false);
}