计算波峰时间

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
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(1000, 1000, CV_8UC3, Scalar(0, 0, 0));
	line(huabu, Point(5, 0), Point(5, 950), Scalar(255, 255, 255), 1, LINE_AA);
	line(huabu, Point(5, 950), Point(950, 950), Scalar(255, 255, 255), 2, LINE_AA);
	VideoCapture capture("34.avi");
	//double fps = capture.get(CV_CAP_PROP_FPS);
	//double pauseTime = 3000 / fps;
	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);

		//namedWindow("原图1", WINDOW_NORMAL);
		//imshow("原图1", s1);
		//namedWindow("灰度1", WINDOW_NORMAL);
		//imshow("灰度1", s2);
		//--------阈值化

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

		namedWindow("阈值1", WINDOW_NORMAL);
		imshow("阈值1", s2);
		double a = sum(s2);
		//double *p = &a;
		//vector<Point>g;
		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;
		namedWindow("画布",WINDOW_NORMAL);
		imshow("画布", huabu);
		/*double t2 = (double)getTickCount();
		//double t3 = t2 - t1;
		cout << "time:" << (t2-t1)/ (getTickFrequency()) <<"秒"<< endl;*/
		double dd = capture.get(CV_CAP_PROP_POS_MSEC)/1000;
		if (capture.get(CAP_PROP_POS_FRAMES) == 4)
		{
			d1 = dd;
			cout << "第一次到最高点需要的时间:" << d1 <<"秒"<< endl;
		}
		if (capture.get(CAP_PROP_POS_FRAMES) == 7)
		{
		    d2 = dd;
			cout << "第一次到最低点需要的时间:" << d2-d1 << "秒" << endl;
		}
		if (capture.get(CAP_PROP_POS_FRAMES) == 10)
		{
			d3 = dd;
			cout << "第二次到最高点需要的时间:" << d3-d2 << "秒" << endl;
		}
		if (capture.get(CAP_PROP_POS_FRAMES) == 13)
		{
			d4 = dd;
			cout << "第二次到最低点需要的时间:" << d4 - d3 << "秒" << endl;
		}
		if (capture.get(CAP_PROP_POS_FRAMES) == 15)
		{
			d5 = dd;
			cout << "第三次到最高点需要的时间:" << d5-d4 << "秒" << endl;
		}
		if (capture.get(CAP_PROP_POS_FRAMES) == 17)
		{
			d6 = dd;
			cout << "第三次到最低点需要的时间:" << d6 - d5 << "秒" << endl;
		}
		
		waitKey(3);
	}

	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值