簡體   English   中英

OpenCV FAST檢測器

[英]OpenCV FAST detector

在我的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()是一個實際上正在做某事的函數。

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)”。

據我所知,FAST算法遍歷所有像素嗎? 我想它實際上不可能比函數inspectPoint()更快地處理每個像素。

FAST檢測器有多快? 或更確切地說,為什么嵌套循環這么慢?

從源代碼的快速瀏覽看來,fastFeatureDetector中對SSE和OpenCL進行了廣泛的優化: github.com/Itseez/opencv/blob/master/modules/features2d/src/‌

SSE和OpenCL並非特定於任何CPU。 SSE利用CPU的能力同時對多條數據執行一條指令(計算)。 因此,根據CPU的體系結構,這可以將速度提高到2倍或遠遠超過4倍。 OpenCL可以利用GPU,這也可以顯着提高某些圖像處理操作的性能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM