Detector OpenCV FAST
No meumain.cpp Eu tenho um trecho:
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();
...
}
meu arquivo está dizendo:
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
Então, seria de esperar queinspectPoint()
é uma função que está realmente fazendo alguma coisa.
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
}
Estou usando o Visual Studio 2013 e a otimização está definida como "Otimização completa (/ Ox)".
Até onde eu sei, o algoritmo FAST passa por todos os pixels? Suponho que não seja possível que ele realmente processe cada pixel mais rápido que a funçãoinspectPoint()
.
Como o detector FAST é tão rápido? Ou melhor, por que o loop aninhado é tão lento?