mexopencv  0.1
mex interface for opencv library
solve.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
14 const ConstMap<string,int> DecompTypesMap = ConstMap<string,int>
15  ("LU", cv::DECOMP_LU)
16  ("SVD", cv::DECOMP_SVD)
17  ("EIG", cv::DECOMP_EIG)
18  ("Cholesky", cv::DECOMP_CHOLESKY)
19  ("QR", cv::DECOMP_QR);
20 }
21 
29 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
30 {
31  // Check the number of arguments
32  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=2);
33 
34  // Argument vector
35  vector<MxArray> rhs(prhs, prhs+nrhs);
36 
37  // Option processing
38  int flags = cv::DECOMP_LU;
39  bool is_normal = false;
40  for (int i=2; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "Method")
43  flags = DecompTypesMap[rhs[i+1].toString()];
44  else if (key == "IsNormal")
45  is_normal = rhs[i+1].toBool();
46  else
47  mexErrMsgIdAndTxt("mexopencv:error",
48  "Unrecognized option %s", key.c_str());
49  }
50  flags |= (is_normal ? cv::DECOMP_NORMAL : 0);
51 
52  // Process
53  Mat src1(rhs[0].toMat(rhs[0].isSingle() ? CV_32F : CV_64F)),
54  src2(rhs[1].toMat(rhs[1].isSingle() ? CV_32F : CV_64F)),
55  dst;
56  bool ret = solve(src1, src2, dst, flags);
57  plhs[0] = MxArray(dst);
58  if (nlhs > 1)
59  plhs[1] = MxArray(ret);
60 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: solve.cpp:29
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