mexopencv  0.1
mex interface for opencv library
getTextSize.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>=1 && (nrhs%2)==1 && nlhs<=2);
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  int thickness = 1;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key=="FontFace")
35  fontFace = FontFace[rhs[i+1].toString()];
36  else if (key=="FontStyle")
37  fontStyle = FontStyle[rhs[i+1].toString()];
38  else if (key=="FontScale")
39  fontScale = rhs[i+1].toDouble();
40  else if (key=="Thickness")
41  thickness = (rhs[i+1].isChar()) ?
42  ThicknessType[rhs[i+1].toString()] : rhs[i+1].toInt();
43  else
44  mexErrMsgIdAndTxt("mexopencv:error", "Unrecognized option");
45  }
46  fontFace |= fontStyle;
47 
48  // Process
49  const string text(rhs[0].toString());
50  int baseLine = 0;
51  Size s = getTextSize(text, fontFace, fontScale, thickness, &baseLine);
52  plhs[0] = MxArray(s);
53  if (nlhs>1)
54  plhs[1] = MxArray(baseLine);
55 }
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: getTextSize.cpp:19
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