mexopencv  0.1
mex interface for opencv library
drawMarker.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
12 //TODO: https://github.com/Itseez/opencv/issues/5905
13 
14 namespace {
16 const ConstMap<string,int> MarkerTypeMap = ConstMap<string,int>
17  ("Cross", cv::MARKER_CROSS)
18  ("+", cv::MARKER_CROSS)
19  ("TiltedCross", cv::MARKER_TILTED_CROSS)
20  ("x", cv::MARKER_TILTED_CROSS)
21  ("Star", cv::MARKER_STAR)
22  ("*", cv::MARKER_STAR)
23  ("Diamond", cv::MARKER_DIAMOND)
24  ("d", cv::MARKER_DIAMOND)
25  ("Square", cv::MARKER_SQUARE)
26  ("s", cv::MARKER_SQUARE)
27  ("TriangleUp", cv::MARKER_TRIANGLE_UP)
28  ("^", cv::MARKER_TRIANGLE_UP)
29  ("TriangleDown", cv::MARKER_TRIANGLE_DOWN)
30  ("v", cv::MARKER_TRIANGLE_DOWN);
31 }
32 
40 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
41 {
42  // Check the number of arguments
43  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
44 
45  // Argument vector
46  vector<MxArray> rhs(prhs, prhs+nrhs);
47 
48  // Option processing
49  Scalar color;
50  int markerType = cv::MARKER_CROSS;
51  int markerSize = 20;
52  int thickness = 1;
53  int line_type = cv::LINE_8;
54  for (int i=2; i<nrhs; i+=2) {
55  string key(rhs[i].toString());
56  if (key == "Color")
57  color = rhs[i+1].toScalar();
58  else if (key == "MarkerType")
59  markerType = (rhs[i+1].isChar()) ?
60  MarkerTypeMap[rhs[i+1].toString()] : rhs[i+1].toInt();
61  else if (key == "MarkerSize")
62  markerSize = rhs[i+1].toInt();
63  else if (key == "Thickness")
64  thickness = (rhs[i+1].isChar()) ?
65  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
66  else if (key == "LineType")
67  line_type = (rhs[i+1].isChar()) ?
68  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
69  else
70  mexErrMsgIdAndTxt("mexopencv:error",
71  "Unrecognized option %s", key.c_str());
72  }
73 
74  // Process
75  Mat img(rhs[0].toMat());
76  Point position(rhs[1].toPoint());
77  drawMarker(img, position, color, markerType, markerSize, thickness,
78  line_type);
79  plhs[0] = MxArray(img);
80 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: drawMarker.cpp:40
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.
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927