# OpenCV 利用getTickCount()与getTickFrequency()计算执行时间

double t1 = (double)getTickCount();
.
.
.
double t2 = (double)getTickCount();
cout<<"time:"<<(t2-t1)*1000/getTickFrequency()<<endl;

getTickCount()与getTickFrequency()都被定义在core.hpp文件下：

//! Returns the number of ticks.

/*!
The function returns the number of ticks since the certain event (e.g. when the machine was turned on).
It can be used to initialize cv::RNG or to measure a function execution time by reading the tick count
before and after the function call. The granularity of ticks depends on the hardware and OS used. Use
cv::getTickFrequency() to convert ticks to seconds.
*/
CV_EXPORTS_W int64 getTickCount();

/*!
Returns the number of ticks per seconds.

The function returns the number of ticks (as returned by cv::getTickCount()) per second.
The following code computes the execution time in milliseconds:

\code
double exec_time = (double)getTickCount();
// do something ...
exec_time = ((double)getTickCount() - exec_time)*1000./getTickFrequency();
\endcode
*/
CV_EXPORTS_W double getTickFrequency();

/*!
Returns the number of CPU ticks.

On platforms where the feature is available, the function returns the number of CPU ticks
since the certain event (normally, the system power-on moment). Using this function
one can accurately measure the execution time of very small code fragments,
for which cv::getTickCount() granularity is not enough.
*/
CV_EXPORTS_W int64 getCPUTickCount();

getTickCount()：用于返回从操作系统启动到当前所经的计时周期数，看名字也很好理解，get Tick Count(s)。 getTickFrequency()：用于返回CPU的频率。get CPU Tick Count(s)。这里的单位是秒。

96 篇文章35 人订阅

0 条评论

## 相关文章

### 视觉搜索和Neo4j的最后一公里

“ 最后一公里 ”是电信行业使用的一个术语，指系统为实际使用该系统的客户提供链接。就图形数据库而言，它指的是终端用户可以从图中提取有价值的信息和洞察力。我们...

1633

24410

1888

### Silverlight中摄像头的运用—part2

Silverlight 4 中摄像头的运用—part1 将跟踪颜色视作输入 好了，我们能够跟踪到这个颜色了，那这么做的意义是什么呢？实际上，我们可以根据它的位...

1816

571

3.6K19

1875

1163

831

21510