mexopencv  0.1
mex interface for opencv library
RotatedRect_.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>=2 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26  string method(rhs[0].toString());
27 
28  if (method == "points") {
29  nargchk(nrhs==2 && nlhs<=1);
30  RotatedRect rect(rhs[1].toRotatedRect());
31  Point2f pt[4];
32  rect.points(pt);
33  vector<Point2f> v(pt, pt+4);
34  plhs[0] = MxArray(Mat(v).reshape(1,0));
35  }
36  else if (method == "boundingRect") {
37  nargchk(nrhs==2 && nlhs<=1);
38  RotatedRect rect(rhs[1].toRotatedRect());
39  Rect r = rect.boundingRect();
40  plhs[0] = MxArray(r);
41  }
42  else if (method == "from3points") {
43  nargchk(nrhs==4 && nlhs<=1);
44  Point2f pt1(rhs[1].toPoint2f()),
45  pt2(rhs[2].toPoint2f()),
46  pt3(rhs[3].toPoint2f());
47  plhs[0] = MxArray(RotatedRect(pt1, pt2, pt3));
48  }
49  else
50  mexErrMsgIdAndTxt("mexopencv:error",
51  "Unrecognized method %s", method.c_str());
52 }
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.