mexopencv  3.4.1
MEX interface for OpenCV library
groupRectangles.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/objdetect.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=3);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  int groupThreshold = 1;
30  double eps = 0.2;
31  vector<int> weights;
32  vector<double> levelWeights;
33  for (int i=1; i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key == "Thresh")
36  groupThreshold = rhs[i+1].toInt();
37  else if (key == "EPS")
38  eps = rhs[i+1].toDouble();
39  else if (key == "Weights")
40  weights = rhs[i+1].toVector<int>();
41  else if (key == "LevelWeights")
42  levelWeights = rhs[i+1].toVector<double>();
43  else
44  mexErrMsgIdAndTxt("mexopencv:error",
45  "Unrecognized option %s", key.c_str());
46  }
47 
48  // Process
49  vector<Rect> rectList(rhs[0].toVector<Rect>());
50  if ((!weights.empty() && weights.size() != rectList.size()) ||
51  (!levelWeights.empty() && levelWeights.size() != rectList.size()))
52  mexErrMsgIdAndTxt("mexopencv:error", "Vectors are the wrong size");
53  groupRectangles(rectList, groupThreshold, eps,
54  (nlhs>1 || !weights.empty() ? &weights : NULL),
55  (nlhs>2 || !levelWeights.empty() ? &levelWeights : NULL));
56  plhs[0] = (rhs[0].isNumeric()) ?
57  MxArray(Mat(rectList, false).reshape(1,0)) : // Nx4
58  MxArray(rectList); // {[x,y,w,h], ...}
59  if (nlhs > 1)
60  plhs[1] = MxArray(weights);
61  if (nlhs > 2)
62  plhs[2] = MxArray(levelWeights);
63 }
T empty(T... args)
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
Mat reshape(int cn, int rows=0) const
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
void groupRectangles(std::vector< Rect > &rectList, int groupThreshold, double eps=0.2)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
T size(T... args)
STL class.
Global constant definitions.
T c_str(T... args)
static softfloat eps()