Skip to content

Commit 637e82d

Browse files
committed
Merge pull request #1251 from berak:face_cleanup
2 parents 8f23155 + 8d9a3e4 commit 637e82d

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

modules/face/include/opencv2/face.hpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ int num_components = 10;
113113
double threshold = 10.0;
114114
// Then if you want to have a cv::FaceRecognizer with a confidence threshold,
115115
// create the concrete implementation with the appropiate parameters:
116-
Ptr<FaceRecognizer> model = createEigenFaceRecognizer(num_components, threshold);
116+
Ptr<FaceRecognizer> model = EigenFaceRecognizer::create(num_components, threshold);
117117
@endcode
118118
119119
Sometimes it's impossible to train the model, just to experiment with threshold values. Thanks to
@@ -148,7 +148,7 @@ Since every FaceRecognizer is a Algorithm, you can use Algorithm::name to get th
148148
149149
@code
150150
// Create a FaceRecognizer:
151-
Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
151+
Ptr<FaceRecognizer> model = EigenFaceRecognizer::create();
152152
// And here's how to get its name:
153153
String name = model->name();
154154
@endcode
@@ -192,7 +192,7 @@ class CV_EXPORTS_W FaceRecognizer : public Algorithm
192192
// Create a new Fisherfaces model and retain all available Fisherfaces,
193193
// this is the most common usage of this specific FaceRecognizer:
194194
//
195-
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
195+
Ptr<FaceRecognizer> model = FisherFaceRecognizer::create();
196196
@endcode
197197
198198
And finally train it on the given dataset (the face images and labels):
@@ -223,7 +223,7 @@ class CV_EXPORTS_W FaceRecognizer : public Algorithm
223223
// Create a new LBPH model (it can be updated) and use the default parameters,
224224
// this is the most common usage of this specific FaceRecognizer:
225225
//
226-
Ptr<FaceRecognizer> model = createLBPHFaceRecognizer();
226+
Ptr<FaceRecognizer> model = LBPHFaceRecognizer::create();
227227
// This is the common interface to train all of the available cv::FaceRecognizer
228228
// implementations:
229229
//
@@ -241,7 +241,7 @@ class CV_EXPORTS_W FaceRecognizer : public Algorithm
241241
// with the new features extracted from newImages!
242242
@endcode
243243
244-
Calling update on an Eigenfaces model (see createEigenFaceRecognizer), which doesn't support
244+
Calling update on an Eigenfaces model (see EigenFaceRecognizer::create), which doesn't support
245245
updating, will throw an error similar to:
246246
247247
@code
@@ -338,6 +338,9 @@ class CV_EXPORTS_W FaceRecognizer : public Algorithm
338338
/** @overload */
339339
virtual void read(const FileNode& fn) = 0;
340340

