19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=3);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
28 int groupThreshold = 1;
31 vector<double> levelWeights;
32 for (
int i=1; i<nrhs; i+=2) {
33 string key(rhs[i].toString());
35 groupThreshold = rhs[i+1].toInt();
36 else if (key ==
"EPS")
37 eps = rhs[i+1].toDouble();
38 else if (key ==
"Weights")
39 weights = rhs[i+1].toVector<
int>();
40 else if (key ==
"LevelWeights")
41 levelWeights = rhs[i+1].toVector<
double>();
43 mexErrMsgIdAndTxt(
"mexopencv:error",
44 "Unrecognized option %s", key.c_str());
48 vector<Rect> rectList(rhs[0].toVector<Rect>());
49 if ((!weights.empty() && weights.size() != rectList.size()) ||
50 (!levelWeights.empty() && levelWeights.size() != rectList.size()))
51 mexErrMsgIdAndTxt(
"mexopencv:error",
"Vectors are the wrong size");
52 groupRectangles(rectList, groupThreshold, eps,
53 (nlhs>1 || !weights.empty() ? &weights : NULL),
54 (nlhs>2 || !levelWeights.empty() ? &levelWeights : NULL));
55 plhs[0] = (rhs[0].isNumeric()) ?
56 MxArray(Mat(rectList,
false).reshape(1,0)) :
61 plhs[2] =
MxArray(levelWeights);
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.