gpt4 book ai didi

c++ - OpenCV FAST 检测器

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:40 26 4
gpt4 key购买 nike

在我的 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,这也可以显着提升某些图像处理操作的性能。

关于c++ - OpenCV FAST 检测器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36749923/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com