getTickCount 函数

返回 CPU 自某个事件(如启动电脑)以来走过的时钟周期数。

getTickFrequency 函数

返回 CPU 一秒钟所走过的时钟周期数。

 

二者结合使用,可以用来计算和观察一段程序或一种算法耗时。

 

代码演示:

#include<opencv.hpp>
using namespace cv;
int main() {
    Mat src = imread("C:/Users/齐明洋/Desktop/1.jpg");
    Mat gray;
    double time_start = static_cast<double>(getTickCount());
    cvtColor(src, gray, COLOR_BGR2GRAY);
    double time_end = static_cast<double>(getTickCount());
    double cost_time = (time_end - time_start) / getTickFrequency();
    printf("%lf s", cost_time);
    imshow("gray", gray);
    waitKey(0);
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2022-01-14
  • 2022-12-23
  • 2021-07-14
相关资源
相似解决方案