I'm using SIFT feature detector in OpenCV 4.5.2. By tuning the nOctaveLayers parameter in cv::SIFT::create(), I get these results from detectAndCompute():
| nOctaveLayers | KeyPoints | Time Cost (ms) |
|---|---|---|
| 1 | 1026 | 63.41 |
| 2 | 1795 | 45.07 |
| 3 | 2043 | 45.74 |
| 4 | 2173 | 47.83 |
| 5 | 2224 | 51.86 |
To my understanding, there should be less computation with fewer octave layers, but why SIFT costs significantly more time with only 1 octave layer?
I also tested detect() and compute() separately, and they both cost more time when nOctaveLayers is 1, which confuses me a lot.
The test image is here (from TUM open dataset). Thanks ahead for any help.
[Edit for @Micka] My test code:
const int test_num = 100;
const int layers = 5;
cout << "layers: " << layers << endl;
auto sift = SIFT::create(0, layers);
vector<KeyPoint> kps;
Mat descs;
auto t1 = chrono::high_resolution_clock::now();
for (int i = 0; i < test_num; ++i)
sift->detectAndCompute(img_src, noArray(), kps, descs);
auto t2 = chrono::high_resolution_clock::now();
cout << "num of kps: " << kps.size() << endl;
cout << "avg time cost: " << chrono::duration<double>(t2 - t1).count() * 1e3 / test_num << endl;
For each nOctaveLayers configuration, I change layers value in the code, recompile & run & record the result.