首页 > 代码库 > opencv播放,变换和保存视频

opencv播放,变换和保存视频

核心函数:

1. cvCreateFileCapture

2. cvGetCaptureProperty

3. cvQueryFrame

4. cvCreateVideoWriter

5. cvWriteFrame

wKioL1Psd5SA7M0QAAUal28CGEg131.jpg

程序:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
#include <stdio.h>
int Vedio(int argc,char** argv)
{
CvCapture* SrcCapture=cvCreateFileCapture("e:\\vedio\\1.avi"); //读取视频文件
cvNamedWindow("src");
cvNamedWindow("GRAY");
IplImage* SrcImage=NULL;
int fps=cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FPS);  //获取视频文件信息
CvSize size=cvSize(cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FRAME_WIDTH),cvGetCaptureProperty(SrcCapture,CV_CAP_PROP_FRAME_HEIGHT));
CvVideoWriter *VideoWriter=cvCreateVideoWriter("e:\\vedio\\3.avi",CV_FOURCC(‘X‘,‘V‘,‘I‘,‘D‘),fps,size); //创建写入文件信息
SrcImage=cvQueryFrame(SrcCapture);
IplImage* Gray=cvCreateImage(cvGetSize(SrcImage),8,1);
while(1)
{
SrcImage=cvQueryFrame(SrcCapture); //获取每一帧图像
if(SrcImage==NULL)
{
break;
}
cvShowImage("src",SrcImage);
cvCvtColor(SrcImage,Gray,CV_BGR2GRAY);
cvShowImage("GRAY",Gray);
cvWriteFrame(VideoWriter,Gray); //保存文件
char c=cvWaitKey(10);
if(c==27)
{break;}
}
//cvWaitKey(0);
cvDestroyWindow("src");
cvDestroyWindow("GRAY");
cvReleaseCapture(&SrcCapture);
cvReleaseVideoWriter(&VideoWriter);
return 0;
}


本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1540031