接下来开始Haar特征提取算法的解析:
在本算法中,Haar特征选取了6种特征子,代码及解析如下:
6种Haar特征描述子计算如下,接下来分析Haar特征的应用:
//生成Haar特征向量 192维 32*6=192维
void HaarFeatures::GenerateSystematic()
{
float x[] = {0.2f, 0.4f, 0.6f, 0.8f};
float y[] = {0.2f, 0.4f, 0.6f, 0.8f};
float s[] = {0.2f, 0.4f};
for (int iy = 0; iy < 4; ++iy) //取x[]中数,窗口系数
{
for (int ix = 0; ix < 4; ++ix) //取y[]中数,窗口系数
{
for (int is = 0; is < 2; ++is) //取s[]中数,窗口系数
{
FloatRect r(x[ix]-s[is]/2, y[iy]-s[is]/2, s[is], s[is]);//获取窗口大小,共32个
for (int it = 0; it < 6; ++it) //it为选取Haar特征描述子类型(共6种)
{
m_features.push_back(HaarFeature(r, it));
}
}
}
}
}
void HaarFeatures::UpdateFeatureVector(const Sample& s)
{
for (int i = 0; i < m_featureCount; ++i)
{
//归一化
m_featVec[i] = m_features[i].Eval(s);
}
}