mexopencv  3.4.1
MEX interface for OpenCV library
getStructuringElement.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  ("Rect", cv::MORPH_RECT)
17  ("Cross", cv::MORPH_CROSS)
18  ("Ellipse", cv::MORPH_ELLIPSE);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk((nrhs%2)==0 && nlhs<=1);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int shape = cv::MORPH_RECT;
38  Size ksize(3,3);
39  Point anchor(-1,-1);
40  for (int i=0; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "Shape")
43  shape = MorphShape[rhs[i+1].toString()];
44  else if (key == "KSize")
45  ksize = rhs[i+1].toSize();
46  else if (key == "Anchor")
47  anchor = rhs[i+1].toPoint();
48  else
49  mexErrMsgIdAndTxt("mexopencv:error",
50  "Unrecognized option %s", key.c_str());
51  }
52 
53  // Process
54  Mat elem = getStructuringElement(shape, ksize, anchor);
55  plhs[0] = MxArray(elem);
56 }
Mat getStructuringElement(int shape, Size ksize, Point anchor=Point(-1,-1))
MORPH_CROSS
STL namespace.
const ConstMap< string, int > MorphShape
Shape map for morphological operation for option processing.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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...
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
MORPH_RECT
STL class.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
T c_str(T... args)
MORPH_ELLIPSE
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927