関数getTextSizeは、指定したテキストを含むボックスの概算サイズを計算して返す。すなわち、以下のコードはテキストと、それを囲むタイトなボックス、およびベースラインを描画する: :
String text =
"Funny text inside the box";
int fontHeight = 60;
int thickness = -1;
int baseline=0;
ft2->loadFontData( "./mplus-1p-regular.ttf", 0 );
Size textSize = ft2->getTextSize(text,
fontHeight,
thickness,
&baseline);
if(thickness > 0){
baseline += thickness;
}
(img.rows + textSize.
height) / 2);
ft2->putText(img, text, textOrg, fontHeight,
n-dimensional dense array class
Definition mat.hpp:840
static Scalar_< double > all(double v0)
Template class for specifying the size of an image or rectangle.
Definition types.hpp:335
_Tp height
the height
Definition types.hpp:363
_Tp width
the width
Definition types.hpp:362
Point2i Point
Definition types.hpp:209
std::string String
Definition cvstd.hpp:151
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
#define CV_8UC3
Definition interface.h:90
Ptr< FreeType2 > createFreeType2()
Create FreeType2 Instance.
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a line segment connecting two points.
@ LINE_8
8-connected line
Definition imgproc.hpp:899