opencv调用摄像头录制视频

1.安装opencv1.0和vc6.0并配置好,vc6下配置opencv1.0教程http://wiki.opencv.org.cn/index.php/VC6%E4%B8%8B%E5%AE%89%E8%A3%85%E4%B8%8E%E9%85%8D%E7%BD%AEOpenCV1.0

2.安装XVID编解码器,下载地址http://download.csdn.net/detail/whzhaochao/6551035

 

3.代码

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include 

using namespace std;
int main()
{
   CvCapture* capture=cvCaptureFromCAM(-1);
   CvVideoWriter* video=NULL;
   IplImage* frame=NULL;
   int n;
   if(!capture) //如果不能打开摄像头给出警告
   {
      cout<<"Can not open the camera."<width,frame->height)); //创建CvVideoWriter对象并分配空间
		//保存的文件名为camera.avi,编码要在运行程序时选择,大小就是摄像头视频的大小,帧频率是32
      if(video) //如果能创建CvVideoWriter对象则表明成功
      {
         cout<<"VideoWriter has created."<0) 
            break; //有其他键盘响应,则退出
      }

      cvReleaseVideoWriter(&video);
      cvReleaseCapture(&capture);
      cvDestroyWindow("Camera Video");
   }
   return 0;
}


 

 

你可能感兴趣的:(C++,图像处理)