opencv 2.4.6 摄像头实时保存视频

#include "stdafx.h"
#include <iostream>
#include <opencv2\opencv.hpp>
 #include "cv.h"
#include "cvaux.h"
#include "highgui.h"
#include <cmath>
using namespace cv;
using namespace std;
void main()
{IplImage* frame=0;
CvVideoWriter *writer = 0;
 cvNamedWindow("camera",1);
CvCapture* capture;
capture=cvCreateCameraCapture(0);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 240);
//cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 320);

frame=cvQueryFrame(capture);
IplImage*b= cvCreateImage(cvGetSize(frame),
 IPL_DEPTH_8U,
 1);
int isColor = 1;
int fps     = 28;  // or 30
int frameW  = frame->width ; // 744 for firewire cameras
int frameH  = frame->height ; // 480 for firewire cameras
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('D', 'I', 'V', 'X'),
                           fps,cvSize(frameW,frameH),0);
/*CV_FOURCC('P','I','M','1') = MPEG-1 codec 
CV_FOURCC('M','J','P','G') = motion-jpeg codec (does not work well) 
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec 
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec 
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec 
CV_FOURCC('U', '2', '6', '3') = H263 codec 
CV_FOURCC('I', '2', '6', '3') = H263I codec 
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec 
将上面的改成 -1 将会打开一个编码器的选择窗口.*/
int i=0;
int n=0;
while(i<=50)
 {
  cvGrabFrame(capture); // capture a frame 
frame=cvRetrieveFrame(capture); // retrieve the captured frame 
 cvCanny(frame , b, 3, 3, 3);
  if(!frame)
   break;
  cvShowImage("camera",b);
n=cvWriteFrame(writer,b);
cout<<n<<endl;
  if(cvWaitKey(33)>=0)
   break;
 }
cvWaitKey(33);
 cvReleaseImage(&frame);
 cvReleaseImage(&b);
 cvDestroyWindow("camera");
 cvReleaseVideoWriter(&writer);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值