opencv实现读取视频保存视频实现读取视频保存视频
不得不说opencv是个强大的东东,以前做一个项目的一个模块时使用到进行图形处理,这次是想将一个视频的播放放慢,以
前在网上看到opencv有这个功能,今天就不小心尝试了下,东西不多,主要是做个小记录还有一点要注意的小问题说一下,
代码不多,基本上也都是copy的网上的
#include <iostream>
#include <assert.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <math.h>
using namespace std;
#ifdef NDEBUG
#pragma comment(lib, "highgui210.lib")
#pragma comment(lib, "cxcore210.lib")
#pragma comment(lib, "ml210.lib")
#pragma comment(lib, "cv210.lib")
#else
#pragma comment(lib, "highgui210d.lib")
#pragma comment(lib, "cxcore210d.lib")
#pragma comment(lib, "ml210d.lib")
#pragma comment(lib, "cv210d.lib")
#endif
char g_fileName[] = "C:\Users\Desktop\test.avi";
char g_winodwName[] = "Cv Test";
int main()
{
::cvNamedWindow("g_winodwName", CV_WINDOW_AUTOSIZE);
CvCapture *pCvCapture = NULL;
pCvCapture = cvCreateFileCapture(g_fileName);
assert(NULL != pCvCapture);
IplImage *pIplFrame = NULL;
char out1[] = "C:\Users\Desktop\out1.avi";
double fps1 = cvGetCaptureProperty(pCvCapture,
CV_CAP_PROP_FPS);
CvSize size1 = cvSize((int)cvGetCaptureProperty(pCvCapture,
CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(pCvCapture,
CV_CAP_PROP_FRAME_HEIGHT));
CvVideoWriter *wrVideo1 = cvCreateVideoWriter(out1,
CV_FOURCC('X','V','I','D'),
10,
size1);
IplImage *gray1 = cvCreateImage(size1,8,1);
while (true)
{
pIplFrame = cvQueryFrame(pCvCapture);
if (NULL == pIplFrame)
{
break;
}
else
{
::cvShowImage(g_winodwName, pIplFrame);
//保存视频文件
cvCvtColor(pIplFrame,gray1,CV_RGB2GRAY);
cvWriteFrame(wrVideo1,gray1);
if (27 == ::cvWaitKey(120))
{
break;
}
}
评论0
最新资源