17 map<int,Ptr<LDA> > obj_;
27 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
33 vector<MxArray> rhs(prhs, prhs+nrhs);
34 int id = rhs[0].toInt();
35 string method(rhs[1].toString());
38 if (method ==
"new") {
39 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
40 int num_components = 0;
41 for (
int i=2; i<nrhs; i+=2) {
42 string key(rhs[i].toString());
43 if (key==
"NumComponents")
44 num_components = rhs[i+1].toInt();
46 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
48 obj_[++last_id] = makePtr<LDA>(num_components);
54 Ptr<LDA> obj = obj_[id];
55 if (method ==
"delete") {
59 else if (method ==
"load") {
61 obj->load(rhs[2].toString());
63 else if (method ==
"save") {
65 obj->save(rhs[2].toString());
67 else if (method ==
"compute") {
69 Mat labels(rhs[3].toMat(CV_32S));
70 if (rhs[2].isCell()) {
71 vector<Mat> src(rhs[2].toVector<Mat>());
72 obj->compute(src, labels);
75 Mat src(rhs[2].toMat(CV_64F));
76 obj->compute(src, labels);
79 else if (method ==
"project") {
81 Mat src(rhs[2].toMat(CV_64F));
82 plhs[0] =
MxArray(obj->project(src));
84 else if (method ==
"reconstruct") {
86 Mat src(rhs[2].toMat(CV_64F));
87 plhs[0] =
MxArray(obj->reconstruct(src));
89 else if (method ==
"get") {
91 string prop(rhs[2].toString());
92 if (prop ==
"eigenvalues")
93 plhs[0] =
MxArray(obj->eigenvalues());
94 else if (prop ==
"eigenvectors")
95 plhs[0] =
MxArray(obj->eigenvectors());
97 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
100 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.