OpenCV FAST检测器 [英] OpenCV FAST detector

查看:60
本文介绍了OpenCV FAST检测器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 main.cpp 中有一段摘录:

Ptr<FastFeatureDetector> fastDetector = FastFeatureDetector::create(80, true);

while (true) {
    Mat image = // get grayscale image 1280x720

    timer.start();
    detector->detect(image, keypoints);
    myfile << "FAST\t" << timer.end() << endl; // timer.end() is how many seconds elapsed since last timer.start()


    keypoints.clear();

    timer.start();
    for (int i = 3; i < image.rows - 3; i++)
    {
        for (int j = 3; j < image.cols - 3; j++)
        {
            if (inspectPoint(image.data, image.cols, i, j)) {
                // this block is never entered
                KeyPoint keypoint(i, j, 3);
                keypoints.push_back(keypoint);
            }
        }
    }
    myfile << "Custom\t" << timer.end() << endl;
    myfile << endl;
    myfile.flush();
    ...
}

myfile 说:

FAST    0.000515495
Custom  0.00221361

FAST    0.000485697
Custom  0.00217653

FAST    0.000490001
Custom  0.00219044

FAST    0.000484373
Custom  0.00216329

FAST    0.000561184
Custom  0.00233214

因此,人们希望 inspectPoint()是一个实际上正在做某事的函数.

So one would expect that inspectPoint() is a function that is actually doing something.

bool inspectPoint(const uchar* img, int cols, int i, int j) {
    uchar p = img[i * cols + j];
    uchar pt = img[(i - 3)*cols + j];
    uchar pr = img[i*cols + j + 3];
    uchar pb = img[(i + 3)*cols + j];
    uchar pl = img[i*cols + j - 3];

    return cols < pt - pr + pb - pl + i; // just random check so that the optimizer doesn't skip any calculations
}

我正在使用Visual Studio 2013,并且优化设置为完全优化(/Ox)".

I am using Visual Studio 2013 and the optimization is set to "Full Optimization (/Ox)".

据我所知,FAST算法遍历所有像素吗?我想它实际上不可能比函数 inspectPoint()更快地处理每个像素.

As far as I know, FAST algorithm goes through all pixels? I suppose it is not possible that it actually processes each pixel faster than the function inspectPoint().

FAST检测器有多快?或者更确切地说,为什么嵌套循环这么慢?

How is FAST detector so fast? Or rather, why is the nested loop so slow?

推荐答案

通过快速浏览源代码,可以发现在fastFeatureDetector中对SSE和OpenCL进行了广泛的优化:

From a quick browsing of the source code it looks like there is extensive optimization for SSE and OpenCL in fastFeatureDetector: github.com/Itseez/opencv/blob/master/modules/features2d/src/‌

SSE和OpenCL并非特定于任何CPU.SSE利用CPU的能力同时对多条数据执行一条指令(计算).因此,根据CPU的体系结构,这可以将速度提高到2倍或远远超过4倍.OpenCL可以利用GPU,这也可以显着提高某些图像处理操作的性能.

SSE and OpenCL are not specific to any CPU. SSE utilizes the CPU's ability to perform a single instruction (calculation) on multiple pieces of data simultaneously. So depending on the CPU's architecture this can improve speeds as little as 2x or well beyond 4x. OpenCL can utilize the GPU which can also give major performance boosts to certain image processing operations.

这篇关于OpenCV FAST检测器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