mexopencv  3.4.1
MEX interface for OpenCV library
fillConvexPoly.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  Scalar color;
30  int lineType = cv::LINE_8;
31  int shift = 0;
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Color")
35  color = (rhs[i+1].isChar()) ?
36  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
37  else if (key == "LineType")
38  lineType = (rhs[i+1].isChar()) ?
39  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
40  else if (key == "Shift")
41  shift = rhs[i+1].toInt();
42  else
43  mexErrMsgIdAndTxt("mexopencv:error",
44  "Unrecognized option %s", key.c_str());
45  }
46 
47  // Process
48  Mat img(rhs[0].toMat());
49  vector<Point> pts(rhs[1].toVector<Point>());
50  fillConvexPoly(img, pts, color, lineType, shift);
51  plhs[0] = MxArray(img);
52 }
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...
const ConstMap< std::string, int > LineType
Line type for drawing.
Definition: mexopencv.hpp:124
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 fillConvexPoly(Mat &img, const Point *pts, int npts, const Scalar &color, int lineType=LINE_8, int shift=0)
const ConstMap< std::string, cv::Scalar > ColorType
Translates MATLAB color names (see ColorSpec) into OpenCV scalars.
Definition: mexopencv.hpp:55
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Mat toMat() const