21 (
"Row", PCA::DATA_AS_ROW)
22 (
"Col", PCA::DATA_AS_COL);
39 int id = rhs[0].toInt();
40 string method(rhs[1].toString());
43 if (method ==
"new") {
55 if (method ==
"delete") {
60 else if (method ==
"read") {
61 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
62 bool loadFromString =
false;
63 for (
int i=3; i<nrhs; i+=2) {
64 string key(rhs[i].toString());
65 if (key ==
"FromString")
66 loadFromString = rhs[i+1].toBool();
69 "Unrecognized option %s", key.
c_str());
71 FileStorage fs(rhs[2].toString(), FileStorage::READ +
72 (loadFromString ? FileStorage::MEMORY : 0));
77 else if (method ==
"write") {
79 FileStorage fs(rhs[2].toString(), FileStorage::WRITE +
80 ((nlhs > 0) ? FileStorage::MEMORY : 0));
87 else if (method ==
"compute") {
88 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
90 int flags = PCA::DATA_AS_ROW;
91 int maxComponents = 0;
92 double retainedVariance = 1.0;
93 bool use_second_variant =
false;
94 for (
int i=3; i<nrhs; i+=2) {
95 string key(rhs[i].toString());
97 mean = rhs[i+1].toMat();
98 else if (key ==
"DataAs")
99 flags =
DataAs[rhs[i+1].toString()];
100 else if (key ==
"MaxComponents")
101 maxComponents = rhs[i+1].toInt();
102 else if (key ==
"RetainedVariance") {
103 retainedVariance = rhs[i+1].toDouble();
104 use_second_variant =
true;
108 "Unrecognized option %s", key.
c_str());
111 if (use_second_variant)
112 obj->operator()(data,
mean, flags, retainedVariance);
114 obj->operator()(data,
mean, flags, maxComponents);
116 else if (method ==
"project") {
120 else if (method ==
"backProject") {
124 else if (method ==
"get") {
126 string prop(rhs[2].toString());
127 if (prop ==
"eigenvectors")
129 else if (prop ==
"eigenvalues")
131 else if (prop ==
"mean")
135 "Unrecognized property %s", prop.
c_str());
137 else if (method ==
"set") {
139 string prop(rhs[2].toString());
140 if (prop ==
"eigenvectors")
142 else if (prop ==
"eigenvalues")
144 else if (prop ==
"mean")
145 obj->
mean = rhs[3].toMat();
148 "Unrecognized property %s", prop.
c_str());
152 "Unrecognized operation %s", method.
c_str());
Scalar mean(InputArray src, InputArray mask=noArray())
Mat project(InputArray vec) const
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void read(const FileNode &fn)
FileNode root(int streamidx=0) const
virtual bool isOpened() const
struct mxArray_tag mxArray
Forward declaration for mxArray.
int last_id
Last object id to allocate.
map< int, Ptr< PCA > > obj_
Object container.
virtual String releaseAndGetString()
Mat backProject(InputArray vec) const
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
void write(FileStorage &fs) const
const ConstMap< std::string, int > DataAs
Data arrangement options.