alensama 2016-02-03 12:52 采纳率: 100%
浏览 2072
已采纳

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 13: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条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题