opencv 计时 帧率
【摘要】
C++版的getTickFrequency返回的是每秒钟的tick数
C版的cvGetTickFrequency返回的是每微妙的tick数
double t = (double)cvGetTickCount(); // 算法过程 t = (double)cvGetTickCount() - t;
printf( "run time = %gms\...
C++版的getTickFrequency返回的是每秒钟的tick数
C版的cvGetTickFrequency返回的是每微妙的tick数
double t = (double)cvGetTickCount();
// 算法过程
t = (double)cvGetTickCount() - t;
printf( "run time = %gms\n", t/(cvGetTickFrequency()*1000) );
这//opencv 中如何进行程序的计时呢?
int64 tStart = 0;
int64 tDuration = 0;
tStart = getTickCount();
tDuration = getTickCount() - tStart;
double fps = static_cast<double>(getTickFrequency() / tDuration);
printf("fps:%f\n",fps);
计时函数1. 纯C 高精度(100ns)测量慢
[cpp] view plain copy
#include <Windows.h>
#include <stdio.h>
int timer1_test()
{
LARGE_INTEGER start;
LARGE_INTEGER end ;
LARGE_INTEGER frequency;
int i = 0;
if (!QueryPerformanceFrequency(&frequency))
{
return -1;
}
QueryPerformanceCounter(&start); //开始计时
// for (int i = 0; i < 100000; ++i)
// {
// ;// 用循环来测试计时
// }
Sleep(1);
QueryPerformanceCounter(&end); //结束计时
printf("main cost:%f\n", (double)(end.QuadPart - start.QuadPart) / (double)frequency.QuadPart); //打印for循环执行时间
getchar();
return 0;
}
2.纯C 低精度(1ms)测量快
w plai copy
#include <stdio.h>
#include <time.h>
void timer2_test()
{
clock_t start,end;
start=clock();
Sleep(1000);
end=clock();
double duration = (double)(end - start);
cout << "--> time: " << duration << " s" << endl;
printf("time : %f ms \n",duration/1000);
}
3.C++ OpenCV测试 高精度 view p copy
#include"opencv.hpp"
void timer3_test()
{
int64 start=0,end=0;
start = getTickCount();
Sleep(1000);
end = getTickCount();
cout << "The differences: " << 1000.0*(end - start)/getTickFrequency()<<" ms"<< endl;
}
这个是在多线程下比较精确的#include <time.h>
struct timespec time1={0,0};
struct timespec time2={0,0};
int main()
{
clock_gettime(CLOCK_REALTIME,&time1);
sRect result = tracker.update( frame);
clock_gettime(CLOCK_REALTIME,&time2);
///
sum_time += (time2.tv_sec-time1.tv_sec)*1000+(time2.tv_nsec-time1.tv_nsec)/1000000 ;
printf("time : %d ms \n", (time2.tv_sec-time1.tv_sec)*1000+(time2.tv_nsec-time1.tv_nsec)/1000000);
return 0;
}
文章来源: blog.csdn.net,作者:网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/60138923
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)