title: Explain the working of shadow detection code implemented in opencv?
body: <p>I am trying to understand the code implemented in opencv for shadow detection the link to which is <a href="https://github.com/Itseez/opencv/blob/master/modules/video/src/bgfg_gaussmix2.cpp" rel="nofollow">Here</a></p>
  
  <p>The code is</p>
  
  <pre><code>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 &lt; nmodes; mode++, mean += nchannels )
      {
          GMM g = gmm[mode];
  
          float numerator = 0.0f;
          float denominator = 0.0f;
          for( int c = 0; c &lt; nchannels; c++ )
          {
              numerator   += data[c] * mean[c];
              denominator += mean[c] * mean[c];
          }
  
          // no division by zero allowed
          if( denominator == 0 )
              return false;
  
          // if tau &lt; a &lt; 1 then also check the color distortion
          if( numerator &lt;= denominator &amp;&amp; numerator &gt;= tau*denominator )
          {
              float a = numerator / denominator;
              float dist2a = 0.0f;
  
              for( int c = 0; c &lt; nchannels; c++ )
              {
                  float dD= a*mean[c] - data[c];
                  dist2a += dD*dD;
              }
  
              if (dist2a &lt; Tb*g.variance*a*a)
                  return true;
          };
  
          tWeight += g.weight;
          if( tWeight &gt; TB )
              return false;
      };
      return false;
  }
  </code></pre>
  
  <p>The nchannels i assume are the rgb channels for each pixel. I am unsure of what dist2a, numerator and denominator is. foreground and background may be but why do we multiply 'data and mean' and 'mean and mean'. The paper implemented here is Zivkovic. “Improved adaptive Gausian mixture model for background subtraction”, International Conference Pattern Recognition, UK, August, 2004,</p>
  
  <p>And the logic is: In RGB color space E represents background and I foreground for each pixel i. The intensity difference Between E and I is computed by minimizing 'a' given by (a) = (Ii-aEi)^2 
  And chromatic difference is given by CDi = |Ii-aEi|
  If the values are within the threshold the pixels are classified as shadows.
  <a href="http://i.stack.imgur.com/iRvfi.png" rel="nofollow">This image will better explain it</a></p>
  
  <p>Please help me Map the logic with the code.</p>