mexopencv  0.1
mex interface for opencv library
Sobel.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>=1 && (nrhs%2)==1 && nlhs<=1);
29 
30  // Argument vector
31  vector<MxArray> rhs(prhs, prhs+nrhs);
32 
33  // Option processing
34  int ddepth = -1;
35  int dx = 1;
36  int dy = 1;
37  int ksize = 3;
38  double scale = 1;
39  double delta = 0;
40  int borderType = cv::BORDER_DEFAULT;
41  for (int i=1; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key=="DDepth")
44  ddepth = (rhs[i+1].isChar()) ?
45  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else if (key=="XOrder")
47  dx = rhs[i+1].toInt();
48  else if (key=="YOrder")
49  dy = rhs[i+1].toInt();
50  else if (key=="KSize")
51  ksize = (rhs[i+1].isChar()) ?
52  KSizeMap[rhs[i+1].toString()] : rhs[i+1].toInt();
53  else if (key=="Scale")
54  scale = rhs[i+1].toDouble();
55  else if (key=="Delta")
56  delta = rhs[i+1].toDouble();
57  else if (key=="BorderType")
58  borderType = BorderType[rhs[i+1].toString()];
59  else
60  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
61  }
62 
63  // Execute function
64  Mat src(rhs[0].toMat()), dst;
65  Sobel(src, dst, ddepth, dx, dy, ksize, scale, delta, borderType);
66  plhs[0] = MxArray(dst);
67 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
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: Sobel.cpp:25
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927