OpenCV 4.12.0
开源计算机视觉
加载中...
搜索中...
无匹配项
cv::freetype::FreeType2 类参考抽象类

#include <opencv2/freetype.hpp>

cv::freetype::FreeType2 的协作图

公共成员函数

virtual Size getTextSize (const String &text, int fontHeight, int thickness, int *baseLine)=0
 计算文本字符串的宽度和高度。
 
virtual void loadFontData (char *pBuf, size_t bufSize, int idx)=0
 加载字体数据。
 
virtual void loadFontData (String fontFileName, int idx)=0
 加载字体数据。
 
virtual void putText (InputOutputArray img, const String &text, Point org, int fontHeight, Scalar color, int thickness, int line_type, bool bottomLeftOrigin)=0
 绘制文本字符串。
 
virtual void setSplitNumber (int num)=0
 设置从贝塞尔曲线到直线的分割数量。
 
- 继承自 cv::Algorithm 的公共成员函数
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 清除算法状态。
 
virtual bool empty () const
 如果 Algorithm 为空(例如,在开始时或在不成功的读取之后),则返回 true。
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 从文件存储中读取算法参数。
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 将算法参数存储到文件存储中。
 
void write (FileStorage &fs, const String &name) const
 

额外的继承成员

- 继承自 cv::Algorithm 的静态公共成员函数
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 从文件中加载算法。
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 从字符串加载算法。
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 从文件节点读取算法。
 
- 继承自 cv::Algorithm 的保护成员函数
void writeFormat (FileStorage &fs) const
 

成员函数文档

◆ getTextSize()

virtual Size cv::freetype::FreeType2::getTextSize ( const String & text,
int fontHeight,
int thickness,
int * baseLine )
纯虚函数

计算文本字符串的宽度和高度。

getTextSize 函数计算并返回一个包含指定文本的框的大概大小。也就是说,以下代码渲染一些文本,它周围的紧密框和基线:

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 维密集数组类
定义 mat.hpp:830
static Scalar_< double > all(double v0)
用于指定图像或矩形大小的模板类。
Definition types.hpp:335
_Tp height
高度
Definition types.hpp:363
_Tp width
宽度
Definition types.hpp:362
typedef Point_< double > 
Point2i Point
Definition types.hpp:209
std::string String
定义 cvstd.hpp:151
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
CV_8UC3
#define CV_8UC3
Ptr< FreeType2 > createFreeType2()
创建 FreeType2 实例。
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制一个简单、粗或填充的矩形。
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
绘制连接两点的线段。
@ LINE_8
8 连接线
Definition imgproc.hpp:895
参数
text输入文本字符串。
fontHeight以像素为单位绘制字体大小。
thickness用于渲染文本的线条粗细。 有关详细信息,请参见 putText。
[输出]baseLine基线相对于最底端文本点的 y 坐标。
返回
包含指定文本的框的大小。
另请参见
cv::putText

◆ loadFontData() [1/2]

virtual void cv::freetype::FreeType2::loadFontData ( char * pBuf,
size_t bufSize,
int idx )
纯虚函数

加载字体数据。

loadFontData 函数从内存加载字体数据。 数据不会被复制,用户需要确保数据的生命周期至少与 FreeType2 一样长。 在销毁 FreeType2 对象后,可以安全地释放缓冲区。

参数
pBuf指向包含字体数据的缓冲区的指针
bufSize缓冲区大小
idxface_index 用于在单个文件中选择字体。

◆ loadFontData() [2/2]

virtual void cv::freetype::FreeType2::loadFontData ( String fontFileName,
int idx )
纯虚函数

加载字体数据。

loadFontData 函数从文件加载字体数据。

参数
fontFileName字体文件名
idxface_index 用于在单个文件中选择字体。

◆ 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 )
纯虚函数

绘制文本字符串。

putText 函数在图像中渲染指定的文本字符串。 无法使用指定字体渲染的符号将替换为“豆腐”或不绘制。

参数
img图像。(仅支持 8UC1/8UC3/8UC4 2D 矩阵。)
text要绘制的文本字符串。
org图像中文本字符串的左下角/左上角。
fontHeight以像素为单位绘制字体大小。
color文本颜色。
thickness用于绘制文本的线条粗细。当为负数时,字形将被填充。否则,将使用此粗细绘制字形。
line_type线条类型。 有关详细信息,请参见 line。
bottomLeftOrigin为 true 时,图像数据原点位于左下角。 否则,它位于左上角。

◆ setSplitNumber()

virtual void cv::freetype::FreeType2::setSplitNumber ( int num)
纯虚函数

设置从贝塞尔曲线到直线的分割数量。

setSplitNumber 函数设置从贝塞尔曲线到直线的分割点数量。 如果要绘制大型字形,则越大越好。 如果要绘制小字形,则越小越好。

参数
num从贝塞尔曲线到直线的分割点数量

此类文档由以下文件生成