现在的位置: 首页 > 综合 > 正文

opencv 学习第一天 如何打开一个视频

2013年10月09日 ⁄ 综合 ⁄ 共 546字 ⁄ 字号 评论关闭
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
void main()
{
	cvNamedWindow("example2",CV_WINDOW_AUTOSIZE);
	CvCapture *cap = cvCreateFileCapture("D:\\output1.mp4");
	IplImage *frame;
	int i=0;
	while(frame = cvQueryFrame(cap))
	{
		i++;
		if (!frame)
			break;
		cvShowImage("example2",frame);
		char c = waitKey(33);//人为的设定每隔33ms播放一帧,这个不是特别好
							//书上说cvcapturefromcamera可以解决,等看到第四章来解决
		if (c == 27)
		{
			break;
		}
		//waitKey(0);
	}
	cout<<i<<endl;
	cvReleaseCapture(&cap);
	cvDestroyWindow("example2");
	system("pause");
}

该程序的缺点是为什么设定waitkey(33),好的方式是应该读出视频的每秒有多少帧,设定该值为上策

抱歉!评论已关闭.