0.0& OpenCV保存相机获取的视频

#include <opencv2/core/mat.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
	
	VideoCapture cap;
	cap.open(1);     //打开相机 

	VideoWriter writer;
	double fps = 15.0;     //保存视频的帧率 
	int coder = VideoWriter::fourcc('I', '4', '2', '0');   //保存视频的编码格式 
	string str = "C:/project/shipin.avi";    //保存视频的路径及后缀 
	bool flag = true;
		
	Mat src;	
	while (1)
	{
		cap >> src;
		if (flag)
		{
			writer.open(str, coder, fps, src.size(), true);   //保存视频的格式 
			flag = false;
		}
			
		writer.write(src);
		imshow("原图", src);
		waitKey(1);
	}
	writer.release();
	return 0;
}


保存视频要注意视频编码格式与后缀相对应,如fourcc('I', '4', '2', '0')与.avi相对应,其他的对应格式可从网上搜索找到

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT小艺

如果文章对你有用,请我喝咖啡吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值