OpenCV打开摄像头 保存视频…

#include "cv.h"
#include "highgui.h"
#include "iostream.h"
int main()
{
CvCapture* capture=cvCaptureFromCAM(-1);
CvVideoWriter* video=NULL;
IplImage* frame=NULL;
int n;
if(!capture) //如果不能打开摄像头给出警告
{
cout<<"Can not open the camera."<<endl;
return -1;
}
else
{
frame=cvQueryFrame(capture); //首先取得摄像头中的一帧
video=cvCreateVideoWriter("camera.avi",-1,32,
cvSize(frame->width,frame->height)); //创建CvVideoWriter对象并分配空间
//保存的文件名为camera.avi,编码要在运行程序时选择,大小就是摄像头视频的大小,帧频率是32
if(video) //如果能创建CvVideoWriter对象则表明成功
{
cout<<"VideoWriter has created."<<endl;
}
cvNamedWindow("Camera Video",1); //新建一个窗口
while(1)
{
frame=cvQueryFrame(capture); //从CvCapture中获得一帧
if(!frame)
{
cout<<"Can not get frame from the capture."<<endl;
break;
}
n=cvWriteFrame(video,frame); //判断是否写入成功,如果返回的是1,表示写入成功
cout<<n<<endl;
cvShowImage("Camera Video",frame); //显示视频内容的图片
if(cvWaitKey(2)>0) break; //有其他键盘响应,则退出
}
cvReleaseVideoWriter(&video);
cvReleaseCapture(&capture);
cvDestroyWindow("Camera Video");
}
return 0;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值