title: Background and foreground in OpencV
body: <p>i'm working on a project using OpenCV243, I need to get the foreground  during a stream, my Problem is that I use the  cv::absdiff to get it doesn't really help, here is my code and the result .</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include&lt;opencv2\opencv.hpp&gt;
  #include&lt;opencv2\calib3d\calib3d.hpp&gt;
  #include&lt;opencv2\core\core.hpp&gt;
  #include &lt;opencv2\highgui\highgui.hpp&gt;
  
  int main (){
      cv::VideoCapture cap(0);
      cv::Mat frame,frame1,frame2;
      cap &gt;&gt; frame;
      frame.copyTo(frame1);
      cv::imwrite("background.jpeg",frame1);
      int key = 0;
      while(key!=27){
          cap &gt;&gt; frame;
          cv::absdiff(frame, frame1, frame2);  // frame2 = frame  -frame1
          cv::imshow("foreground", frame2);
          if(key=='c'){
              //frame.copyTo(frame2);
              cv::imwrite("foreground.jpeg", frame2); 
              key = 0;
          }
  
          cv::imshow("frame",frame);
          key = cv::waitKey(10);
      }
      cap.release();
      return 0;
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/1R0Xv.jpg" alt="Background ">
  <img src="https://i.stack.imgur.com/VSXp7.jpg" alt="foreground ">
  as you can see  the subtraction work but what I want to get is only the  values of that changed  for example if have a Pixel in the background  with   <strong>[130,130,130]</strong> and the same pixel has <strong>[200,200,200]</strong>  in the frame  I  want to get exactly the last values and not <strong>[70,70,70]</strong>
  I've already seen this tutorial : <a href="http://mateuszstankiewicz.eu/?p=189" rel="nofollow noreferrer">http://mateuszstankiewicz.eu/?p=189</a>
  but I can't understand the code and I have problems setting cv::BackgroundSubtractorMOG2 with my openCV version </p>
  
  <p>thanks in advance for you help </p>