mexopencv  3.4.1
MEX interface for OpenCV library
polylines.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  bool isClosed = true;
30  Scalar color;
31  int thickness = 1;
32  int lineType = cv::LINE_8;
33  int shift = 0;
34  for (int i=2; i<nrhs; i+=2) {
35  string key(rhs[i].toString());
36  if (key == "Color")
37  color = (rhs[i+1].isChar()) ?
38  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
39  else if (key == "Thickness")
40  thickness = (rhs[i+1].isChar()) ?
41  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
42  else if (key == "LineType")
43  lineType = (rhs[i+1].isChar()) ?
44  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
45  else if (key == "Shift")
46  shift = rhs[i+1].toInt();
47  else if (key == "Closed")
48  isClosed = rhs[i+1].toBool();
49  else
50  mexErrMsgIdAndTxt("mexopencv:error",
51  "Unrecognized option %s", key.c_str());
52  }
53 
54  // Process
55  Mat img(rhs[0].toMat());
56  vector<vector<Point> > pts(MxArrayToVectorVectorPoint<int>(rhs[1]));
57  polylines(img, pts, isClosed, color, thickness, lineType, shift);
58  plhs[0] = MxArray(img);
59 }
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void polylines(Mat &img, const Point *const *pts, const int *npts, int ncontours, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: polylines.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
const ConstMap< std::string, int > ThicknessType
Thickness type for drawing.
Definition: mexopencv.hpp:130
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