mexopencv  0.1
mex interface for opencv library
invert.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
15  ("LU", cv::DECOMP_LU)
16  ("SVD", cv::DECOMP_SVD)
17  ("EIG", cv::DECOMP_EIG)
18  ("Cholesky", cv::DECOMP_CHOLESKY);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=2);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int method = cv::DECOMP_LU;
38  for (int i=1; i<nrhs; i+=2) {
39  string key(rhs[i].toString());
40  if (key=="Method")
41  method = InvMethods[rhs[i+1].toString()];
42  else
43  mexErrMsgIdAndTxt("mexopencv:error",
44  "Unrecognized option %s", key.c_str());
45  }
46 
47  // Process
48  Mat src(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)), dst;
49  double d = invert(src, dst, method);
50  plhs[0] = MxArray(dst);
51  if (nlhs>1)
52  plhs[1] = MxArray(d);
53 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: invert.cpp:28
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927