mexopencv  3.4.1
MEX interface for OpenCV library
Laplacian.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  int ksize = 1;
31  double scale = 1;
32  double delta = 0;
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].toInt();
41  else if (key == "Scale")
42  scale = rhs[i+1].toDouble();
43  else if (key == "Delta")
44  delta = rhs[i+1].toDouble();
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  Laplacian(src, dst, ddepth, ksize, scale, delta, 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
void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
STL namespace.
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...
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:66
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 mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Laplacian.cpp:20
STL class.
Global constant definitions.
T c_str(T... args)
BORDER_DEFAULT
cv::Mat toMat() const