mexopencv  3.4.1
MEX interface for OpenCV library
thinning.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/ximgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 using namespace cv::ximgproc;
13 
14 namespace {
18  ("GuoHall", cv::ximgproc::THINNING_GUOHALL);
19 }
20 
28 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
29 {
30  // Check the number of arguments
31  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
32 
33  // Argument vector
34  vector<MxArray> rhs(prhs, prhs+nrhs);
35 
36  // Option processing
37  int thinningType = cv::ximgproc::THINNING_ZHANGSUEN;
38  for (int i=1; i<nrhs; i+=2) {
39  string key(rhs[i].toString());
40  if (key == "ThinningType")
41  thinningType = ThinningTypesMap[rhs[i+1].toString()];
42  else
43  mexErrMsgIdAndTxt("mexopencv:error",
44  "Unrecognized option %s", key.c_str());
45  }
46 
47  // Process
48  Mat src(rhs[0].toMat(CV_8U)), dst;
49  thinning(src, dst, thinningType);
50  plhs[0] = MxArray(dst);
51 }
const ConstMap< string, int > ThinningTypesMap
Thinning techniques for option processing.
Definition: thinning.cpp:16
#define CV_8U
STL namespace.
void thinning(InputArray src, OutputArray dst, int thinningType=THINNING_ZHANGSUEN)
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: thinning.cpp:28
STL class.
Global constant definitions.
T c_str(T... args)
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const