fixes
This commit is contained in:
parent
36afd4ef55
commit
aa76ef9a98
@ -952,10 +952,10 @@ namespace cv
|
|||||||
virtual void setLabelsInfo(const std::map<int, string>& additionalInfo) = 0;
|
virtual void setLabelsInfo(const std::map<int, string>& additionalInfo) = 0;
|
||||||
|
|
||||||
// Gets string information by label
|
// Gets string information by label
|
||||||
virtual string getLabelInfo(const int label) = 0;
|
virtual string getLabelInfo(int label) const = 0;
|
||||||
|
|
||||||
// Gets labels by string
|
// Gets labels by string
|
||||||
virtual vector<int> getLabelsByString(const string str) = 0;
|
virtual vector<int> getLabelsByString(const string& str) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
||||||
|
@ -21,9 +21,9 @@
|
|||||||
struct LabelInfo
|
struct LabelInfo
|
||||||
{
|
{
|
||||||
LabelInfo():label(-1), value("") {}
|
LabelInfo():label(-1), value("") {}
|
||||||
LabelInfo(int _label, std::string _value): label(_label), value(_value) {}
|
LabelInfo(int _label, const std::string &_value): label(_label), value(_value) {}
|
||||||
std::string value;
|
|
||||||
int label;
|
int label;
|
||||||
|
std::string value;
|
||||||
void write(cv::FileStorage& fs) const
|
void write(cv::FileStorage& fs) const
|
||||||
{
|
{
|
||||||
fs << "{" << "label" << label << "value" << value << "}";
|
fs << "{" << "label" << label << "value" << value << "}";
|
||||||
@ -33,7 +33,11 @@ struct LabelInfo
|
|||||||
label = (int)node["label"];
|
label = (int)node["label"];
|
||||||
value = (std::string)node["value"];
|
value = (std::string)node["value"];
|
||||||
}
|
}
|
||||||
friend std::ostream& operator<<(std::ostream& out, const LabelInfo& info);
|
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)
|
static void write(cv::FileStorage& fs, const std::string&, const LabelInfo& x)
|
||||||
@ -49,12 +53,6 @@ static void read(const cv::FileNode& node, LabelInfo& x, const LabelInfo& defaul
|
|||||||
x.read(node);
|
x.read(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, const LabelInfo& info)
|
|
||||||
{
|
|
||||||
out << "{ label = " << info.label << ", " << "value = " << info.value << "}";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace cv
|
namespace cv
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -188,10 +186,10 @@ public:
|
|||||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||||
|
|
||||||
// Gets additional information by label
|
// Gets additional information by label
|
||||||
string getLabelInfo(const int label);
|
string getLabelInfo(int label) const;
|
||||||
|
|
||||||
// Gets labels by string
|
// Gets labels by string
|
||||||
std::vector<int> getLabelsByString(const string str);
|
std::vector<int> getLabelsByString(const string& str);
|
||||||
|
|
||||||
AlgorithmInfo* info() const;
|
AlgorithmInfo* info() const;
|
||||||
};
|
};
|
||||||
@ -253,10 +251,10 @@ public:
|
|||||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||||
|
|
||||||
// Gets additional information by label
|
// Gets additional information by label
|
||||||
string getLabelInfo(const int label);
|
string getLabelInfo(int label) const;
|
||||||
|
|
||||||
// Gets labels by string
|
// Gets labels by string
|
||||||
std::vector<int> getLabelsByString(const string str);
|
std::vector<int> getLabelsByString(const string& str);
|
||||||
|
|
||||||
AlgorithmInfo* info() const;
|
AlgorithmInfo* info() const;
|
||||||
};
|
};
|
||||||
@ -348,10 +346,10 @@ public:
|
|||||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||||
|
|
||||||
// Gets additional information by label
|
// Gets additional information by label
|
||||||
string getLabelInfo(const int label);
|
string getLabelInfo(int label) const;
|
||||||
|
|
||||||
// Gets labels by string
|
// Gets labels by string
|
||||||
std::vector<int> getLabelsByString(const string str);
|
std::vector<int> getLabelsByString(const string& str);
|
||||||
|
|
||||||
// Getter functions.
|
// Getter functions.
|
||||||
int neighbors() const { return _neighbors; }
|
int neighbors() const { return _neighbors; }
|
||||||
@ -522,14 +520,14 @@ void Eigenfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
|||||||
_labelsInfo = labelsInfo;
|
_labelsInfo = labelsInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Eigenfaces::getLabelInfo(const int label)
|
string Eigenfaces::getLabelInfo(int label) const
|
||||||
{
|
{
|
||||||
if(_labelsInfo.count(label) > 0)
|
if(_labelsInfo.count(label) > 0)
|
||||||
return _labelsInfo[label];
|
return _labelsInfo.at(label);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> Eigenfaces::getLabelsByString(const string str)
|
vector<int> Eigenfaces::getLabelsByString(const string& str)
|
||||||
{
|
{
|
||||||
vector<int> labels;
|
vector<int> labels;
|
||||||
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++)
|
||||||
@ -683,14 +681,14 @@ void Fisherfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
|||||||
_labelsInfo = labelsInfo;
|
_labelsInfo = labelsInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Fisherfaces::getLabelInfo(const int label)
|
string Fisherfaces::getLabelInfo(int label) const
|
||||||
{
|
{
|
||||||
if(_labelsInfo.count(label) > 0)
|
if(_labelsInfo.count(label) > 0)
|
||||||
return _labelsInfo[label];
|
return _labelsInfo.at(label);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> Fisherfaces::getLabelsByString(const string str)
|
vector<int> Fisherfaces::getLabelsByString(const string& str)
|
||||||
{
|
{
|
||||||
vector<int> labels;
|
vector<int> labels;
|
||||||
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++)
|
||||||
@ -920,14 +918,14 @@ void LBPH::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
|||||||
_labelsInfo = labelsInfo;
|
_labelsInfo = labelsInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
string LBPH::getLabelInfo(const int label)
|
string LBPH::getLabelInfo(int label) const
|
||||||
{
|
{
|
||||||
if(_labelsInfo.count(label) > 0)
|
if(_labelsInfo.count(label) > 0)
|
||||||
return _labelsInfo[label];
|
return _labelsInfo.at(label);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<int> LBPH::getLabelsByString(const string str)
|
vector<int> LBPH::getLabelsByString(const string& str)
|
||||||
{
|
{
|
||||||
vector<int> labels;
|
vector<int> labels;
|
||||||
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++)
|
||||||
|
@ -130,7 +130,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
//
|
//
|
||||||
string result_message = format("Predicted class = %d / Actual class = %d.", predictedLabel, testLabel);
|
string result_message = format("Predicted class = %d / Actual class = %d.", predictedLabel, testLabel);
|
||||||
cout << result_message << endl;
|
cout << result_message << endl;
|
||||||
if( (predictedLabel == testLabel) && (model->getLabelInfo(predictedLabel) != "") )
|
if( (predictedLabel == testLabel) && !model->getLabelInfo(predictedLabel).empty() )
|
||||||
cout << format("%d-th label's info: %s", predictedLabel, model->getLabelInfo(predictedLabel).c_str()) << endl;
|
cout << format("%d-th label's info: %s", predictedLabel, model->getLabelInfo(predictedLabel).c_str()) << endl;
|
||||||
// Sometimes you'll need to get/set internal model data,
|
// Sometimes you'll need to get/set internal model data,
|
||||||
// which isn't exposed by the public cv::FaceRecognizer.
|
// which isn't exposed by the public cv::FaceRecognizer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user