mexopencv  3.4.1
MEX interface for OpenCV library
sqrBoxFilter.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 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  int ddepth = -1;
30  Size ksize(5,5);
31  Point anchor(-1,-1);
32  bool normalize = true;
33  int borderType = cv::BORDER_DEFAULT;
34  for (int i=1; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "DDepth")
37  ddepth = (rhs[i+1].isChar()) ?
38  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
39  else if (key == "KSize")
40  ksize = rhs[i+1].toSize();
41  else if (key == "Anchor")
42  anchor = rhs[i+1].toPoint();
43  else if (key == "Normalize")
44  normalize = rhs[i+1].toBool();
45  else if (key == "BorderType")
46  borderType = BorderType[rhs[i+1].toString()];
47  else
48  mexErrMsgIdAndTxt("mexopencv:error",
49  "Unrecognized option %s", key.c_str());
50  }
51 
52  // Process
53  Mat src(rhs[0].toMat()), dst;
54  sqrBoxFilter(src, dst, ddepth, ksize, anchor, normalize, borderType);
55  plhs[0] = MxArray(dst);
56 }
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
Definition: mexopencv.hpp:27
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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...
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:66
static Vec< _Tp, cn > normalize(const Vec< _Tp, cn > &v)
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
void sqrBoxFilter(InputArray _src, OutputArray _dst, int ddepth, Size ksize, Point anchor=Point(-1, -1), bool normalize=true, int borderType=BORDER_DEFAULT)
STL class.
Global constant definitions.
T c_str(T... args)
BORDER_DEFAULT
cv::Mat toMat() const