mexopencv  3.4.1
MEX interface for OpenCV library
drawContours.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 contourIdx = -1;
30  Scalar color(Scalar::all(255));
31  int thickness = 1;
32  int lineType = cv::LINE_8;
33  vector<Vec4i> hierarchy;
34  int maxLevel = INT_MAX;
35  Point offset;
36  for (int i=2; i<nrhs; i+=2) {
37  string key(rhs[i].toString());
38  if (key == "ContourIdx")
39  contourIdx = rhs[i+1].toInt();
40  else if (key == "Color")
41  color = (rhs[i+1].isChar()) ?
42  ColorType[rhs[i+1].toString()] : rhs[i+1].toScalar();
43  else if (key == "Thickness")
44  thickness = (rhs[i+1].isChar()) ?
45  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
46  else if (key == "LineType")
47  lineType = (rhs[i+1].isChar()) ?
48  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
49  else if (key == "Hierarchy")
50  //hierarchy = MxArrayToVectorVec<int,4>(rhs[i+1]);
51  hierarchy = rhs[i+1].toVector<Vec4i>();
52  else if (key == "MaxLevel")
53  maxLevel = rhs[i+1].toInt();
54  else if (key == "Offset")
55  offset = rhs[i+1].toPoint();
56  else
57  mexErrMsgIdAndTxt("mexopencv:error",
58  "Unrecognized option %s", key.c_str());
59  }
60 
61  // Process
62  Mat image(rhs[0].toMat());
63  vector<vector<Point> > contours(MxArrayToVectorVectorPoint<int>(rhs[1]));
64  drawContours(image, contours, contourIdx, color, thickness, lineType,
65  hierarchy, maxLevel, offset);
66  plhs[0] = MxArray(image);
67 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void drawContours(InputOutputArray image, InputArrayOfArrays contours, int contourIdx, const Scalar &color, int thickness=1, int lineType=LINE_8, InputArray hierarchy=noArray(), int maxLevel=INT_MAX, Point offset=Point())
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
static Scalar_< double > all(double v0)
cv::Mat toMat() const