mexopencv  0.1
mex interface for opencv library
erode.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<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  Mat kernel;
29  Point anchor(-1,-1);
30  int iterations = 1;
31  int borderType = cv::BORDER_CONSTANT;
32  Scalar borderValue = morphologyDefaultBorderValue();
33  for (int i=1; i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key=="Element")
36  kernel = rhs[i+1].toMat(CV_8U);
37  else if (key=="Anchor")
38  anchor = rhs[i+1].toPoint();
39  else if (key=="Iterations")
40  iterations = rhs[i+1].toInt();
41  else if (key=="BorderType")
42  borderType = BorderType[rhs[i+1].toString()];
43  else if (key=="BorderValue")
44  borderValue = rhs[i+1].toScalar();
45  else
46  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
47  }
48 
49  // Process
50  Mat src(rhs[0].toMat()), dst;
51  erode(src, dst, kernel, anchor, iterations, borderType, borderValue);
52  plhs[0] = MxArray(dst);
53 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: erode.cpp:19
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.