cvCreateVideoWriter( const char* filename, int fourcc, double fps, CvSize frame_size,
int is_color CV_DEFAULT(1));
这是一个保存视频文件的函数 第一个参数是文件名 每次保存的文件名称为当前时间,自己写的代码如下:
char *getSystemTime()
{
char y[20], mon[5], d[5], h[5], mins[5], *temp;
char *temp;
char str[5]=".avi";
time_t rawtime;
struct tm *timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime); // 需要给timeinfo赋值
printf("%4d-%02d-%02d-%02d:%02d:%02d\n", 1900 + timeinfo->tm_year, 1 + timeinfo->tm_mon, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
_itoa(1900 + timeinfo->tm_year, y, 10);
_itoa(1 + timeinfo->tm_mon, mon, 10);
_itoa(timeinfo->tm_mday, d, 10);
_itoa(timeinfo->tm_hour, h, 10);
_itoa(timeinfo->tm_min, mins, 10);
strcat(y, mon);
strcat(y, d);
strcat(y, h);
strcat(y, mins);
temp = strcat(y, str);
printf("%s\n", temp);
return temp;
}
int main(int argc, char** argv)
{
CvVideoWriter* video = NULL;
CvCapture* capture = cvCaptureFromCAM(0);
int n;
pFrame = cvQueryFrame(capture); //首先取得摄像头中的一帧
int fps = 32; //捕捉帧率
CvVideoWriter* writer = 0; //保存就加上这句
int isColol = 1;
int frameW = 640;
int frameH = 480;
video = cvCreateVideoWriter(getSystemTime(), CV_FOURCC('P', 'I', 'M', '1'), fps, cvSize(frameW, frameH), isColol);
if (video) //如果能创建CvVideoWriter对象则表明成功
{
cout << "VideoWriter has created." << endl;
}
//创建窗口
cvNamedWindow("video", 1);
if (argc == 1)
if (!(pCapture = cvCaptureFromCAM(0)))
{
MessageBox(NULL, TEXT("打开摄像头失败,请查看是否已连接摄像头"), TEXT("错误通知"), MB_OK);
return -2;
}
while (1)
{
pFrame = cvQueryFrame(capture); //从CvCapture中获得一帧
if (!pFrame)
{
cout << "Can not get frame from the capture." << endl;
break;
}
n = cvWriteFrame(video, pFrame); //判断是否写入成功,如果返回的是1,表示写入成功
cout << n << endl;
cvShowImage("video", pFrame); //显示视频内容的图片
}
别的不重要的就不写了,debug出来到 video = cvCreateVideoWriter(getSystemTime(), CV_FOURCC('P', 'I', 'M', '1'), fps, cvSize(frameW, frameH), isColol);
这句就报错了情况如下!
图片说明
求大神帮助