http://blog.youkuaiyun.com/pp5576155/article/details/7029699 #define CV_WRAP
HOGDescriptor一共有4个构造函数,前三个有CV_WRAP前缀,表示它们是从DLL里导出的函数,即我们在程序当中可以调用的函数;最后一个没有上述的前缀,所以我们暂时用不到,它其实就是一个拷贝构造函数。
CV_WRAP HOGDescriptor() : winSize(64,128), blockSize(16,16), blockStride(8,8),
cellSize(8,8), nbins(9), derivAperture(1), winSigma(-1),
histogramNormType(HOGDescriptor::L2Hys), L2HysThreshold(0.2), gammaCorrection(true),
nlevels(HOGDescriptor::DEFAULT_NLEVELS)
{}
CV_WRAP HOGDescriptor(Size _winSize, Size _blockSize, Size _blockStride,
Size _cellSize, int _nbins, int _derivAperture=1, double _winSigma=-1,
int _histogramNormType=HOGDescriptor::L2Hys,
double _L2HysThreshold=0.2, bool _gammaCorrection=false,
int _nlevels=HOGDescriptor::DEFAULT_NLEVELS)
: winSize(_winSize), blockSize(_blockSize), blockStride(_blockStride), cellSize(_cellSize),
nbins(_nbins), derivAperture(_derivAperture), winSigma(_winSigma),
histogramNormType(_histogramNormType), L2HysThreshold(_L2HysThreshold),
gammaCorrection(_gammaCorrection), nlevels(_nlevels)
{}
The macros
CV_Assert and
CV_DbgAssert evaluate the specified expression and if it is 0, the macros raise an error. The macro
CV_Assert checks the condition in both Debug and Release configurations, while
CV_DbgAssertis only retained in the Debug configuration.如果判断为0,则引发一个错误
size_t HOGDescriptor::getDescriptorSize() const
{
CV_Assert(blockSize.width % cellSize.width == 0 &&
blockSize.height % cellSize.height == 0);
CV_Assert((winSize.width - blockSize.width) % blockStride.width == 0 &&
(winSize.height - blockSize.height) % blockStride.height == 0 );
return (size_t)nbins*
(blockSize.width/cellSize.width)*
(blockSize.height/cellSize.height)*
((winSize.width - blockSize.width)/blockStride.width + 1)*
((winSize.height - blockSize.height)/blockStride.height + 1);
}
以上代码为HOG维度计算。
区间归一化(Block normalization)
作者采用了四中不同的方法对区间进行归一化,并对结果进行了比较。引入v表示一个还没有被归一化的向量,它包含了给定区间(block)的所有直方图信息。| | vk | |表示v的k阶范数,这里的k去1、2。用e表示一个很小的常数。这时,归一化因子可以表示如下:
L2-norm:
L1-norm:
L1-sqrt:
还有第四种归一化方式:L2-Hys,它可以通过先进行L2-norm,对结果进行截短(clipping),然后再重新归一化得到。作者发现:采用L2-Hys, L2-norm, 和 L1-sqrt方式所取得的效果是一样的,L1-norm稍微表现出一点点不可靠性。但是对于没有被归一化的数据来说,这四种方法都表现出来显著的改进。
Size winSize;//窗口大小
Size blockSize;//Block大小
Size blockStride;//block每次移动宽度包括水平和垂直两个方向
Size cellSize;//Cell单元大小
int nbins;//直方图bin数目
int derivAperture;//不知道什么用
double winSigma;//高斯函数的方差
int histogramNormType;//直方图归一化类型,具体见论文
double L2HysThreshold;//L2Hys化中限制最大值为0.2
bool gammaCorrection;//是否Gamma校正
vector<float> svmDetector;//检测算子
namespace cv
{
double HOGDescriptor::getWinSigma() const
{
//winSigma默认为-1,然而有下式知,实际上为4;否则自己选择参数
return winSigma >= 0 ? winSigma : (blockSize.width + blockSize.height)/8.;
}
}