mexopencv  0.1
mex interface for opencv library
integral.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=3);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int sdepth = -1;
29  int sqdepth = -1;
30  for (int i=1; i<nrhs; i+=2) {
31  string key(rhs[i].toString());
32  if (key=="SDepth")
33  sdepth = (rhs[i+1].isChar()) ?
34  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
35  else if (nlhs>1 && key=="SQDepth")
36  sqdepth = (rhs[i+1].isChar()) ?
37  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
38  else
39  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
40  }
41 
42  // Process
43  Mat src(rhs[0].toMat()), sum, sqsum, tilted;
44  switch (nlhs) {
45  case 0:
46  case 1:
47  integral(src, sum, sdepth);
48  plhs[0] = MxArray(sum);
49  break;
50  case 2:
51  integral(src, sum, sqsum, sdepth, sqdepth);
52  plhs[0] = MxArray(sum);
53  plhs[1] = MxArray(sqsum);
54  break;
55  case 3:
56  integral(src, sum, sqsum, tilted, sdepth, sqdepth);
57  plhs[0] = MxArray(sum);
58  plhs[1] = MxArray(sqsum);
59  plhs[2] = MxArray(tilted);
60  break;
61  }
62 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: integral.cpp:19