資源簡(jiǎn)介
FreeType 結(jié)合opencv –> 在圖像上顯示中文
代碼編寫參考:
http://blog.csdn.net/huixingshao/article/details/43563853#comments

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?“CvxText.h“
//====================================================================
//====================================================================
//?打開(kāi)字庫(kù)
CvxText::CvxText(const?char?*freeType)
{
assert(freeType?!=?NULL);
//?打開(kāi)字庫(kù)文件?創(chuàng)建一個(gè)字體
if(FT_Init_FreeType(&m_library))?throw;
if(FT_New_Face(m_library?freeType?0?&m_face))?throw;
//?設(shè)置字體輸出參數(shù)
restoreFont();
//?設(shè)置C語(yǔ)言的字符集環(huán)境
setlocale(LC_ALL?““);
}
//?釋放FreeType資源
CvxText::~CvxText()
{
FT_Done_Face????(m_face);
FT_Done_FreeType(m_library);
}
//?設(shè)置字體參數(shù):
//
//?font?????????-?字體類型?目前不支持
//?size?????????-?字體大小/空白比例/間隔比例/旋轉(zhuǎn)角度
//?underline???-?下畫線
//?diaphaneity???-?透明度
void?CvxText::getFont(int?*type?CvScalar?*size?bool?*underline?float?*diaphaneity)
{
if(type)?*type?=?m_fontType;
if(size)?*size?=?m_fontSize;
if(underline)?*underline?=?m_fontUnderline;
if(diaphaneity)?*diaphaneity?=?m_fontDiaphaneity;
}
void?CvxText::setFont(int?*type?CvScalar?*size?bool?*underline?float?*diaphaneity)
{
//?參數(shù)合法性檢查
if(type)
{
if(type?>=?0)?m_fontType?=?*type;
}
if(size)
{
m_fontSize.val[0]?=?fabs(size->val[0]);
m_fontSize.val[1]?=?fabs(size->val[1]);
m_fontSize.val[2]?=?fabs(size->val[2]);
m_fontSize.val[3]?=?fabs(size->val[3]);
}
if(underline)
{
m_fontUnderline???=?*underline;
}
if(diaphaneity)
{
m_fontDiaphaneity?=?*diaphaneity;
}
FT_Set_Pixel_Sizes(m_face?(int)m_fontSize.val[0]?0);
}
//?恢復(fù)原始的字體設(shè)置
void?CvxText::restoreFont()
{
m_fontType?=?0;????????????//?字體類型(不支持)
m_fontSize.val[0]?=?20;??????//?字體大小
m_fontSize.val[1]?=?0.5;???//?空白字符大小比例
m_fontSize.val[2]?=?0.1;???//?間隔大小比例
m_fontSize.val[3]?=?0;??????//?旋轉(zhuǎn)角度(不支持)
m_fontUnderline???=?false;???//?下畫線(不支持)
m_fontDiaphaneity?=?1.0;???//?色彩比例(可產(chǎn)生透明效果)
//?設(shè)置字符大小
FT_Set_Pixel_Sizes(m_face?(int)m_fontSize.val[0]?0);
}
//?輸出函數(shù)(顏色默認(rèn)為黑色)
int?CvxText::putText(IplImage?*img?const?char????*text?CvPoint?pos)
{
return?putText(img?text?pos?CV_RGB(255255255));
}
int?CvxText::putText(IplImage?*img?const?wchar_t?*text?CvPoint?pos)
{
return?putText(img?text?pos?CV_RGB(255255255));
}
//
int?CvxText::putText(IplImage?*img?const?char????*text?CvPoint?pos?CvScalar?color)
{
if(img?==?NULL)?return?-1;
if(text?==?NULL)?return?-1;
//
int?i;
for(i?=?0;?text[i]?!=?‘\0‘;?++i)
{
wchar_t?wc?=?text[i];
//?解析雙字節(jié)符號(hào)
if(!isascii(wc))?mbtowc(&wc?&text[i++]?2);
//?輸出當(dāng)前的字符
putWChar(img?wc?pos?color);
}
return?i;
}
int?CvxText::putText(IplImage?*img?const?wchar_t?*text?CvPoint?pos?CvScalar?color)
{
if(img?==?NULL)?return?-1;
if(text?==?NULL)?return?-1;
//
int?i;
for(i?=?0;?text[i]?!=?‘\0‘;?++i)
{
//?輸出當(dāng)前的字符
putWChar(img?text[i]?pos?color);
}
return?i;
}
//?輸出當(dāng)前字符?更新m_pos位置
void?CvxText::putWChar(IplImage?*img?wchar_t?wc?CvPoint?&pos?CvScalar?color)
{
//?根據(jù)unicode生成字體的二值位圖
FT_UInt?glyph_index?=?FT_Get_Char_Index(m_face?wc);
FT_Load_Glyph(m_face?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-04-06?14:14??FreeTypetest\
?????目錄???????????0??2016-04-06?14:13??FreeTypetest\FTtest\
?????文件?????????885??2016-04-06?13:43??FreeTypetest\FTtest.sln
?????文件???????12800??2016-04-06?14:13??FreeTypetest\FTtest.suo
?????文件????????4234??2016-04-06?13:48??FreeTypetest\FTtest\CvxText.cpp
?????文件????????5681??2016-04-06?13:57??FreeTypetest\FTtest\CvxText.h
?????目錄???????????0??2016-04-06?13:51??FreeTypetest\FTtest\ft251_slib\
?????目錄???????????0??2016-04-06?13:51??FreeTypetest\FTtest\ft251_slib\include\
?????目錄???????????0??2016-04-06?13:51??FreeTypetest\FTtest\ft251_slib\include\config\
?????文件???????24206??2013-11-12?19:24??FreeTypetest\FTtest\ft251_slib\include\config\ftconfig.h
?????文件???????26419??2013-11-12?19:27??FreeTypetest\FTtest\ft251_slib\include\config\ftheader.h
?????文件????????1431??2009-03-14?21:45??FreeTypetest\FTtest\ft251_slib\include\config\ftmodule.h
?????文件???????53774??2013-11-12?19:26??FreeTypetest\FTtest\ft251_slib\include\config\ftoption.h
?????文件????????7487??2012-09-29?15:42??FreeTypetest\FTtest\ft251_slib\include\config\ftstdlib.h
?????文件??????256336??2013-11-21?22:42??FreeTypetest\FTtest\ft251_slib\include\freetype.h
?????文件????????2425??2013-11-13?16:46??FreeTypetest\FTtest\ft251_slib\include\ft2build.h
?????文件???????10758??2013-09-03?17:02??FreeTypetest\FTtest\ft251_slib\include\ftadvanc.h
?????文件???????13258??2013-09-03?17:03??FreeTypetest\FTtest\ft251_slib\include\ftautoh.h
?????文件????????5347??2013-09-03?17:03??FreeTypetest\FTtest\ft251_slib\include\ftbbox.h
?????文件????????6958??2009-03-14?21:45??FreeTypetest\FTtest\ft251_slib\include\ftbdf.h
?????文件???????14225??2013-05-29?15:24??FreeTypetest\FTtest\ft251_slib\include\ftbitmap.h
?????文件????????4409??2011-01-01?00:44??FreeTypetest\FTtest\ft251_slib\include\ftbzip2.h
?????文件???????58586??2013-09-03?17:05??FreeTypetest\FTtest\ft251_slib\include\ftcache.h
?????文件???????10140??2013-10-24?03:31??FreeTypetest\FTtest\ft251_slib\include\ftcffdrv.h
?????文件????????8556??2013-09-03?17:08??FreeTypetest\FTtest\ft251_slib\include\ftchapters.h
?????文件????????5745??2009-07-03?21:28??FreeTypetest\FTtest\ft251_slib\include\ftcid.h
?????文件???????12648??2013-05-29?05:00??FreeTypetest\FTtest\ft251_slib\include\fterrdef.h
?????文件????????9490??2013-05-29?05:00??FreeTypetest\FTtest\ft251_slib\include\fterrors.h
?????文件????????4630??2012-01-17?18:32??FreeTypetest\FTtest\ft251_slib\include\ftgasp.h
?????文件???????40439??2013-09-03?17:10??FreeTypetest\FTtest\ft251_slib\include\ftglyph.h
?????文件???????12954??2013-09-03?17:10??FreeTypetest\FTtest\ft251_slib\include\ftgxval.h
............此處省略90個(gè)文件信息
評(píng)論
共有 條評(píng)論