mexopencv  0.1
mex interface for opencv library
boundingRect.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 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Process
28  Rect r;
29  if (rhs[0].isNumeric() || rhs[0].isLogical()) {
30  // points or mask
31  Mat curve(rhs[0].toMat(
32  rhs[0].isUint8() || rhs[0].isLogical() ? CV_8U :
33  (rhs[0].isFloat() ? CV_32F : CV_32S)));
34  r = boundingRect(curve);
35  }
36  else if (rhs[0].isCell()) {
37  // points
38  if (!rhs[0].isEmpty() && rhs[0].at<MxArray>(0).isFloat()) {
39  vector<Point2f> curve(rhs[0].toVector<Point2f>());
40  r = boundingRect(curve);
41  }
42  else {
43  vector<Point> curve(rhs[0].toVector<Point>());
44  r = boundingRect(curve);
45  }
46  }
47  else
48  mexErrMsgIdAndTxt("mexopencv:error", "Invalid input");
49  plhs[0] = MxArray(r);
50 }
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
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.