mexopencv  3.4.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 {
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 }
DECOMP_SVD
const ConstMap< string, int > DecompTypesMap
matrix decomposition types for option processing
Definition: solve.cpp:14
DECOMP_NORMAL
STL namespace.
DECOMP_LU
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: solve.cpp:29
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
DECOMP_CHOLESKY
DECOMP_EIG
#define CV_32F
#define CV_64F
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...
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
bool solve(InputArray src1, InputArray src2, OutputArray dst, int flags=DECOMP_LU)
Global constant definitions.
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
DECOMP_QR
cv::Mat toMat() const