mexopencv  0.1
mex interface for opencv library
drawContours.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int contourIdx = -1;
29  Scalar color(Scalar::all(255));
30  int thickness = 1;
31  int lineType = cv::LINE_8;
32  vector<Vec4i> hierarchy;
33  int maxLevel = INT_MAX;
34  Point offset;
35  for (int i=2; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key=="ContourIdx")
38  contourIdx = rhs[i+1].toInt();
39  else if (key=="Color")
40  color = rhs[i+1].toScalar();
41  else if (key=="Thickness")
42  thickness = (rhs[i+1].isChar()) ?
43  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
44  else if (key=="LineType")
45  lineType = (rhs[i+1].isChar()) ?
46  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
47  else if (key=="Hierarchy")
48  //hierarchy = MxArrayToVectorVec<int,4>(rhs[i+1]);
49  hierarchy = rhs[i+1].toVector<Vec4i>();
50  else if (key=="MaxLevel")
51  maxLevel = rhs[i+1].toInt();
52  else if (key=="Offset")
53  offset = rhs[i+1].toPoint();
54  else
55  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
56  }
57 
58  // Process
59  Mat image(rhs[0].toMat());
60  vector<vector<Point> > contours(MxArrayToVectorVectorPoint<int>(rhs[1]));
61  drawContours(image, contours, contourIdx, color, thickness, lineType,
62  hierarchy, maxLevel, offset);
63  plhs[0] = MxArray(image);
64 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< std::string, int > LineType
Line type for drawing.
Definition: mexopencv.hpp:109
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
const ConstMap< std::string, int > ThicknessType
Thickness type for drawing.
Definition: mexopencv.hpp:115
Global constant definitions.