mexopencv  0.1
mex interface for opencv library
adaptiveThreshold.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 namespace {
14 const ConstMap<string,int> AdaptiveMethod = ConstMap<string,int>
15  ("Mean", cv::ADAPTIVE_THRESH_MEAN_C)
16  ("Gaussian", cv::ADAPTIVE_THRESH_GAUSSIAN_C);
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  double maxValue = 255;
36  int adaptiveMethod = cv::ADAPTIVE_THRESH_MEAN_C;
37  int thresholdType = cv::THRESH_BINARY;
38  int blockSize = 3;
39  double C = 5;
40  for (int i=1; i<nrhs; i+=2) {
41  string key(rhs[i].toString());
42  if (key == "MaxValue")
43  maxValue = rhs[i+1].toDouble();
44  else if (key == "Method")
45  adaptiveMethod = AdaptiveMethod[rhs[i+1].toString()];
46  else if (key == "Type")
47  thresholdType = ThreshType[rhs[i+1].toString()];
48  else if (key == "BlockSize")
49  blockSize = rhs[i+1].toInt();
50  else if (key == "C")
51  C = rhs[i+1].toDouble();
52  else
53  mexErrMsgIdAndTxt("mexopencv:error",
54  "Unrecognized option %s", key.c_str());
55  }
56 
57  // Process
58  Mat src(rhs[0].toMat(CV_8U)), dst;
59  adaptiveThreshold(src, dst, maxValue, adaptiveMethod, thresholdType,
60  blockSize, C);
61  plhs[0] = MxArray(dst);
62 }
const ConstMap< std::string, int > ThreshType
Thresholding type map for option processing.
Definition: mexopencv.hpp:79
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927