视频的读取、播放、保存

#include  
#include  
#include  
#include  

int main()
{
	cv::VideoCapture capture;
	//读取视频文件,无法读取,暂时问题没有解决  
	capture.open("C:\\Users\\deming.yuan.HIRAIN\\Desktop\\ConsoleApplication3\\ConsoleApplication3\\videotest.avi");
	//判断视频流读取是否正确  
	if (!capture.isOpened())
	{
		std::cout << "fail to open video!" << std::endl;
		return -1;
	}

	//获取视频的帧数  
	long nTotalFrame = capture.get(CV_CAP_PROP_FRAME_COUNT);
	std::cout << "nTotalFrame = " << nTotalFrame << std::endl;

	//获取帧的宽、高  
	int frameWidth = capture.get(CV_CAP_PROP_FRAME_WIDTH);
	int frameHeight = capture.get(CV_CAP_PROP_FRAME_HEIGHT);

	std::cout << "frameWidth = " << frameWidth << std::endl;
	std::cout << "frameHeight = " << frameHeight << std::endl;

	//获取视频帧率  

	double frameRate = capture.get(CV_CAP_PROP_FPS);
	std::cout << "frameRate = " << frameRate << std::endl;

	system("pause");
	//显示视频  
	cv::Mat frameImg;
	long currentFrame = 1;

	while (cv::waitKey(50) != 27)  //按下esc退出  
	{
		std::cout << "the currentFrame is : " << currentFrame++ << std::endl;
		capture >> frameImg;
		if (!frameImg.empty())
		{
			cv::resize(frameImg, frameImg, cv::Size(640, 480));     //改变图像分别率到640*480
			cv::imshow("frameImg", frameImg);

		}
		else
		{
			break;
		}
	}
	capture.release();
	return 0;
}

你可能感兴趣的:(openCV)