解释在opencv中实现的阴影检测代码的工作原理

Explain the working of shadow detection code implemented in opencv?

本文关键字:代码 工作 检测 阴影 opencv 实现 解释      更新时间:2023-10-16

我正在尝试理解opencv中实现的用于阴影检测的代码,其链接在这里

代码是

detectShadowGMM(const float* data, int nchannels, int nmodes,
                const GMM* gmm, const float* mean,
                float Tb, float TB, float tau)
{
    float tWeight = 0;
    // check all the components  marked as background:
    for( int mode = 0; mode < nmodes; mode++, mean += nchannels )
    {
        GMM g = gmm[mode];
        float numerator = 0.0f;
        float denominator = 0.0f;
        for( int c = 0; c < nchannels; c++ )
        {
            numerator   += data[c] * mean[c];
            denominator += mean[c] * mean[c];
        }
        // no division by zero allowed
        if( denominator == 0 )
            return false;
        // if tau < a < 1 then also check the color distortion
        if( numerator <= denominator && numerator >= tau*denominator )
        {
            float a = numerator / denominator;
            float dist2a = 0.0f;
            for( int c = 0; c < nchannels; c++ )
            {
                float dD= a*mean[c] - data[c];
                dist2a += dD*dD;
            }
            if (dist2a < Tb*g.variance*a*a)
                return true;
        };
        tWeight += g.weight;
        if( tWeight > TB )
            return false;
    };
    return false;
}

我假设的n通道是每个像素的rgb通道。我不确定dist2a,分子和分母是什么。前景和背景可能是,但为什么我们要乘以"数据和平均值"和"平均值和平均值"。这里实现的论文是日夫科维奇。"用于背景减法的改进自适应高斯混合模型",国际会议模式识别,英国,2004 年 8 月,

逻辑是:在RGB色彩空间中,E代表背景,I表示每个像素i的前景。E 和 I 之间的强度差是通过最小化 (a) = (Ii-aEi)^2 给出的"a"来计算的色差由 CDi = |高爱|如果值在阈值范围内,则像素被分类为阴影。这张图片会更好地解释它

请帮我用代码映射逻辑。

本文中解释了实现一种实时鲁棒背景减法和阴影检测的统计方法由塔纳拉特·霍普拉塞特 大卫·哈伍德 拉里·戴维斯这在上述论文的参考文献中存在。

下面的链接显示了用于实现的公式。 点击这里查看图片