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從貝塞爾曲線到直線的分割點數量

此類文件由以下檔案生成