mirror of
https://github.com/opencv/opencv.git
synced 2024-11-26 04:00:30 +08:00
facerec2
This commit is contained in:
parent
8d4a76925c
commit
59c8edfd98
@ -79,7 +79,7 @@ Moreover every :ocv:class:`FaceRecognizer` supports the:
|
||||
|
||||
* **Loading/Saving** the model state from/to a given XML or YAML.
|
||||
|
||||
* **Setting/Getting labels info**, that is storaged as a string.
|
||||
* **Setting/Getting labels info**, that is storaged as a string. String labels info is useful for keeping names of the recognized people.
|
||||
|
||||
.. 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.
|
||||
|
||||
|
@ -958,6 +958,26 @@ namespace cv
|
||||
vector<int> getLabelsByString(const string& str);
|
||||
};
|
||||
|
||||
// The FaceRecognizerBase class is introduced to keep the FaceRecognizer binary backward compatibility in 2.4
|
||||
// In master setLabelInfo/getLabelInfo/getLabelsByString should be virtual and _labelsInfo should be moved to FaceRecognizer
|
||||
// that allows to avoid FaceRecognizer2 in master
|
||||
class FaceRecognizer2 : 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);
|
||||
};
|
||||
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_components = 0, double threshold = DBL_MAX);
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX);
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8,
|
||||
|
@ -133,37 +133,18 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
||||
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)
|
||||
void FaceRecognizer2::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
||||
{
|
||||
_labelsInfo = labelsInfo;
|
||||
}
|
||||
|
||||
string FaceRecognizerBase::getLabelInfo(int label) const
|
||||
string FaceRecognizer2::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> FaceRecognizer2::getLabelsByString(const string& str)
|
||||
{
|
||||
vector<int> labels;
|
||||
for(std::map<int,string>::const_iterator it = _labelsInfo.begin(); it != _labelsInfo.end(); it++)
|
||||
@ -177,7 +158,7 @@ vector<int> FaceRecognizerBase::getLabelsByString(const string& str)
|
||||
|
||||
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
|
||||
// Cognitive Neuroscience 3 (1991), 71–86.
|
||||
class Eigenfaces : public FaceRecognizerBase
|
||||
class Eigenfaces : public FaceRecognizer2
|
||||
{
|
||||
private:
|
||||
int _num_components;
|
||||
@ -230,7 +211,7 @@ public:
|
||||
// faces: Recognition using class specific linear projection.". IEEE
|
||||
// Transactions on Pattern Analysis and Machine Intelligence 19, 7 (1997),
|
||||
// 711–720.
|
||||
class Fisherfaces: public FaceRecognizerBase
|
||||
class Fisherfaces: public FaceRecognizer2
|
||||
{
|
||||
private:
|
||||
int _num_components;
|
||||
@ -287,7 +268,7 @@ public:
|
||||
// patterns: Application to face recognition." IEEE Transactions on Pattern
|
||||
// Analysis and Machine Intelligence, 28(12):2037-2041.
|
||||
//
|
||||
class LBPH : public FaceRecognizerBase
|
||||
class LBPH : public FaceRecognizer2
|
||||
{
|
||||
private:
|
||||
int _grid_x;
|
||||
@ -404,21 +385,21 @@ void FaceRecognizer::load(const string& filename) {
|
||||
|
||||
void FaceRecognizer::setLabelsInfo(const std::map<int, string>& labelsInfo)
|
||||
{
|
||||
FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
|
||||
FaceRecognizer2* base = dynamic_cast<FaceRecognizer2*>(this);
|
||||
CV_Assert(base != 0);
|
||||
base->setLabelsInfo(labelsInfo);
|
||||
}
|
||||
|
||||
string FaceRecognizer::getLabelInfo(const int &label)
|
||||
{
|
||||
FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
|
||||
FaceRecognizer2* base = dynamic_cast<FaceRecognizer2*>(this);
|
||||
CV_Assert(base != 0);
|
||||
return base->getLabelInfo(label);
|
||||
}
|
||||
|
||||
vector<int> FaceRecognizer::getLabelsByString(const string& str)
|
||||
{
|
||||
FaceRecognizerBase* base = dynamic_cast<FaceRecognizerBase*>(this);
|
||||
FaceRecognizer2* base = dynamic_cast<FaceRecognizer2*>(this);
|
||||
CV_Assert(base != 0);
|
||||
return base->getLabelsByString(str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user