⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fps.htm

📁 cmu车辆检测以及跟踪程序
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0047)http://www.cc.gatech.edu/ccg/people/david/fps.h -->
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY><XMP>#ifndef _FPS_H_
#define _FPS_H_

/*********************************************************************
 * Instructions
 *
 * (1) Create an FPS object
 * (2) Call addFrame() for each new frame
 *     (i.e. each occurence of event you're tracking)
 * (3) Call display(ms) to display the current fps every
 *     [ms] milliseconds
 * (3a) or, call display(ms, msg) to do the same with a custom message
 * (3b) or, call getFps(ms) to get the fps directly
 *       if the fps value was calculated more than ms milliseconds ago
 *       it will be recomputed -- no paramter => 500ms
 * (4) optionally, you can call reset() at any time to reset the tracker
 *
 * example:
 *  ...
 *  // perform possibly slow operation and display fps each second
 *  FPS fps;
 *  while(1){
 *   performSlowOperation();
 *   fps.addFrame();
 *   fps.display(1000);
 *  }
 *  ...
 *********************************************************************/

#ifndef WIN32
#include <sys/time.h>
#endif

class FPS{
protected:

#ifdef WIN32
  int last, cur;
#else 
  struct timeval last, cur;
#endif
  long n;

  float fps;

public:

  void addFrame(){
    n++;
  }

  int display(long minMS, char *msg){
    if (ready(minMS)){
      printf("%s%0.3f\n", msg, fps);
      return 1;
    }
    return 0;
  }

  int ready(long minMS){
    long dm;     // difference in seconds, micro, and milli

#ifdef WIN32
    cur = GetTickCount();
    dm = cur - last;
#else
    long ds, du;
    gettimeofday(&cur, NULL);
    ds = cur.tv_sec - last.tv_sec;
    du = 1000000*ds - last.tv_usec + cur.tv_usec;
    dm = du / 1000;
#endif
    
    if (dm>=minMS){
      fps = 1000.0f * (float)n / (float)dm;
      n = 0;

#ifdef WIN32
      last = cur;
#else
      last.tv_sec = cur.tv_sec;
      last.tv_usec = cur.tv_usec;      
#endif
      return 1;
    }
    return 0;
  }
  
  float getFps(int v = 500){
    ready(v);
    return fps;
  }

  int display(long minMS){
    return display(minMS, "fps: ");
  }

  void reset(){
    n = 0;
    fps = 0.0f;
#ifdef WIN32
    last = GetTickCount();
#else
    gettimeofday(&last, NULL);
#endif
  }

  FPS(){
    reset();
  }  

};

#endif
</XMP></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -