前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >OpenCV 利用getTickCount()与getTickFrequency()计算执行时间

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

作者头像
chaibubble
发布2018-01-02 10:22:10
2.5K0
发布2018-01-02 10:22:10
举报
文章被收录于专栏:深度学习与计算机视觉

其实这是个很简单的应用,贴出来是因为我经常能用到这两个函数,顺便写一下吧。

代码语言:javascript
复制
double t1 = (double)getTickCount();
.
.
.
double t2 = (double)getTickCount();
cout<<"time:"<<(t2-t1)*1000/getTickFrequency()<<endl;

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

代码语言:javascript
复制
//! 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)。这里的单位是秒。

所以剩下的就很清晰了: 总次数/一秒内重复的次数 = 时间(s)

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-05-01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档