在处理图像数据时,经常需要测算性能数据,其中计算耗时是一个关键指标。此处,介绍如何利用opencv来进行计时。具体见代码注释
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main() {
//getTickCount获取CPU自某个事件以来走过的时钟周期数,例如开机
double start = static_cast<double>(getTickCount());
for (int i = 0; i < 1e9; i++)
for (int j = 0; j < 1e9; j++);
double end = static_cast<double>(getTickCount());
// getTickFrequency 获取CPU一秒钟走过的时钟周期数
double run_time = (end - start) / getTickFrequency();
cout << "run_time=" << run_time << " seconds" << endl;
system("Pause");
}
结果如下: