您的位置:首页 > 编程语言

OpenCV getTickCount统计代码运行时间

2015-04-26 09:36 330 查看
       

        在OpenCV编程中,可能会遇到比较不同算法之间的运算复杂度及时耗的问题,下面给出一个统计代码运行时间的demo,里面用到getTickCount函数,使用时需要添加头文件#include "opencv2/imgproc/imgproc.hpp"

#include<iostream>
#include <opencv2/opencv.hpp>
#include "opencv2/imgproc/imgproc.hpp"

using namespace cv;
using namespace std;

int main(){
double t = (double)getTickCount();//开始时间
for (int i = 0; i <= 1000; i++){}//可替换成其他代码
t = (double)getTickCount() - t;//代码运行时间=结束时间-开始时间
printf("execution time = %gms\n", t*1000. / getTickFrequency());//转换时间单位并输出代码运行时间
system("pause");//让dos界面停留
return 0;
}

代码运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息