close

下載 freeType 2.9.1

編譯 freeType產生static library

 

image

加入新的屬性表單 ChineseFont.props

image

標頭檔目錄設定: C:\OpenCV\freetype-2.9.1\include

image

其他函式庫目錄: C:\OpenCV\freetype-2.9.1\objs

image

image

其他相依性: freetype.lib

image

C:\Windows\Fonts

image

微軟正黑體

image

   1:  
   2: #include "pch.h"
   3: #include <iostream>
   4: #include <opencv2/opencv.hpp>
   5: #include "i18nText.h"
   6:  
   7: using namespace std;
   8: using namespace cv;
   9:  
  10:  
  11: i18nText GetText(int fontSize)
  12: {
  13:     i18nText _font(fontSize);
  14:     _font.setFont("C:\\Windows\\Fonts\\msjh.ttc");
  15:     return _font;
  16: }
  17: void AddText(Mat& img, const wchar_t *msg, Point position, i18nText &font, Scalar color)
  18: {
  19:     font.putText(img, msg, position, color);
  20: }
  21: void AddText(Mat& img, const wchar_t *msg, Point position, int fontsize, Scalar color)
  22: {
  23:     i18nText i18n(fontsize);
  24:     //if (i18n.setFont("C:\\Windows\\Fonts\\kaiu.ttf"))
  25:     if (i18n.setFont("C:\\Windows\\Fonts\\msjh.ttc"))
  26:     {
  27:         i18n.putText(img, msg, position, color);
  28:     }    
  29: }
  30: void demo()
  31: {
  32:     Mat img(640, 480, CV_8UC3, CV_RGB(0, 0, 0));
  33:     namedWindow("test", WINDOW_AUTOSIZE);
  34:     const wchar_t *msg = L"台灣 / 繁體";
  35:     i18nText font1 = GetText(25);
  36:     i18nText font2 = GetText(45);
  37:     AddText(img, msg, Point(25, 45), font1, CV_RGB(255, 0, 0));
  38:     //AddText(img, msg, Point(25, 45), 25, CV_RGB(255, 0, 0));
  39:     
  40:     const wchar_t *msg2 = L"中国 / 简体";
  41:     AddText(img, msg2, Point(15, 200), font2, CV_RGB(0, 255, 0));
  42:     //AddText(img, msg2, Point(15, 200), 45, CV_RGB(0, 255, 0));
  43:     
  44:     const wchar_t *msg3 = L"こんにちは / hello";
  45:     AddText(img, msg3, Point(45, 350), font2, CV_RGB(0, 0, 255));
  46:     //AddText(img, msg3, Point(45, 350), 35, CV_RGB(0, 0, 255));
  47:     imshow("test", img);
  48:     waitKey(0);
  49: }

 

image

參考資料

1. 给OpenCV(2.x)增加汉字输出功能

2. VS2010中OpenCV 显示汉字

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()