mexopencv  0.1
mex interface for opencv library
niBlackThreshold.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 //TODO: https://github.com/Itseez/opencv_contrib/pull/542
15 
23 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
24 {
25  // Check the number of arguments
26  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
27 
28  // Argument vector
29  vector<MxArray> rhs(prhs, prhs+nrhs);
30 
31  // Option processing
32  double maxValue = 255;
33  int type = cv::THRESH_BINARY;
34  int blockSize = 5;
35  for (int i=2; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key == "MaxValue")
38  maxValue = rhs[i+1].toDouble();
39  else if (key == "Type")
40  type = ThreshType[rhs[i+1].toString()];
41  else if (key == "BlockSize")
42  blockSize = rhs[i+1].toInt();
43  else
44  mexErrMsgIdAndTxt("mexopencv:error",
45  "Unrecognized option %s", key.c_str());
46  }
47 
48  // Process
49  Mat src(rhs[0].toMat(CV_8U)), dst;
50  double delta = rhs[1].toDouble();
51  niBlackThreshold(src, dst, maxValue, type, blockSize, delta);
52  plhs[0] = MxArray(dst);
53 }
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.