341+
/** @overload */
342+
virtual bool empty() const = 0;
343+
341344
/** @brief Sets string info for the specified model's label.
342345
343346
The string info is replaced by the provided value if it was set before for the specified label.

modules/face/include/opencv2/face/facerec.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CV_EXPORTS_W BasicFaceRecognizer : public FaceRecognizer
3636

3737
virtual void read(const FileNode& fn);
3838
virtual void write(FileStorage& fs) const;
39+
virtual bool empty() const;
3940

4041
using FaceRecognizer::read;
4142
using FaceRecognizer::write;
@@ -72,8 +73,8 @@ class CV_EXPORTS_W EigenFaceRecognizer : public BasicFaceRecognizer
7273
7374
### Model internal data:
7475
75-
- num_components see createEigenFaceRecognizer.
76-
- threshold see createEigenFaceRecognizer.
76+
- num_components see EigenFaceRecognizer::create.
77+
- threshold see EigenFaceRecognizer::create.
7778
- eigenvalues The eigenvalues for this Principal Component Analysis (ordered descending).
7879
- eigenvectors The eigenvectors for this Principal Component Analysis (ordered by their
7980
eigenvalue).
@@ -109,8 +110,8 @@ class CV_EXPORTS_W FisherFaceRecognizer : public BasicFaceRecognizer
109110
110111
### Model internal data:
111112
112-
- num_components see createFisherFaceRecognizer.
113-
- threshold see createFisherFaceRecognizer.
113+
- num_components see FisherFaceRecognizer::create.
114+
- threshold see FisherFaceRecognizer::create.
114115
- eigenvalues The eigenvalues for this Linear Discriminant Analysis (ordered descending).
115116
- eigenvectors The eigenvectors for this Linear Discriminant Analysis (ordered by their
116117
eigenvalue).
@@ -171,11 +172,11 @@ class CV_EXPORTS_W LBPHFaceRecognizer : public FaceRecognizer
171172
172173
### Model internal data:
173174
174-
- radius see createLBPHFaceRecognizer.
175-
- neighbors see createLBPHFaceRecognizer.
176-
- grid_x see createLBPHFaceRecognizer.
177-
- grid_y see createLBPHFaceRecognizer.
178-
- threshold see createLBPHFaceRecognizer.
175+
- radius see LBPHFaceRecognizer::create.
176+
- neighbors see LBPHFaceRecognizer::create.
177+
- grid_x see LLBPHFaceRecognizer::create.
178+
- grid_y see LBPHFaceRecognizer::create.
179+
- threshold see LBPHFaceRecognizer::create.
179180
- histograms Local Binary Patterns Histograms calculated from the given training data (empty if
180181
none was given).
181182
- labels Labels corresponding to the calculated Local Binary Patterns Histograms.

modules/face/samples/facerec_lbph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ int main(int argc, const char *argv[]) {
9797
// So if you want a LBPH FaceRecognizer using a radius of
9898
// 2 and 16 neighbors, call the factory method with:
9999
//
100-
// cv::createLBPHFaceRecognizer(2, 16);
100+
// cv::face::LBPHFaceRecognizer::create(2, 16);
101101
//
102102
// And if you want a threshold (e.g. 123.0) call it with its default values:
103103
//
104-
// cv::createLBPHFaceRecognizer(1,8,8,8,123.0)
104+
// cv::face::LBPHFaceRecognizer::create(1,8,8,8,123.0)
105105
//
106106
Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create();
107107
model->train(images, labels);

modules/face/samples/facerec_save_load.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ int main(int argc, const char *argv[]) {
115115
// 10 principal components (read Eigenfaces), then call
116116
// the factory method like this:
117117
//
118-
// cv::createEigenFaceRecognizer(10);
118+
// cv::face::EigenFaceRecognizer::create(10);
119119
//
120120
// If you want to create a FaceRecognizer with a
121121
// confidence threshold (e.g. 123.0), call it with:
122122
//
123-
// cv::createEigenFaceRecognizer(10, 123.0);
123+
// cv::face::EigenFaceRecognizer::create(10, 123.0);
124124
//
125125
// If you want to use _all_ Eigenfaces and have a threshold,
126126
// then call the method like this:
127127
//
128-
// cv::createEigenFaceRecognizer(0, 123.0);
128+
// cv::face::EigenFaceRecognizer::create(0, 123.0);
129129
//
130130
Ptr<EigenFaceRecognizer> model0 = EigenFaceRecognizer::create();
131131
model0->train(images, labels);

modules/face/src/face_basic.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ cv::Mat BasicFaceRecognizer::getMean() const
5353
void BasicFaceRecognizer::read(const FileNode& fs)
5454
{
5555
//read matrices
56+
fs["threshold"] >> _threshold;
5657
fs["num_components"] >> _num_components;
5758
fs["mean"] >> _mean;
5859
fs["eigenvalues"] >> _eigenvalues;
@@ -76,6 +77,7 @@ void BasicFaceRecognizer::read(const FileNode& fs)
7677
void BasicFaceRecognizer::write(FileStorage& fs) const
7778
{
7879
// write matrices
80+
fs << "threshold" << _threshold;
7981
fs << "num_components" << _num_components;
8082
fs << "mean" << _mean;
8183
fs << "eigenvalues" << _eigenvalues;
@@ -88,3 +90,8 @@ void BasicFaceRecognizer::write(FileStorage& fs) const
8890
fs << LabelInfo(it->first, it->second);
8991
fs << "]";
9092
}
93+
94+
bool BasicFaceRecognizer::empty() const
95+
{
96+
return (_labels.empty());
97+
}

modules/face/src/lbph_faces.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ class LBPH : public LBPHFaceRecognizer
100100
// See FaceRecognizer::save.
101101
void write(FileStorage& fs) const;
102102

103+
bool empty() const {
104+
return (_labels.empty());
105+
}
106+
103107
CV_IMPL_PROPERTY(int, GridX, _grid_x)
104108
CV_IMPL_PROPERTY(int, GridY, _grid_y)
105109
CV_IMPL_PROPERTY(int, Radius, _radius)
@@ -111,6 +115,7 @@ class LBPH : public LBPHFaceRecognizer
111115

112116

113117
void LBPH::read(const FileNode& fs) {
118+
fs["threshold"] >> _threshold;
114119
fs["radius"] >> _radius;
115120
fs["neighbors"] >> _neighbors;
116121
fs["grid_x"] >> _grid_x;
@@ -133,6 +138,7 @@ void LBPH::read(const FileNode& fs) {
133138

134139
// See FaceRecognizer::save.
135140
void LBPH::write(FileStorage& fs) const {
141+
fs << "threshold" << _threshold;
136142
fs << "radius" << _radius;
137143
fs << "neighbors" << _neighbors;
138144
fs << "grid_x" << _grid_x;

modules/face/tutorials/face_tutorial.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ publications, because a lot of people asked for.
2323

2424
The currently available algorithms are:
2525

26-
- Eigenfaces (see createEigenFaceRecognizer)
27-
- Fisherfaces (see createFisherFaceRecognizer)
28-
- Local Binary Patterns Histograms (see createLBPHFaceRecognizer)
26+
- Eigenfaces (see EigenFaceRecognizer::create)
27+
- Fisherfaces (see FisherFaceRecognizer::create)
28+
- Local Binary Patterns Histograms (see LBPHFaceRecognizer::create)
2929

3030
You don't need to copy and paste the source code examples from this page, because they are available
3131
in the src folder coming with this documentation. If you have built OpenCV with the samples turned

0 commit comments

Comments
 (0)