mexopencv  0.1
mex interface for opencv library
Canny.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int apertureSize = 3;
29  bool L2gradient = false;
30  for (int i=2; i<nrhs; i+=2) {
31  string key(rhs[i].toString());
32  if (key=="ApertureSize")
33  apertureSize = rhs[i+1].toInt();
34  else if (key=="L2Gradient")
35  L2gradient = rhs[i+1].toBool();
36  else
37  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
38  }
39 
40  // Second argument
41  double threshold1 = 0, threshold2 = 0;
42  if (rhs[1].numel()==1) {
43  threshold2 = rhs[1].toDouble();
44  threshold1 = 0.4 * threshold2;
45  }
46  else if (rhs[1].numel()==2) {
47  Scalar s(rhs[1].toScalar());
48  threshold1 = s[0];
49  threshold2 = s[1];
50  }
51  else
52  mexErrMsgIdAndTxt("mexopencv:error","Invalid argument");
53 
54  // Process
55  Mat image(rhs[0].toMat(CV_8U)), edges;
56  Canny(image, edges, threshold1, threshold2, apertureSize, L2gradient);
57  plhs[0] = MxArray(edges);
58 }
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.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Canny.cpp:19