mexopencv  0.1
mex interface for opencv library
putText.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>=3 && (nrhs%2)==1 && nlhs<=1);
23 
24  // Argument vector
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26 
27  // Option processing
28  int fontFace = cv::FONT_HERSHEY_SIMPLEX;
29  int fontStyle = 0;
30  double fontScale = 1.0;
31  Scalar color;
32  int thickness = 1;
33  int lineType = cv::LINE_8;
34  bool bottomLeftOrigin = false;
35  for (int i=3; i<nrhs; i+=2) {
36  string key(rhs[i].toString());
37  if (key=="FontFace")
38  fontFace = FontFace[rhs[i+1].toString()];
39  else if (key=="FontStyle")
40  fontStyle = FontStyle[rhs[i+1].toString()];
41  else if (key=="FontScale")
42  fontScale = rhs[i+1].toDouble();
43  else if (key=="Color")
44  color = rhs[i+1].toScalar();
45  else if (key=="Thickness")
46  thickness = (rhs[i+1].isChar()) ?
47  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
48  else if (key=="LineType")
49  lineType = (rhs[i+1].isChar()) ?
50  LineType[rhs[i+1].toString()] : rhs[i+1].toInt();
51  else if (key=="BottomLeftOrigin")
52  bottomLeftOrigin = rhs[i+1].toBool();
53  else
54  mexErrMsgIdAndTxt("mexopencv:error","Unrecognized option");
55  }
56  fontFace |= fontStyle;
57 
58  // Process
59  Mat img(rhs[0].toMat());
60  string text(rhs[1].toString());
61  Point org(rhs[2].toPoint());
62  putText(img, text, org, fontFace, fontScale, color, thickness,
63  lineType, bottomLeftOrigin);
64  plhs[0] = MxArray(img);
65 }
const ConstMap< std::string, int > FontStyle
Font styles for drawing.
Definition: mexopencv.hpp:130
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: putText.cpp:19
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.
const ConstMap< std::string, int > FontFace
Font faces for drawing.
Definition: mexopencv.hpp:119