title: Remove Shadow from Extracted Foreground
body: <p>I'm newbie with OpenCV + C++ + Visual Studio 2012. And now I need to learn them.
  Here's the code for background substraction/foreground extraction, and I need to remove the shadow from the foreground, and include them into background model.</p>
  
  <p><pre>
      include opencv2/opencv.hpp
      include iostream
      include vector</p>
  
  <code>int main(int argc, char *argv[])
  {
      cv::Mat frame;
      cv::Mat back;
      cv::Mat fore;
      cv::VideoCapture cap(0);
  
      cv::BackgroundSubtractorMOG2 bg;
      bg.nmixtures = 3;
      bg.bShadowDetection = true;
      bg.nShadowDetection = 0; //resolved!
      bg.fTau = 0.5;           //resolved!
  
  
      std::vector&lt;std::vector&lt;cv::Point&gt; &gt; contours;
  
      cv::namedWindow("Frame");
      cv::namedWindow("Background");
  
      for(;;)
      {
          cap &gt;&gt; frame;
          bg.operator ()(frame,fore);
          bg.getBackgroundImage(back);
  
          cv::erode(fore,fore,cv::Mat());
          cv::dilate(fore,fore,cv::Mat());
  
          cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
          cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
  
          cv::imshow("Frame",frame);
          cv::imshow("Background",back);
          if(cv::waitKey(30) &gt;= 0) break;
      }
      return 0;
  }
  </code></pre>
  
  <p></p>
  
  <p>I've changed <em>bshadowdetection = true</em> or <em>false</em> but nothing happened. So What should I do?
  Thanks. :)</p>
  
  <p>NB: Sorry for my bad english. :D</p>
  
  <p>================</p>
  
  <p><strong>Resolved!</strong></p>
  
  <p>If you want to remove the shadow from the foreground, just add the code below after bg.bShadowDetection = True:</p>
  
  <p>bg.nShadowDetection = 0 and bg.fTau = 0.5, see the code above! :D</p>
  
  <p>If the shadow still detected, you can adjust the value. </p>
  
  <p>bg.fTau = 0.5 means that if pixel is more than 2 times darker then it is not shadow. </p>
  
  <p>bg.nShadowDetection default value is 127. if you wanna remove the shadow just set the foreground min.threshold to 127. or you can set the bg.nShadowDetection to 0 like me. </p>
  
  <p>Cheers! :D</p>