CvxText.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //====================================================================
  2. //====================================================================
  3. //
  4. // 文件: CvxText.h
  5. //
  6. // 说明: OpenCV汉字输出
  7. //
  8. // 时间:
  9. //
  10. // 作者: chaishushan#gmail.com
  11. //
  12. //====================================================================
  13. //====================================================================
  14. #ifndef OPENCV_CVX_TEXT_2007_08_31_H
  15. #define OPENCV_CVX_TEXT_2007_08_31_H
  16. /**
  17. * \file CvxText.h
  18. * \brief OpenCV汉字输出接口
  19. *
  20. * 实现了汉字输出功能。
  21. */
  22. #include "ft2build.h"
  23. #include FT_FREETYPE_H
  24. //#include"opnecv2/opencv.hpp"
  25. #include <opencv2/opencv.hpp>
  26. #include "libwmvrecord.h"
  27. class CvxText
  28. {
  29. // 禁止copy
  30. CvxText& operator=(const CvxText&);
  31. //================================================================
  32. //================================================================
  33. public:
  34. /**
  35. * 装载字库文件
  36. */
  37. CvxText(CWmvHostApi* pHostApi, const char *freeType);
  38. virtual ~CvxText();
  39. //================================================================
  40. //================================================================
  41. /**
  42. * 获取字体。目前有些参数尚不支持。
  43. *
  44. * \param font 字体类型, 目前不支持
  45. * \param size 字体大小/空白比例/间隔比例/旋转角度
  46. * \param underline 下画线
  47. * \param diaphaneity 透明度
  48. *
  49. * \sa setFont, restoreFont
  50. */
  51. void getFont(int *type,
  52. CvScalar *size=NULL, bool *underline=NULL, float *diaphaneity=NULL);
  53. /**
  54. * 设置字体。目前有些参数尚不支持。
  55. *
  56. * \param font 字体类型, 目前不支持
  57. * \param size 字体大小/空白比例/间隔比例/旋转角度
  58. * \param underline 下画线
  59. * \param diaphaneity 透明度
  60. *
  61. * \sa getFont, restoreFont
  62. */
  63. void setFont(int *type,
  64. CvScalar *size=NULL, bool *underline=NULL, float *diaphaneity=NULL);
  65. /**
  66. * 恢复原始的字体设置。
  67. *
  68. * \sa getFont, setFont
  69. */
  70. void restoreFont();
  71. //================================================================
  72. //================================================================
  73. /**
  74. * 输出汉字(颜色默认为黑色)。遇到不能输出的字符将停止。
  75. *
  76. * \param img 输出的影象
  77. * \param text 文本内容
  78. * \param pos 文本位置
  79. *
  80. * \return 返回成功输出的字符长度,失败返回-1。
  81. */
  82. int putText(IplImage *img, const char *text, CvPoint pos);
  83. /**
  84. * 输出汉字(颜色默认为黑色)。遇到不能输出的字符将停止。
  85. *
  86. * \param img 输出的影象
  87. * \param text 文本内容
  88. * \param pos 文本位置
  89. *
  90. * \return 返回成功输出的字符长度,失败返回-1。
  91. */
  92. int putText(IplImage *img, const wchar_t *text, CvPoint pos);
  93. /**
  94. * 输出汉字。遇到不能输出的字符将停止。
  95. *
  96. * \param img 输出的影象
  97. * \param text 文本内容
  98. * \param pos 文本位置
  99. * \param color 文本颜色
  100. *
  101. * \return 返回成功输出的字符长度,失败返回-1。
  102. */
  103. int putText(IplImage *img, const char *text, CvPoint pos, CvScalar color);
  104. /**
  105. * 输出汉字。遇到不能输出的字符将停止。
  106. *
  107. * \param img 输出的影象
  108. * \param text 文本内容
  109. * \param pos 文本位置
  110. * \param color 文本颜色
  111. *
  112. * \return 返回成功输出的字符长度,失败返回-1。
  113. */
  114. int putText(IplImage *img, const wchar_t *text, CvPoint pos, CvScalar color);
  115. //================================================================
  116. //================================================================
  117. private:
  118. // 输出当前字符, 更新m_pos位置
  119. void putWChar(IplImage *img, wchar_t wc, CvPoint &pos, CvScalar color);
  120. //================================================================
  121. //================================================================
  122. private:
  123. FT_Library m_library; // 字库
  124. FT_Face m_face; // 字体
  125. //================================================================
  126. //================================================================
  127. // 默认的字体输出参数
  128. int m_fontType;
  129. CvScalar m_fontSize;
  130. bool m_fontUnderline;
  131. float m_fontDiaphaneity;
  132. //================================================================
  133. //================================================================
  134. };
  135. #endif // OPENCV_CVX_TEXT_2007_08_31_H