opencv保存视频

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
using namespace std;
using namespace cv;
Mat s1;
bool leftButtonDownFlag = false;
Point originalPoint;
Point processPoint;
double sum(Mat src)
{
	double counterw = 0;
	double counterz = 0;
	Mat_<uchar>::iterator it = src.begin<uchar>();
	Mat_<uchar>::iterator itend = src.end<uchar>();
	for (; it != itend; it++)
	{
		if ((*it) > 0)
			counterw += 1;
		if ((*it) == 0)
			counterz += 1;
	}
	double a = counterw * 1.0 / (counterz + counterw) * 100;
	return a;
}
int main()
{
	Mat huabu(Size(1280, 960), CV_8UC3, Scalar(0, 0, 0));
	line(huabu, Point(5, 0), Point(5, 950), Scalar(255, 255, 255), 2, LINE_AA);
	line(huabu, Point(5, 950), Point(950, 950), Scalar(255, 255, 255), 2, LINE_AA);
	VideoWriter write;
	string outvideo = "huabu25.avi";
	write.open(outvideo, 0, 4.016, Size(1000, 1000), true);
	if (!write.isOpened())
	{
		cerr << "Could not open the output video file for write\n";
		return -1;
	}
	VideoCapture capture("34.avi");

	int i = 15;
	float last = 0;
	double d1, d2, d3, d4, d5, d6;
	//double t1= (double)getTickCount();

	while (1)
	{

		capture >> s1;
		if (s1.empty()) //||waitKey(pauseTime)==27
		{
			cout << "n=vedio is over";
			waitKey(0);
			return 0;
		}
		Mat s2;
		cvtColor(s1, s2, COLOR_BGR2GRAY);

		threshold(s2, s2, 253, 255, THRESH_BINARY);

		double a = sum(s2);

		cout << "占比是:" << a << endl;
		//---------
		int h = 100;
		int w = 100;
		line(huabu, Point(i - 10, 950 - last * 10), Point(i, 950 - a * 10), Scalar(0, 0, 255), 2, LINE_AA);
		i += 10;
		last = a;

		imshow("s2", huabu);
		write.write(huabu);
		waitKey(0);
	}

	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值