19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
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();
37 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
41 double threshold1 = 0, threshold2 = 0;
42 if (rhs[1].numel()==1) {
43 threshold2 = rhs[1].toDouble();
44 threshold1 = 0.4 * threshold2;
46 else if (rhs[1].numel()==2) {
47 Scalar s(rhs[1].toScalar());
52 mexErrMsgIdAndTxt(
"mexopencv:error",
"Invalid argument");
55 Mat image(rhs[0].toMat(CV_8U)), edges;
56 Canny(image, edges, threshold1, threshold2, apertureSize, L2gradient);
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.