0
在關於HOG的Dalal和Triggs文件中,似乎多尺度檢測通過掃描圖像金字塔來工作。但是我找不到執行金字塔掃描/循環的modules/objdetect/src/hog.cpp中的哪一部分。我的理解錯了,還是我讀了錯誤的源文件?多尺度檢測環路如何在OpenCV的HOG檢測中工作?
在關於HOG的Dalal和Triggs文件中,似乎多尺度檢測通過掃描圖像金字塔來工作。但是我找不到執行金字塔掃描/循環的modules/objdetect/src/hog.cpp中的哪一部分。我的理解錯了,還是我讀了錯誤的源文件?多尺度檢測環路如何在OpenCV的HOG檢測中工作?
如果你看看源代碼,這個功能
void HOGCache::init(const HOGDescriptor* _descriptor,
const Mat& _img, Size _paddingTL, Size _paddingBR,
bool _useCache, Size _cacheStride)
你會看到下面的評論
// Initialize 2 lookup tables, pixData & blockData.
// Here is why:
//
// The detection algorithm runs in 4 nested loops (at each pyramid layer):
// loop over the windows within the input image
// loop over the blocks within each window
// loop over the cells within each block
// loop over the pixels in each cell
//
// As each of the loops runs over a 2-dimensional array,
// we could get 8(!) nested loops in total, which is very-very slow.
//
// To speed the things up, we do the following:
// 1. loop over windows is unrolled in the HOGDescriptor::{compute|detect} methods;
// inside we compute the current search window using getWindow() method.
// Yes, it involves some overhead (function call + couple of divisions),
// but it's tiny in fact.
// 2. loop over the blocks is also unrolled. Inside we use pre-computed blockData[j]
// to set up gradient and histogram pointers.
// 3. loops over cells and pixels in each cell are merged
// (since there is no overlap between cells, each pixel in the block is processed once)
// and also unrolled. Inside we use PixData[k] to access the gradient values and
// update the histogram
//
正如註釋說明,這些環展開了優化的目的,這也許是爲什麼通過源代碼快速掃描很難找到它們。