mexopencv  3.4.1
MEX interface for OpenCV library
drawMarker.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 
13 namespace {
16  ("Cross", cv::MARKER_CROSS)
17  ("+", cv::MARKER_CROSS)
18  ("TiltedCross", cv::MARKER_TILTED_CROSS)
20  ("Star", cv::MARKER_STAR)
21  ("*", cv::MARKER_STAR)
22  ("Diamond", cv::MARKER_DIAMOND)
23  ("d", cv::MARKER_DIAMOND)
24  ("Square", cv::MARKER_SQUARE)
25  ("s", cv::MARKER_SQUARE)
26  ("TriangleUp", cv::MARKER_TRIANGLE_UP)
28  ("TriangleDown", cv::MARKER_TRIANGLE_DOWN)
30 }
31 
39 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
40 {
41  // Check the number of arguments
42  nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
43 
44  // Argument vector
45  vector<MxArray> rhs(prhs, prhs+nrhs);
46 
47  // Option processing
48  Scalar color;
49  int markerType = cv::MARKER_CROSS;
50  int markerSize = 20;
51  int thickness = 1;
52  int line_type = cv::LINE_8;
53  for (int i=2; i<nrhs; i+=2) {
54  string key(rhs[i].toString());
55  if (key == "Color")
56  color = (rhs[i+1].isChar()) ?
57  ColorType[rhs[i+1].toString()] : 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 }
MARKER_TILTED_CROSS
MARKER_SQUARE
const ConstMap< string, int > MarkerTypeMap
Marker types for option processing.
Definition: drawMarker.cpp:15
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: drawMarker.cpp:39
MARKER_STAR
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
MARKER_TRIANGLE_UP
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
MARKER_DIAMOND
const ConstMap< std::string, int > ThicknessType
Thickness type for drawing.
Definition: mexopencv.hpp:130
STL class.
Global constant definitions.
void drawMarker(Mat &img, Point position, const Scalar &color, int markerType=MARKER_CROSS, int markerSize=20, int thickness=1, int line_type=8)
T c_str(T... args)
MARKER_TRIANGLE_DOWN
const ConstMap< std::string, cv::Scalar > ColorType
Translates MATLAB color names (see ColorSpec) into OpenCV scalars.
Definition: mexopencv.hpp:55
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
MARKER_CROSS
cv::Mat toMat() const