现在的位置: 首页 > 综合 > 正文

opencv学习笔记-入门(31) 计时函数的应用及视频处理心得

2013年08月20日 ⁄ 综合 ⁄ 共 868字 ⁄ 字号 评论关闭

1.在不少算法中,总会遇到计算算法用时的情况,一般使用getTickCount.在opencv2refman.pdf中介绍了这个函数

getTickCount

Returns the number of ticks.

C++:int64 getTickCount()

Python:cv2.getTickCount()->retval

The function returns the number of ticks after the certain event (for example, when the machine was turned on). It
can be used to initializeRNG()or to measure a function execution time by reading the tick count before and after the
function call. See also the tick frequency.

其中就是返回算法用时的时钟次数,int64为有符号64位整数数据类型。

用法如下:

#include <opencv2/core/core.hpp>
//#include <opencv2/opencv.hpp>
#include "iostream"
using namespace std;
using namespace cv;  //应当添加的,后则会出错

int main()
{
	double t = (double)getTickCount();
	cout << "hai" << "hei";
	for(int i = 0; i < 10; i++)
	{
		cout << i;
	}
	t = (double)getTickCount() - t;
	cout << "the time is :" << t << endl;

	cin.get();
	cin.get();
	return 0;
}

这样得到了算法运行的时钟的次数。
2.在对视频进行处理的时候,今天遇到处理起来特别的慢,我用的视频大小是640*440的为MP4格式的,处理起来和用摄像头直接采集的差很多,我换了一个avi 的大小是320 *270的,效果好很多。opencv看来在对avi的视频处理起来效果要好很多啊。

抱歉!评论已关闭.