mexopencv  0.1
mex interface for opencv library
getStructuringElement.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  ("Rect", cv::MORPH_RECT)
16  ("Cross", cv::MORPH_CROSS)
17  ("Ellipse", cv::MORPH_ELLIPSE);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk((nrhs%2)==0 && nlhs<=1);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  int shape = cv::MORPH_RECT;
37  Size ksize(3,3);
38  Point anchor(-1,-1);
39  for (int i=0; i<nrhs; i+=2) {
40  string key(rhs[i].toString());
41  if (key=="Shape")
42  shape = MorphShape[rhs[i+1].toString()];
43  else if (key=="KSize")
44  ksize = rhs[i+1].toSize();
45  else if (key=="Anchor")
46  anchor = rhs[i+1].toPoint();
47  else
48  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
49  }
50 
51  // Process
52  Mat elem = getStructuringElement(shape, ksize, anchor);
53  plhs[0] = MxArray(elem);
54 }
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927