mexopencv  3.4.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 }
DECOMP_SVD
STL namespace.
DECOMP_LU
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
DECOMP_CHOLESKY
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: invert.cpp:28
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
const ConstMap< string, int > InvMethods
Inversion Methods.
Definition: invert.cpp:14
STL class.
Global constant definitions.
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const
double invert(InputArray src, OutputArray dst, int flags=DECOMP_LU)