mexopencv  3.4.1
MEX interface for OpenCV library
adaptiveThreshold.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 {
17  ("Gaussian", cv::ADAPTIVE_THRESH_GAUSSIAN_C);
18 }
19 
27 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
28 {
29  // Check the number of arguments
30  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
31 
32  // Argument vector
33  vector<MxArray> rhs(prhs, prhs+nrhs);
34 
35  // Option processing
36  double maxValue = 255;
37  int adaptiveMethod = cv::ADAPTIVE_THRESH_MEAN_C;
38  int thresholdType = cv::THRESH_BINARY;
39  int blockSize = 3;
40  double C = 5;
41  for (int i=1; i<nrhs; i+=2) {
42  string key(rhs[i].toString());
43  if (key == "MaxValue")
44  maxValue = rhs[i+1].toDouble();
45  else if (key == "Method")
46  adaptiveMethod = AdaptiveMethod[rhs[i+1].toString()];
47  else if (key == "Type")
48  thresholdType = ThreshType[rhs[i+1].toString()];
49  else if (key == "BlockSize")
50  blockSize = rhs[i+1].toInt();
51  else if (key == "C")
52  C = rhs[i+1].toDouble();
53  else
54  mexErrMsgIdAndTxt("mexopencv:error",
55  "Unrecognized option %s", key.c_str());
56  }
57 
58  // Process
59  Mat src(rhs[0].toMat(CV_8U)), dst;
60  adaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType,
61  blockSize, C);
62  plhs[0] = MxArray(dst);
63 }
void adaptiveThreshold(InputArray src, OutputArray dst, double maxValue, int adaptiveMethod, int thresholdType, int blockSize, double C)
#define CV_8U
const ConstMap< std::string, int > ThreshType
Thresholding type map for option processing.
Definition: mexopencv.hpp:94
STL namespace.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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
const ConstMap< string, int > AdaptiveMethod
Adaptive thresholding type map for option processing.
ADAPTIVE_THRESH_GAUSSIAN_C
THRESH_BINARY
STL class.
Global constant definitions.
T c_str(T... args)
ADAPTIVE_THRESH_MEAN_C
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
cv::Mat toMat() const