C++ 多尺度检测循环在OpenCV'中的工作原理;猪的检测?
在Dalal和Triggs关于猪的论文中,多尺度检测似乎是通过扫描图像金字塔来实现的。但是我找不到模块/objdetect/src/hog.cpp中执行金字塔扫描/循环的部分。是我的理解错误,还是我读取了错误的源文件?如果您查看此函数的源代码C++ 多尺度检测循环在OpenCV'中的工作原理;猪的检测?,c++,opencv,image-processing,object-detection,C++,Opencv,Image Processing,Object Detection,在Dalal和Triggs关于猪的论文中,多尺度检测似乎是通过扫描图像金字塔来实现的。但是我找不到模块/objdetect/src/hog.cpp中执行金字塔扫描/循环的部分。是我的理解错误,还是我读取了错误的源文件?如果您查看此函数的源代码 void HOGCache::init(const HOGDescriptor* _descriptor, const Mat& _img, Size _paddingTL, Size _paddingBR, boo
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
//
正如注释所解释的,循环是为了优化而展开的,这也许就是为什么快速浏览源代码很难找到它们的原因