其他分享
首页 > 其他分享> > 用Opencv实现以‘H‘‘2‘‘6‘‘4‘格式录制并预览摄像机视频代码

用Opencv实现以‘H‘‘2‘‘6‘‘4‘格式录制并预览摄像机视频代码

作者:互联网

#include<iostream>
#include<opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
	VideoCapture cam(0);//到开摄像头
	if (!cam.isOpened())
	{
		cout << "cam open failed !" << endl;
		getchar();
		return -1;

	}
	cout << "cam open success !" << endl;
	namedWindow("cam");
	Mat img;
	VideoWriter vw;//生成视频流对象
	int fps = cam.get(CAP_PROP_FPS);
	if (fps <= 0)fps = 25;
	vw.open("D:/tupian/1out.avi", VideoWriter::fourcc('X', '2', '6', '4'), fps,
		Size(cam.get(CAP_PROP_FRAME_WIDTH), cam.get(CAP_PROP_FRAME_HEIGHT)));//创建视频文件
	if (!vw.isOpened())
	{
		cout << "VideoWriter open failed !" << endl;
		getchar();
		return -1;
	}
	cout << "VideoWriter open failed !" << endl;

	for (;;)
	{
		cam.read(img);
		if(img.empty())break;
		imshow("cam", img);
		vw.write(img);//将画面写入该文件下
		if(waitKey(5)=='q')break;
		
	}
	

	waitKey(0);
	return 0;

}

标签:cout,预览,int,namespace,摄像机,Opencv,cam,using,include
来源: https://blog.csdn.net/weixin_52799870/article/details/122665220