19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=4);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
32 bool fixedRange =
false;
33 bool maskOnly =
false;
35 for (
int i=3; i<nrhs; i+=2) {
36 string key(rhs[i].toString());
38 mask = rhs[i+1].toMat(CV_8U);
39 else if (key==
"LoDiff")
40 loDiff = rhs[i+1].toScalar();
41 else if (key==
"UpDiff")
42 upDiff = rhs[i+1].toScalar();
43 else if (key==
"Connectivity")
44 connectivity = rhs[i+1].toInt();
45 else if (key==
"FixedRange")
46 fixedRange = rhs[i+1].toBool();
47 else if (key==
"MaskOnly")
48 maskOnly = rhs[i+1].toBool();
49 else if (key==
"MaskFillValue")
50 maskVal = rhs[i+1].toInt();
52 mexErrMsgIdAndTxt(
"mexopencv:error",
53 "Unrecognized option %s", key.c_str());
55 if (connectivity!=4 && connectivity!=8)
56 mexErrMsgIdAndTxt(
"mexopencv:error",
"Connectivity must be 4 or 8");
57 if (maskVal<0 || maskVal>255)
58 mexErrMsgIdAndTxt(
"mexopencv:error",
"Fill value between 1 and 255");
59 maskVal = (maskVal==0 && maskOnly) ? 1 : maskVal;
60 int flags = connectivity |
62 (fixedRange ? cv::FLOODFILL_FIXED_RANGE : 0) |
63 (maskOnly ? cv::FLOODFILL_MASK_ONLY : 0);
66 Mat img(rhs[0].toMat(rhs[0].isUint8() ? CV_8U :
67 (rhs[0].isInt32() ? CV_32S : CV_32F)));
68 Point seed(rhs[1].toPoint());
69 Scalar newVal(rhs[2].toScalar());
73 area = floodFill(img, mask, seed, newVal, (nlhs>1 ? &rect : NULL),
74 loDiff, upDiff, flags);
76 area = floodFill(img, seed, newVal, (nlhs>1 ? &rect : NULL),
77 loDiff, upDiff, flags);
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.