OpenCV 5.0.0-pre
Open Source Computer Vision
Loading...
Searching...
No Matches
cv::freetype::FreeType2 Class Referenceabstract

#include <opencv2/freetype.hpp>

Collaboration diagram for cv::freetype::FreeType2:

Public Member Functions

virtual Size getTextSize (const String &text, int fontHeight, int thickness, int *baseLine)=0
 Calculates the width and height of a text string.
 
virtual void loadFontData (char *pBuf, size_t bufSize, int idx)=0
 Load font data.
 
virtual void loadFontData (String fontFileName, int idx)=0
 Load font data.
 
virtual void putText (InputOutputArray img, const String &text, Point org, int fontHeight, Scalar color, int thickness, int line_type, bool bottomLeftOrigin)=0
 Draws a text string.
 
virtual void setSplitNumber (int num)=0
 Set Split Number from Bezier-curve to line.
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state.
 
virtual bool empty () const
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage.
 
virtual void save (const String &filename) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage.
 
void write (FileStorage &fs, const String &name) const
 

Additional Inherited Members

- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 Loads algorithm from the file.
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String.
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 Reads algorithm from the file node.
 
- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Member Function Documentation

◆ getTextSize()

virtual Size cv::freetype::FreeType2::getTextSize ( const String & text,
int fontHeight,
int thickness,
int * baseLine )
pure virtual

Calculates the width and height of a text string.

The function getTextSize calculates and returns the approximate size of a box that contains the specified text. That is, the following code renders some text, the tight box surrounding it, and the baseline: :

String text = "Funny text inside the box";
int fontHeight = 60;
int thickness = -1;
int linestyle = LINE_8;
Mat img(600, 800, CV_8UC3, Scalar::all(0));
int baseline=0;
ft2->loadFontData( "./mplus-1p-regular.ttf", 0 );
Size textSize = ft2->getTextSize(text,
fontHeight,
thickness,
&baseline);
if(thickness > 0){
baseline += thickness;
}
// center the text
Point textOrg((img.cols - textSize.width) / 2,
(img.rows + textSize.height) / 2);
// draw the box
rectangle(img, textOrg + Point(0, baseline),
textOrg + Point(textSize.width, -textSize.height),
Scalar(0,255,0),1,8);
// ... and the baseline first
line(img, textOrg + Point(0, thickness),
textOrg + Point(textSize.width, thickness),
Scalar(0, 0, 255),1,8);
// then put the text itself
ft2->putText(img, text, textOrg, fontHeight,
Scalar::all(255), thickness, linestyle, true );
n-dimensional dense array class
Definition mat.hpp:951
static Scalar_< double > all(double v0)
Template class for specifying the size of an image or rectangle.
Definition types.hpp:338
_Tp height
the height
Definition types.hpp:366
_Tp width
the width
Definition types.hpp:365
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:79
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:896
Parameters
textInput text string.
fontHeightDrawing font size by pixel unit.
thicknessThickness of lines used to render the text. See putText for details.
[out]baseLiney-coordinate of the baseline relative to the bottom-most text point.
Returns
The size of a box that contains the specified text.
See also
cv::putText

◆ loadFontData() [1/2]

virtual void cv::freetype::FreeType2::loadFontData ( char * pBuf,
size_t bufSize,
int idx )
pure virtual

Load font data.

The function loadFontData loads font data from memory. The data is not copied, the user needs to make sure the data lives at least as long as FreeType2. After the FreeType2 object is destroyed, the buffer can be safely deallocated.

Parameters
pBufpointer to buffer containing font data
bufSizesize of buffer
idxface_index to select a font faces in a single file.

◆ loadFontData() [2/2]

virtual void cv::freetype::FreeType2::loadFontData ( String fontFileName,
int idx )
pure virtual

Load font data.

The function loadFontData loads font data from file.

Parameters
fontFileNameFontFile Name
idxface_index to select a font faces in a single file.

◆ putText()

virtual void cv::freetype::FreeType2::putText ( InputOutputArray img,
const String & text,
Point org,
int fontHeight,
Scalar color,
int thickness,
int line_type,
bool bottomLeftOrigin )
pure virtual

Draws a text string.

The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn.

Parameters
imgImage. (Only 8UC1/8UC3/8UC4 2D mat is supported.)
textText string to be drawn.
orgBottom-left/Top-left corner of the text string in the image.
fontHeightDrawing font size by pixel unit.
colorText color.
thicknessThickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness.
line_typeLine type. See the line for details.
bottomLeftOriginWhen true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.

◆ setSplitNumber()

virtual void cv::freetype::FreeType2::setSplitNumber ( int num)
pure virtual

Set Split Number from Bezier-curve to line.

The function setSplitNumber set the number of split points from bezier-curve to line. If you want to draw large glyph, large is better. If you want to draw small glyph, small is better.

Parameters
numnumber of split points from bezier-curve to line

The documentation for this class was generated from the following file: