Minor grammatical correction in comments.

pull/2/head
Philipp Wagner 13 years ago
parent cd7d93f362
commit b3c61ee0fe
  1. 17
      modules/contrib/src/facerec.cpp
  2. 15
      samples/cpp/facerec_demo.cpp

@ -53,7 +53,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double
// make sure the input data is a vector of matrices or vector of vector // make sure the input data is a vector of matrices or vector of vector
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) { if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
string error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >)."; string error_message = "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).";
error(Exception(CV_StsBadArg, error_message, "asRowMatrix", __FILE__, __LINE__)); CV_Error(CV_StsBadArg, error_message);
} }
// number of samples // number of samples
size_t n = src.total(); size_t n = src.total();
@ -69,7 +69,7 @@ static Mat asRowMatrix(InputArrayOfArrays src, int rtype, double alpha=1, double
// make sure data can be reshaped, throw exception if not! // make sure data can be reshaped, throw exception if not!
if(src.getMat(i).total() != d) { if(src.getMat(i).total() != d) {
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total()); string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total());
error(Exception(CV_StsBadArg, error_message, "cv::asRowMatrix", __FILE__, __LINE__)); CV_Error(CV_StsBadArg, error_message);
} }
// get a hold of the current row // get a hold of the current row
Mat xi = data.row(i); Mat xi = data.row(i);
@ -125,8 +125,7 @@ public:
// corresponding labels in labels. num_components will be kept for // corresponding labels in labels. num_components will be kept for
// classification. // classification.
Eigenfaces(InputArray src, InputArray labels, Eigenfaces(InputArray src, InputArray labels,
int num_components = 0, int num_components = 0, double threshold = DBL_MAX) :
double threshold = DBL_MAX) :
_num_components(num_components), _num_components(num_components),
_threshold(threshold) { _threshold(threshold) {
train(src, labels); train(src, labels);
@ -178,10 +177,8 @@ public:
// Initializes and computes a Fisherfaces model with images in src and // Initializes and computes a Fisherfaces model with images in src and
// corresponding labels in labels. num_components will be kept for // corresponding labels in labels. num_components will be kept for
// classification. // classification.
Fisherfaces(InputArray src, Fisherfaces(InputArray src, InputArray labels,
InputArray labels, int num_components = 0, double threshold = DBL_MAX) :
int num_components = 0,
double threshold = DBL_MAX) :
_num_components(num_components), _num_components(num_components),
_threshold(threshold) { _threshold(threshold) {
train(src, labels); train(src, labels);
@ -235,7 +232,9 @@ public:
// //
// radius, neighbors are used in the local binary patterns creation. // radius, neighbors are used in the local binary patterns creation.
// grid_x, grid_y control the grid size of the spatial histograms. // grid_x, grid_y control the grid size of the spatial histograms.
LBPH(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold = DBL_MAX) : LBPH(int radius=1, int neighbors=8,
int grid_x=8, int grid_y=8,
double threshold = DBL_MAX) :
_grid_x(grid_x), _grid_x(grid_x),
_grid_y(grid_y), _grid_y(grid_y),
_radius(radius), _radius(radius),

@ -30,8 +30,9 @@ using namespace std;
static Mat toGrayscale(InputArray _src) { static Mat toGrayscale(InputArray _src) {
Mat src = _src.getMat(); Mat src = _src.getMat();
// only allow one channel // only allow one channel
if(src.channels() != 1) if(src.channels() != 1) {
CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported"); CV_Error(CV_StsBadArg, "Only Matrices with one channel are supported");
}
// create and return normalized image // create and return normalized image
Mat dst; Mat dst;
cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1); cv::normalize(_src, dst, 0, 255, NORM_MINMAX, CV_8UC1);
@ -130,16 +131,16 @@ int main(int argc, const char *argv[]) {
// cv::Algorithm, you can query the data. // cv::Algorithm, you can query the data.
// //
// First we'll use it to set the threshold of the FaceRecognizer // First we'll use it to set the threshold of the FaceRecognizer
// without retraining the model: // to 0.0 without retraining the model. This can be useful if
// you are evaluating the model:
// //
model->set("threshold", 0.0); model->set("threshold", 0.0);
// Now the threshold is of this model is 0.0. A prediction // Now the threshold of this model is set to 0.0. A prediction
// now returns -1, as it's impossible to have a distance // now returns -1, as it's impossible to have a distance below
// below it // it
//
predictedLabel = model->predict(testSample); predictedLabel = model->predict(testSample);
cout << "Predicted class = " << predictedLabel << endl; cout << "Predicted class = " << predictedLabel << endl;
// Now here is how to get the eigenvalues of this Eigenfaces model: // Here is how to get the eigenvalues of this Eigenfaces model:
Mat eigenvalues = model->getMat("eigenvalues"); Mat eigenvalues = model->getMat("eigenvalues");
// And we can do the same to display the Eigenvectors (read Eigenfaces): // And we can do the same to display the Eigenvectors (read Eigenfaces):
Mat W = model->getMat("eigenvectors"); Mat W = model->getMat("eigenvectors");

Loading…
Cancel
Save