mexopencv  0.1
mex interface for opencv library
groupRectangles.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>=1 && (nrhs%2)==1 && nlhs<=3);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int groupThreshold = 1;
29  double eps = 0.2;
30  vector<int> weights;
31  vector<double> levelWeights;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Thresh")
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>();
42  else
43  mexErrMsgIdAndTxt("mexopencv:error",
44  "Unrecognized option %s", key.c_str());
45  }
46 
47  // Process
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)) : // Nx4
57  MxArray(rectList); // {[x,y,w,h], ...}
58  if (nlhs > 1)
59  plhs[1] = MxArray(weights);
60  if (nlhs > 2)
61  plhs[2] = MxArray(levelWeights);
62 }
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
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Global constant definitions.