mexopencv  3.4.1
MEX interface for OpenCV library
Sobel.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  ("Scharr", CV_SCHARR);
17 }
18 
26 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
27 {
28  // Check the number of arguments
29  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
30 
31  // Argument vector
32  vector<MxArray> rhs(prhs, prhs+nrhs);
33 
34  // Option processing
35  int ddepth = -1;
36  int dx = 1;
37  int dy = 1;
38  int ksize = 3;
39  double scale = 1;
40  double delta = 0;
41  int borderType = cv::BORDER_DEFAULT;
42  for (int i=1; i<nrhs; i+=2) {
43  string key(rhs[i].toString());
44  if (key == "DDepth")
45  ddepth = (rhs[i+1].isChar()) ?
46  ClassNameMap[rhs[i+1].toString()] : rhs[i+1].toInt();
47  else if (key == "XOrder")
48  dx = rhs[i+1].toInt();
49  else if (key == "YOrder")
50  dy = rhs[i+1].toInt();
51  else if (key == "KSize")
52  ksize = (rhs[i+1].isChar()) ?
53  KSizeMap[rhs[i+1].toString()] : rhs[i+1].toInt();
54  else if (key == "Scale")
55  scale = rhs[i+1].toDouble();
56  else if (key == "Delta")
57  delta = rhs[i+1].toDouble();
58  else if (key == "BorderType")
59  borderType = BorderType[rhs[i+1].toString()];
60  else
61  mexErrMsgIdAndTxt("mexopencv:error",
62  "Unrecognized option %s", key.c_str());
63  }
64 
65  // Process
66  Mat src(rhs[0].toMat()), dst;
67  Sobel(src, dst, ddepth, dx, dy, ksize, scale, delta, borderType);
68  plhs[0] = MxArray(dst);
69 }
const ConstMap< string, int > KSizeMap
KSize map for option processing.
Definition: Sobel.cpp:15
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 Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
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
STL class.
Global constant definitions.
T c_str(T... args)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Sobel.cpp:26
BORDER_DEFAULT
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
CV_SCHARR
cv::Mat toMat() const