static void icvUpdateFullWindow( double* src_pixel, int nChannels, int* match,
CvGaussBGPoint* g_point,
const CvGaussBGStatModelParams
*bg_model_params )
{
const double learning_rate_weight = (1.0/(double)bg_model_params->win_size);
for(int k = 0; k < bg_model_params->n_gauss; k++)
{
//这个就是更新权重,w=(1-a)w+a*m (a:更新率,m是匹配,匹配就是1,不匹配就是0)
//可以改写:
//
g_point->g_values[k].weight = g_point->(1-learning_rate_weight)*g_values[k].weight
// +learning_rate_weight*(double)match[k]
g_point->g_values[k].weight = g_point->g_values[k].weight +
(learning_rate_weight*((double)match[k] -
g_point->g_values[k].weight));
//更新方差,均值等参数
if(match[k])
{
//learning_rate_gaussian实际就是p(在更新方差和均值要用的参数)
//实际上可以这样设置:
//double learning_rate_gaussian = ((double)match[k]*learning_rate_weight)/(g_point->g_values[k].weight
double learning_rate_gaussian = (double)match[k]/(g_point->g_values[k].weight*
(double)bg_model_params->win_size);
for(int m = 0; m < nChannels; m++)
{
//均值和方差的更新公式
//u = (1-p)*u+p*x = u+p*(x-u)
//o = (1-p)*o*o+p*(x-u)*(x-u)
const double tmpDiff = src_pixel[m] - g_point->g_values[k].mean[m];
g_point->g_values[k].mean[m] = g_point->g_values[k].mean[m] +
(learning_rate_gaussian * tmpDiff);
g_point->g_values[k].variance[m] = g_point->g_values[k].variance[m]+
(learning_rate_gaussian*((tmpDiff*tmpDiff) - g_point->g_values[k].variance[m]));
}
}
}
}
{
}