资源简介
Ubuntu环境下,OpenCV通过链接freetype库,来支持中文显示。

代码片段和文件信息
#include
#include
#include
#include
#include
#include “CvxText.h“
// 打开字库
CvxText::CvxText(const char* freeType)
{
assert(freeType != NULL);
// 打开字库文件 创建一个字体
if(FT_Init_FreeType(&m_library)) throw;
if(FT_New_Face(m_library freeType 0 &m_face)) throw;
// 设置字体输出参数
restoreFont();
// 设置C语言的字符集环境
setlocale(LC_ALL ““);
}
// 释放FreeType资源
CvxText::~CvxText()
{
FT_Done_Face(m_face);
FT_Done_FreeType(m_library);
}
// 设置字体参数:
//
// font - 字体类型 目前不支持
// size - 字体大小/空白比例/间隔比例/旋转角度
// underline - 下画线
// diaphaneity - 透明度
void CvxText::getFont(int* type cv::Scalar* 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 cv::Scalar* size bool* underline float* diaphaneity)
{
// 参数合法性检查
if (type) {
if(type >= 0) m_fontType = *type;
}
if (size) {
m_fontSize.val[0] = std::fabs(size->val[0]);
m_fontSize.val[1] = std::fabs(size->val[1]);
m_fontSize.val[2] = std::fabs(size->val[2]);
m_fontSize.val[3] = std::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);
}
// 恢复原始的字体设置
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; // 旋转角度(不支持)
m_fontUnderline = false; // 下画线(不支持)
m_fontDiaphaneity = 1.0; // 色彩比例(可产生透明效果)
// 设置字符大小
FT_Set_Pixel_Sizes(m_face (int)m_fontSize.val[0] 0);
}
// 输出函数(颜色默认为白色)
int CvxText::putText(cv::Mat& img char* text cv::Point pos)
{
return putText(img text pos CV_RGB(255 255 255));
}
int CvxText::putText(cv::Mat& img const wchar_t* text cv::Point pos)
{
return putText(img text pos CV_RGB(255255255));
}
int CvxText::putText(cv::Mat& img const char* text cv::Point pos cv::Scalar color)
{
if (img.data == nullptr) return -1;
if (text == nullptr) return -1;
int i;
for (i = 0; text[i] != ‘\0‘; ++i) {
wchar_t wc = text[i];
// 解析双字节符号
if(!isascii(wc)) mbtowc(&wc &text[i++] 2);
// 输出当前的字符
putWChar(img wc pos color);
}
return i;
}
int CvxText::putText(cv::Mat& img const wchar_t* text cv::Point pos cv::Scalar color)
{
if (img.data == nullptr) return -1;
if (text == nullptr) return -1;
int i;
for(i = 0; text[i] != ‘\0‘; ++i) {
// 输出当前的字符
putWChar(img text[i] pos color);
}
return i;
}
// 输出当前字符 更新m_pos位置
void CvxText::putWChar(cv::Mat& img wchar_t wc cv::Point& p
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-10-29 03:36 chinese\
文件 3193 2018-08-23 02:17 chinese\CvxText.h
文件 9753284 2017-09-28 15:55 chinese\simhei.ttf
文件 5030 2018-08-23 02:16 chinese\CvxText.cpp
文件 58723 2018-10-29 03:26 chinese\demo.jpg
文件 1580 2018-10-29 03:32 chinese\main.cpp
文件 403 2018-10-29 03:25 chinese\CMakeLists.txt
目录 0 2018-10-29 03:32 chinese\.idea\
文件 11945 2018-10-29 03:32 chinese\.idea\workspace.xm
文件 97 2018-10-29 03:16 chinese\.idea\chinese.iml
文件 240 2018-10-29 03:16 chinese\.idea\misc.xm
文件 266 2018-10-29 03:14 chinese\.idea\modules.xm
文件 181 2018-10-29 03:29 chinese\.idea\encodings.xm
目录 0 2018-10-29 03:16 chinese\.idea\codest
文件 1775 2018-10-29 03:16 chinese\.idea\codest
- 上一篇:全志H3硬件设计资料
- 下一篇:软件工程导论学习辅导
相关资源
- VisualStudioUninstaller vs卸载工具
- 组态王驱动开发包3.0.0.7(中文)
- 多窗口后台鼠标连点器
- 使用选择性重传协议实现UDP可靠通信
- VC 获得文件属性 获取文件的创建时
- 读者写者问题(读者优先,写者优先
- 用VC 编写的仿QQ聊天室程序源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- 外点法程序
- 外罚函数程序
- qt-电子点菜系统
- 推箱子及人工智能寻路C 源代码
- 自己写的航空订票系统c 版--数据结构
- 数据结构实验魔王语言
- MUSIC算法c 实现
- C 餐厅叫号系统(QT平)
- 国际象棋c 完整版
-
ob
jectARX给Auto CAD加工具条 - 画图程序MFC/VC/VC CRectTracker 串行化
- MFC网络编程实例
- c 课程设计 职工信息管理系统
- 基于OpenCV的数字识别468815
- VC 游戏编程—附源代码
- 使用opencv去掉二值化图像中黑色面积
- IpHlpApi.h&IpHlpApi.lib
- 清华大学 c 郑莉 ppt课件
- c 程序判断离散数学中命题公式
- 多项式求和(数据结构C 版)
- vc 6.0开发的流程图编辑器
- VC 天空盒(skyBox)实现(附源代码)
评论
共有 条评论