opencv 计算消费时间函数、耗时、频率 getTickCount() getTickFrequency()

用法

#include 
using namespace cv;
int main(int argc, const char* argv[]) {
	//...
	double count1 = getTickCount();
	//处理
	double count2 = getTickCount();
	double time_consume = (count2 - count1) / getTickFrequency();
	printf("消费时间:%f\n", time_consume);
	//...
}

示例,计算处理时间

源图:
opencv 计算消费时间函数、耗时、频率 getTickCount() getTickFrequency()_第1张图片

#include 
#include 

using namespace cv;

int main(int argc, const char* argv[]) {

	Mat src, dst1, dst2;
	src = imread("./test.jpg");
	//if (src.empty()) {
	if (!src.data){
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("input img");	//默认自动窗口大小
	imshow("input img", src);

	dst1 = Mat::zeros(src.size(), src.type());	//第二个参数是位深度,目前值为16
	dst2 = Mat::zeros(src.size(), src.type());

	double count1 = getTickCount();

	//三个for循环,执行运算 g_dstImage(i,j) =a*g_srcImage(i,j) + b
	for (int y = 0; y < src.rows; y++)
	{
		for (int x = 0; x < src.cols; x++)
		{
			for (int c = 0; c < 3; c++)	//三个通道
			{
				dst1.at<Vec3b>(y, x)[c] = src.at<Vec3b>(y, x)[c] * 2;	//不饱和滤除
				dst2.at<Vec3b>(y, x)[c] = saturate_cast<uchar>(src.at<Vec3b>(y, x)[c] * 2);	//饱和滤除
			
			}
		}
	}
	double count2 = getTickCount();

	double time_consume = (count2 - count1) / getTickFrequency();
	printf("消费时间:%f\n", time_consume);
	

	namedWindow("output img1");	//默认自动窗口大小
	namedWindow("output img2");
	imshow("output img1", dst1);
	imshow("output img2", dst2);

	waitKey(0);
	return 0;
}

运行结果:
在这里插入图片描述
约40ms

调试中打印下count看看
在这里插入图片描述
参考文章:【opencv4】opencv视频教程 C++(opencv教程)3、矩阵的掩膜操作(filter2D)

你可能感兴趣的:(Opencv,opencv,计算机视觉,人工智能)