《OpenCV计时函数》

OpenCV的计时函数有两种版本:C版本和C++版本,两种版本的计时函数获取的时间单位不一样,但是使用方法是一样的。

一、C版本

函数原型

cvGetTickCount()和cvGetTickFrequency()函数,此函数得到的时间单位为微秒(us)。

示例代码
double start = static_cast<double>(cvGetTickCount());
double time = ((double)cvGetTickCount() - start) / cvGetTickFrequency();
cout << "所花费时间为:" << time << "us" << endl;

二、C++版本

函数原型

getTickCount()和getTickFrequency()函数,此函数得到的时间单位为秒(s)。

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

getTickFrequency():返回CPU一秒中所走的时钟周期数。所以可以以秒为单位对某运算时间计时。

示例代码
double start = static_cast<double>(getTickCount());
double time = ((double)getTickCount() - start) / getTickFrequency();
cout << "所用时间为:" << time << "秒" << endl;


猜你喜欢

转载自blog.csdn.net/mars_xiaolei/article/details/81033948