mexopencv  3.4.1
MEX interface for OpenCV library
ellipse2Poly.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/imgproc.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>=2 && (nrhs%2)==0 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  int angle = 0;
30  int arcStart = 0;
31  int arcEnd = 360;
32  int delta = 5;
33  bool doublePrecision = false;
34  for (int i=2; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "Angle")
37  angle = rhs[i+1].toInt();
38  else if (key == "StartAngle")
39  arcStart = rhs[i+1].toInt();
40  else if (key == "EndAngle")
41  arcEnd = rhs[i+1].toInt();
42  else if (key == "Delta")
43  delta = rhs[i+1].toInt();
44  else if (key == "DoublePrecision")
45  doublePrecision = rhs[i+1].toBool();
46  else
47  mexErrMsgIdAndTxt("mexopencv:error",
48  "Unrecognized option %s", key.c_str());
49  }
50 
51  // Process
52  if (doublePrecision) {
53  Point2d center(rhs[0].toPoint_<double>());
54  Size2d axes(rhs[1].toSize_<double>());
55  vector<Point2d> pts;
56  ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
57  plhs[0] = MxArray(Mat(pts,false).reshape(1,0)); // Nx2 numeric matrix
58  }
59  else {
60  Point center(rhs[0].toPoint());
61  Size axes(rhs[1].toSize());
62  vector<Point> pts;
63  ellipse2Poly(center, axes, angle, arcStart, arcEnd, delta, pts);
64  plhs[0] = MxArray(Mat(pts,false).reshape(1,0)); // Nx2 numeric matrix
65  }
66 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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...
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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
STL class.
Global constant definitions.
T c_str(T... args)
void ellipse2Poly(Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, std::vector< Point > &pts)