mexopencv  0.1
mex interface for opencv library
getDerivKernels.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  ("Scharr", CV_SCHARR);
16 }
17 
25 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
26 {
27  // Check the number of arguments
28  nargchk((nrhs%2)==0 && nlhs<=2);
29 
30  // Argument vector
31  vector<MxArray> rhs(prhs, prhs+nrhs);
32 
33  // Option processing
34  int dx = 1;
35  int dy = 1;
36  int ksize = 3;
37  bool normalize = false;
38  int ktype = CV_32F;
39  for (int i=0; i<nrhs; i+=2) {
40  string key(rhs[i].toString());
41  if (key=="Dx")
42  dx = rhs[i+1].toInt();
43  else if (key=="Dy")
44  dy = rhs[i+1].toInt();
45  else if (key=="KSize")
46  ksize = (rhs[i+1].isChar()) ?
47  KSizeMap[rhs[i+1].toString()] : rhs[i+1].toInt();
48  else if (key=="Normalize")
49  normalize = rhs[i+1].toBool();
50  else if (key=="KType")
51  ktype = (rhs[i+1].isChar()) ?
52  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
53  else
54  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
55  }
56 
57  // Process
58  Mat kx, ky;
59  getDerivKernels(kx, ky, dx, dy, ksize, normalize, ktype);
60  plhs[0] = MxArray(kx);
61  if (nlhs>1)
62  plhs[1] = MxArray(ky);
63 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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