設置好opencv環境
1,包含頭文件 #include "CvxText.h"
#include "cv.h"
#include "highgui.h"
#include "cxcore.h"
2,工程->設置-> 連接-> "對象/庫模塊" 添加 cxcore.lib cv.lib cvaux.lib highgui.lib
3,將C:/WINDOWS/Fonts/中的simhei.ttf,simsun.ttf等要用的字庫文件拷貝到自己工程的運行文件目錄中(開始時不知道有這步,運行出錯了)
4,pImg = cvLoadImage("p1.jpg",1); //加載圖片
CvxText text("simhei.ttf");//加載字體庫
float p = 0.5;
text.setFont(NULL, NULL, NULL, &p); // 透明處理
text.putText(pImg, msg, cvPoint(100,150),CV_RGB(255,0,0)); //在圖片中輸入文字
cvNamedWindow("test",1);
cvShowImage("test", pImage); //顯示圖片
cvWaitKey(0); //等待按鍵
