moving FaceRecognizer2 from public header to .cpp
This commit is contained in:
parent
59c8edfd98
commit
02b32d86d3
@ -958,26 +958,6 @@ namespace cv
|
|||||||
vector<int> getLabelsByString(const string& str);
|
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> 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> createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX);
|
||||||
CV_EXPORTS_W Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8,
|
CV_EXPORTS_W Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8,
|
||||||
|
@ -18,41 +18,6 @@
|
|||||||
#include "precomp.hpp"
|
#include "precomp.hpp"
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
struct LabelInfo
|
|
||||||
{
|
|
||||||
LabelInfo():label(-1), value("") {}
|
|
||||||
LabelInfo(int _label, const std::string &_value): label(_label), value(_value) {}
|
|
||||||
int label;
|
|
||||||
std::string value;
|
|
||||||
void write(cv::FileStorage& fs) const
|
|
||||||
{
|
|
||||||
fs << "{" << "label" << label << "value" << value << "}";
|
|
||||||
}
|
|
||||||
void read(const cv::FileNode& node)
|
|
||||||
{
|
|
||||||
label = (int)node["label"];
|
|
||||||
value = (std::string)node["value"];
|
|
||||||
}
|
|
||||||
std::ostream& operator<<(std::ostream& out)
|
|
||||||
{
|
|
||||||
out << "{ label = " << label << ", " << "value = " << value << "}";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static void write(cv::FileStorage& fs, const std::string&, const LabelInfo& x)
|
|
||||||
{
|
|
||||||
x.write(fs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void read(const cv::FileNode& node, LabelInfo& x, const LabelInfo& default_value = LabelInfo())
|
|
||||||
{
|
|
||||||
if(node.empty())
|
|
||||||
x = default_value;
|
|
||||||
else
|
|
||||||
x.read(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -133,29 +98,81 @@ inline vector<_Tp> remove_dups(const vector<_Tp>& src) {
|
|||||||
return elems;
|
return elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceRecognizer2::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
// The FaceRecognizer2 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
|
||||||
{
|
{
|
||||||
_labelsInfo = labelsInfo;
|
protected:
|
||||||
}
|
// Stored pairs "label id - string info"
|
||||||
|
std::map<int, string> _labelsInfo;
|
||||||
|
|
||||||
string FaceRecognizer2::getLabelInfo(int label) const
|
public:
|
||||||
{
|
// Sets additional information as pairs label - info.
|
||||||
std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
|
virtual void setLabelsInfo(const std::map<int, string>& labelsInfo)
|
||||||
return iter != _labelsInfo.end() ? iter->second : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<int> FaceRecognizer2::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);
|
_labelsInfo = labelsInfo;
|
||||||
if(found != string::npos)
|
|
||||||
labels.push_back(it->first);
|
|
||||||
}
|
}
|
||||||
return labels;
|
|
||||||
|
// Gets string information by label
|
||||||
|
virtual string getLabelInfo(int label) const
|
||||||
|
{
|
||||||
|
std::map<int, string>::const_iterator iter(_labelsInfo.find(label));
|
||||||
|
return iter != _labelsInfo.end() ? iter->second : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets labels by string
|
||||||
|
virtual vector<int> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
// Utility structure to load/save face label info (a pair of int and string) via FileStorage
|
||||||
|
struct LabelInfo
|
||||||
|
{
|
||||||
|
LabelInfo():label(-1), value("") {}
|
||||||
|
LabelInfo(int _label, const std::string &_value): label(_label), value(_value) {}
|
||||||
|
int label;
|
||||||
|
std::string value;
|
||||||
|
void write(cv::FileStorage& fs) const
|
||||||
|
{
|
||||||
|
fs << "{" << "label" << label << "value" << value << "}";
|
||||||
|
}
|
||||||
|
void read(const cv::FileNode& node)
|
||||||
|
{
|
||||||
|
label = (int)node["label"];
|
||||||
|
value = (std::string)node["value"];
|
||||||
|
}
|
||||||
|
std::ostream& operator<<(std::ostream& out)
|
||||||
|
{
|
||||||
|
out << "{ label = " << label << ", " << "value = " << value << "}";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static void write(cv::FileStorage& fs, const std::string&, const LabelInfo& x)
|
||||||
|
{
|
||||||
|
x.write(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void read(const cv::FileNode& node, LabelInfo& x, const LabelInfo& default_value = LabelInfo())
|
||||||
|
{
|
||||||
|
if(node.empty())
|
||||||
|
x = default_value;
|
||||||
|
else
|
||||||
|
x.read(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
|
// Turk, M., and Pentland, A. "Eigenfaces for recognition.". Journal of
|
||||||
// Cognitive Neuroscience 3 (1991), 71–86.
|
// Cognitive Neuroscience 3 (1991), 71–86.
|
||||||
class Eigenfaces : public FaceRecognizer2
|
class Eigenfaces : public FaceRecognizer2
|
||||||
|
Loading…
Reference in New Issue
Block a user