opencv读取视频,摄像头,保存视频代码

opencv读取视频,摄像头,保存视频最基础的代码

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

int main( int argc, char** argv )
{
CvCapture* capture = 0;
IplImage* frame = 0;

capture = cvCaptureFromCAM( 0 );
//capture = cvCaptureFromAVI("1.wmv");//播放视频 就换成这句

int fps=25; //捕捉帧率
//double fps = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS); //视频帧率

CvVideoWriter* writer = 0; //保存就加上这句
int isColol=1;
int frameW=640;
int frameH=480;
writer=cvCreateVideoWriter("out.avi",CV_FOURCC('F','L','V','1'),fps,cvSize(frameW,frameH),isColol);

cvNamedWindow( "摄像头", 1 );

//for(int i=0;i<50;i++) //2秒
for(;;) //一直读
{
frame = cvQueryFrame( capture );

cvWriteFrame(writer,frame );

cvShowImage( "摄像头", frame ); //显示一帧图像
cvWaitKey(1000 / fps);//视频速度


cvReleaseVideoWriter(&writer);
cvReleaseImage(&frame);
cvReleaseCapture( &capture );
cvDestroyWindow("摄像头");
return 0;
}

你可能感兴趣的:(opencv读取视频,摄像头,保存视频代码)