mexopencv  3.4.1
MEX interface for OpenCV library
fillPoly.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  Point offset;
33  for (int i=2; i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key == "Color")
36  color = (rhs[i+1].isChar()) ?
37  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
38  else if (key == "LineType")
39  lineType = (rhs[i+1].isChar()) ?
40  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
41  else if (key == "Shift")
42  shift = rhs[i+1].toInt();
43  else if (key == "Offset")
44  offset = rhs[i+1].toPoint();
45  else
46  mexErrMsgIdAndTxt("mexopencv:error",
47  "Unrecognized option %s", key.c_str());
48  }
49 
50  // Process
51  Mat img(rhs[0].toMat());
52  vector<vector<Point> > pts(MxArrayToVectorVectorPoint<int>(rhs[1]));
53  fillPoly(img, pts, color, lineType, shift, offset);
54  plhs[0] = MxArray(img);
55 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: fillPoly.cpp:20
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
void fillPoly(Mat &img, const Point **pts, const int *npts, int ncontours, const Scalar &color, int lineType=LINE_8, int shift=0, Point offset=Point())
STL class.
Global constant definitions.
T c_str(T... args)
const ConstMap< std::string, cv::Scalar > ColorType
Translates MATLAB color names (see ColorSpec) into OpenCV scalars.
Definition: mexopencv.hpp:55
cv::Mat toMat() const