alensama 2016-02-03 04:52 采纳率: 100%
浏览 2075
已采纳

opencv 保存视频文件名称更改问题

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);
这句就报错了情况如下!
图片说明
图片说明
求大神帮助

展开全部

  • 写回答

3条回答 默认 最新

  • threenewbee 2016-02-03 05:56
    关注

    假设你的文件名是类似20160203.avi

     char t[100];
    SYSTEMTIME st;
    GetSystemTime(&st);
    sprintf(t, "%04d%2d%2d.avi",  st.wYear,  st.wMonth,  st.wDay );
    video = cvCreateVideoWriter(t, CV_FOURCC('P', 'I', 'M', '1'), fps, cvSize(frameW, frameH), isColol);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部