forked from China-SPE-T-2013-Group1/Face-Verification-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subspace.hpp
92 lines (69 loc) · 2.83 KB
/
subspace.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef __SUBSPACE_HPP__
#define __SUBSPACE_HPP__
#include "opencv2/core/core.hpp"
using namespace cv;
using namespace std;
namespace cv { namespace subspace {
// Calculates the projection Y = (X - mean) * W.
Mat project(InputArray W, InputArray mean, InputArray X);
// Calculates the reconstruction X = Y*W + mean.
Mat reconstruct(InputArray W, InputArray mean, InputArray Y);
// This class performs a Linear Discriminant Analysis with the classic
// Fisher's Optimization Criterion.
//
// TODO Use InputArray instead of Mat and vector<Mat> for data input.
class LDA {
private:
bool _dataAsRow;
int _num_components;
Mat _eigenvectors;
Mat _eigenvalues;
void lda(InputArray src, InputArray labels);
public:
// Initializes a LDA with num_components (default 0) and specifies how
// samples are aligned (default dataAsRow=true).
LDA(int num_components = 0) :
_num_components(num_components) {};
// Initializes and performs a Discriminant Analysis with Fisher's
// Optimization Criterion on given data in src and corresponding labels
// in labels. If 0 (or less) number of components are given, they are
// automatically determined for given data in computation.
LDA(const Mat& src, vector<int> labels,
int num_components = 0) :
_num_components(num_components)
{
this->compute(src, labels); //! compute eigenvectors and eigenvalues
}
// Initializes and performs a Discriminant Analysis with Fisher's
// Optimization Criterion on given data in src and corresponding labels
// in labels. If 0 (or less) number of components are given, they are
// automatically determined for given data in computation.
LDA(InputArray src, InputArray labels,
int num_components = 0) :
_num_components(num_components)
{
this->compute(src, labels); //! compute eigenvectors and eigenvalues
}
// Serializes this object to a given filename.
void save(const string& filename) const;
// Deserializes this object from a given filename.
void load(const string& filename);
// Serializes this object to a given cv::FileStorage.
void save(FileStorage& fs) const;
// Deserializes this object from a given cv::FileStorage.
void load(const FileStorage& node);
// Destructor.
~LDA() {}
//! Compute the discriminants for data in src and labels.
void compute(InputArray src, InputArray labels);
// Projects samples into the LDA subspace.
Mat project(InputArray src);
// Reconstructs projections from the LDA subspace.
Mat reconstruct(InputArray src);
// Returns the eigenvectors of this LDA.
Mat eigenvectors() const { return _eigenvectors; };
// Returns the eigenvalues of this LDA.
Mat eigenvalues() const { return _eigenvalues; }
};
}} // namespace
#endif