1、cv::getTickCount()与cv::getTickFrequency()搭配使用,计时单位是秒。
使用方法:
double ts = (double)cv::getTickCount();
...
double te = (double)cv::getTickCount();
double T = (te-ts)*1000/cv::getTickFrequency();//单位ms
2、cvGetTickCount()与cvGetTickFrequency()搭配使用,单位是微妙
使用方法:
double ts = (double)cvGetTickCount();
...
double te = (double)cvGetTickCount();
doublt T = (te-ts)/cvGetTickFrequency()*1000;//单位ms
3、GetTickCount()与GetTickFrequency()搭配使用,单位是毫秒
通常用小单位的时间取度量大单位的时间,比如度量ms,通常应选取方法2,这样度量时间更精确。
为了更加精确的计算频率,比如视频帧率,应该以段时间为单位进行计算,比如:
double ts = (double)cvGetTickCount();
int n = 0;
whiile(true)
{
n = n+1;
double te = (double)cvGetTickCount();
double T = (te-ts)/cvGetTickFrequency()*1000;//单位ms
if(T>2000)//2秒统计一次帧率
{
int f = n*1000/T;
ts = te;
n = 0;
}
}