OpenCV FAST Detektor
In meinem main.cpp Ich habe einen Auszug:
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();
...
}
meine Date sagt
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
So würde man erwarten, dassinspectPoint()
ist eine Funktion, die tatsächlich etwas tut.
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
}
Ich verwende Visual Studio 2013 und die Optimierung ist auf "Vollständige Optimierung (/Ox)"@ eingestell
Soweit ich weiß, geht der FAST-Algorithmus durch alle Pixel? Ich nehme an, es ist nicht möglich, dass es tatsächlich jedes Pixel schneller verarbeitet als die FunktioninspectPoint()
.
Wie ist der FAST-Detektor so schnell? Oder warum ist die verschachtelte Schleife so langsam?