OpenCV计算时间检测功能

Dav*_*ola 0 c++ opencv surf feature-detection

我正在尝试计算我的程序从图像中检测关键点所需的时间。如果在我的 C++ 程序中我执行两次(使用相同的图像),则两者之间存在巨大差异。第一次大约用 600-800 毫秒,第二次只用 100-200 毫秒。

有谁知道发生了什么事?

这是我获取时间的代码:

struct timeval t1, t2;

Ptr<SURF> detector = SURF::create(400);

gettimeofday(&t1, 0x0);

detector->detect( imagen1, keypoints_1 );

gettimeofday(&t2, 0x0);

int milliSeconds = Utils::calculateDiff(t1, t2);
Run Code Online (Sandbox Code Playgroud)

这是我计算差异的代码:

static int calculateDiff(timeval t1, timeval t2)
{
    return (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec)/1000;
}
Run Code Online (Sandbox Code Playgroud)

这是一个示例:

样本

ber*_*rak 5

请注意, gettimeofday 使用的是 wall-time,而像这样的问题通常需要 cpu/clock-time。

对于分析,尝试一些东西(甚至更便携),如下所示:

int64 t0 = cv::getTickCount();
//
// some lengthy op.
//
int64 t1 = cv::getTickCount();
double secs = (t1-t0)/cv::getTickFrequency();
Run Code Online (Sandbox Code Playgroud)