opencv 计算消费时间函数耗时频率 getTickCount() getTickFrequency()
Posted Dontla
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv 计算消费时间函数耗时频率 getTickCount() getTickFrequency()相关的知识,希望对你有一定的参考价值。
用法
#include <opencv2/opencv.hpp>
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);
//...
示例,计算处理时间
源图:
#include <opencv2/opencv.hpp>
#include <iostream>
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 计算消费时间函数耗时频率 getTickCount() getTickFrequency()的主要内容,如果未能解决你的问题,请参考以下文章
opencv基础测量运行时间的函数getTickCount/getCPUTickCount/getTickFrequency