mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 13:47:32 +08:00
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;
|
||||
|
||||
// Gets string information by label
|
||||
virtual string getLabelInfo(const int label) = 0;
|
||||
virtual string getLabelInfo(int label) const = 0;
|
||||
|
||||
// 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);
|
||||
|
@ -21,9 +21,9 @@
|
||||
struct LabelInfo
|
||||
{
|
||||
LabelInfo():label(-1), value("") {}
|
||||
LabelInfo(int _label, std::string _value): label(_label), value(_value) {}
|
||||
std::string 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 << "}";
|
||||
@ -33,7 +33,11 @@ struct LabelInfo
|
||||
label = (int)node["label"];
|
||||
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)
|
||||
@ -49,12 +53,6 @@ static void read(const cv::FileNode& node, LabelInfo& x, const LabelInfo& defaul
|
||||
x.read(node);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const LabelInfo& info)
|
||||
{
|
||||
out << "{ label = " << info.label << ", " << "value = " << info.value << "}";
|
||||
return out;
|
||||
}
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
@ -188,10 +186,10 @@ public:
|
||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||
|
||||
// Gets additional information by label
|
||||
string getLabelInfo(const int label);
|
||||
string getLabelInfo(int label) const;
|
||||
|
||||
// Gets labels by string
|
||||
std::vector<int> getLabelsByString(const string str);
|
||||
std::vector<int> getLabelsByString(const string& str);
|
||||
|
||||
AlgorithmInfo* info() const;
|
||||
};
|
||||
@ -253,10 +251,10 @@ public:
|
||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||
|
||||
// Gets additional information by label
|
||||
string getLabelInfo(const int label);
|
||||
string getLabelInfo(int label) const;
|
||||
|
||||
// Gets labels by string
|
||||
std::vector<int> getLabelsByString(const string str);
|
||||
std::vector<int> getLabelsByString(const string& str);
|
||||
|
||||
AlgorithmInfo* info() const;
|
||||
};
|
||||
@ -348,10 +346,10 @@ public:
|
||||
void setLabelsInfo(const std::map<int,string>& labelsInfo);
|
||||
|
||||
// Gets additional information by label
|
||||
string getLabelInfo(const int label);
|
||||
string getLabelInfo(int label) const;
|
||||
|
||||
// Gets labels by string
|
||||
std::vector<int> getLabelsByString(const string str);
|
||||
std::vector<int> getLabelsByString(const string& str);
|
||||
|
||||
// Getter functions.
|
||||
int neighbors() const { return _neighbors; }
|
||||
@ -522,14 +520,14 @@ void Eigenfaces::setLabelsInfo(const std::map<int,string>& labelsInfo)
|
||||
_labelsInfo = labelsInfo;
|
||||
}
|
||||
|
||||
string Eigenfaces::getLabelInfo(const int label)
|
||||
string Eigenfaces::getLabelInfo(int label) const
|
||||
{
|
||||
if(_labelsInfo.count(label) > 0)
|
||||
return _labelsInfo[label];
|
||||
return _labelsInfo.at(label);
|
||||
return "";
|
||||
}
|
||||
|
||||
vector<int> Eigenfaces::getLabelsByString(const string str)
|
||||
vector<int> Eigenfaces::getLabelsByString(const string& str)
|
||||
{
|
||||
vector<int> labels;
|
||||
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;
|
||||
}
|
||||
|
||||
string Fisherfaces::getLabelInfo(const int label)
|
||||
string Fisherfaces::getLabelInfo(int label) const
|
||||
{
|
||||
if(_labelsInfo.count(label) > 0)
|
||||
return _labelsInfo[label];
|
||||
return _labelsInfo.at(label);
|
||||
return "";
|
||||
}
|
||||
|
||||
vector<int> Fisherfaces::getLabelsByString(const string str)
|
||||
vector<int> Fisherfaces::getLabelsByString(const string& str)
|
||||
{
|
||||
vector<int> labels;
|
||||
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;
|
||||
}
|
||||
|
||||
string LBPH::getLabelInfo(const int label)
|
||||
string LBPH::getLabelInfo(int label) const
|
||||
{
|
||||
if(_labelsInfo.count(label) > 0)
|
||||
return _labelsInfo[label];
|
||||
return _labelsInfo.at(label);
|
||||
return "";
|
||||
}
|
||||
|
||||
vector<int> LBPH::getLabelsByString(const string str)
|
||||
vector<int> LBPH::getLabelsByString(const string& str)
|
||||
{
|
||||
vector<int> labels;
|
||||
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);
|
||||
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;
|
||||
// Sometimes you'll need to get/set internal model data,
|
||||
// which isn't exposed by the public cv::FaceRecognizer.
|
||||
|
Loading…
Reference in New Issue
Block a user