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); }