mexopencv  3.4.1
MEX interface for OpenCV library
getDerivKernels.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/imgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 
13 namespace {
16  ("Scharr", CV_SCHARR);
17 }
18 
26 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
27 {
28  // Check the number of arguments
29  nargchk((nrhs%2)==0 && nlhs<=2);
30 
31  // Argument vector
32  vector<MxArray> rhs(prhs, prhs+nrhs);
33 
34  // Option processing
35  int dx = 1;
36  int dy = 1;
37  int ksize = 3;
38  bool normalize = false;
39  int ktype = CV_32F;
40  for (int i=0; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "Dx")
43  dx = rhs[i+1].toInt();
44  else if (key == "Dy")
45  dy = rhs[i+1].toInt();
46  else if (key == "KSize")
47  ksize = (rhs[i+1].isChar()) ?
48  KSizeMap[rhs[i+1].toString()] : rhs[i+1].toInt();
49  else if (key == "Normalize")
50  normalize = rhs[i+1].toBool();
51  else if (key == "KType")
52  ktype = (rhs[i+1].isChar()) ?
53  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
54  else
55  mexErrMsgIdAndTxt("mexopencv:error",
56  "Unrecognized option %s", key.c_str());
57  }
58 
59  // Process
60  Mat kx, ky;
61  getDerivKernels(kx, ky, dx, dy, ksize, normalize, ktype);
62  plhs[0] = MxArray(kx);
63  if (nlhs>1)
64  plhs[1] = MxArray(ky);
65 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
const ConstMap< string, int > KSizeMap
KSize map for option processing.
STL namespace.
void getDerivKernels(OutputArray kx, OutputArray ky, int dx, int dy, int ksize, bool normalize=false, int ktype=CV_32F)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_32F
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...
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
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/output arguments number check.
Definition: mexopencv.hpp:181
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_SCHARR