主函数是用于读取摄像头,并在视频上写时间字幕:
CvCapture* capture;
capture = cvCaptureFromCAM(0);
IplImage* frame;
cvNamedWindow("video",1);
cvResizeWindow("video",750,750);
CvFont timeFont,timeFont1;
cvInitFont(&timeFont, CV_FONT_HERSHEY_COMPLEX, 1.0f,1.0f,0,1,8);
cvInitFont(&timeFont1, CV_FONT_HERSHEY_COMPLEX, 1.0f,1.0f,0,1,8);
// Initialize new applied memory of 'time1'
char timestr[25];
memset(timestr, 0, 25 * sizeof(char));
while (1)
{
frame = cvQueryFrame( capture );
if (!frame) break;
// Get the systme local time info
time_t rawtime;
struct tm* timeinfo;
//time( &rawtime );
rawtime = time( NULL );
timeinfo = localtime( &rawtime );
char* p = asctime( timeinfo );
// the 25th character of array 'p' is '/n'
// but it can not be display correctly in the image
// so we just read out the first 24 character of 'p'
for (int i = 0; i < 24; i++)
{
timestr[i] = *p;
p++;
}
p = NULL;
// Bitwise inversion of every element of the current frame
IplImage* frame_not = cvCreateImage(cvGetS