这个实验和之前的画圆的类似,先捕捉图像,然后再上面输出文字。
#include "stdafx.h" #include "highgui.h" #include "cv.h" #include "stdio.h" #include <ctype.h> #include <time.h> int main(int argc,char ** argv) { time_t t; char showMsg[256]; //the font variable CvFont font; CvCapture *capture = 0; //从摄像头读取 capture = cvCaptureFromCAM(0); if(!capture) { fprintf(stderr,"Could not initialize capturing...\n"); return -1; } cvNamedWindow("Laplacian",1); //循环捕捉,直到用户按键跳出循环体 for(;;) { IplImage * frame =0; //抓起一祯 frame = cvQueryFrame(capture); if(!frame) break; time(&t); strftime(showMsg, sizeof(showMsg), "%H%M%S", localtime(&t) ); //格式化输出. // 初始化字体 cvInitFont(&font,CV_FONT_HERSHEY_SIMPLEX, 4.5,1,0,2);//初始化字体,准备写到图片上的 // cvPoint 为起笔的x,y坐标 cvPutText(frame,showMsg,cvPoint(300,100),&font,CV_RGB(255,0,0));//在图片中输出字符 cvShowImage("Laplacian",frame); if(cvWaitKey(10)>0) break; } cvReleaseCapture(&capture); cvDestroyWindow("Laplacian"); return 0; }
参考:
1.http://blog.csdn.net/jiadelin/article/details/2916329 strftime()函数用法
2.http://blog.csdn.net/jinshengtao/article/details/20549221 利用OpenCV给图像添加标注
3.http://blog.csdn.net/ycc892009/article/details/6516528 opencv-在图像上显示字符(不包括中文)