title: opencv background substraction
body: <p>I have an image of the background scene and an image of the same scene with objects in front. Now I want to create a mask of the object in the foreground with background substraction. Both images are RGB. </p>
  
  <p>I have already created the following code:</p>
  
  <pre><code>cv::Mat diff;
  diff.create(orgImage.dims, orgImage.size, CV_8UC3);
  diff = abs(orgImage-refImage);
  
  cv::Mat mask(diff.rows, diff.cols, CV_8U, cv::Scalar(0,0,0));
  //mask = (diff &gt; 10);
  
  for (int j=0; j&lt;diff.rows; j++) {
      // get the address of row j
      //uchar* dataIn= diff.ptr&lt;uchar&gt;(j);
      //uchar* dataOut= mask.ptr&lt;uchar&gt;(j);
      for (int i=0; i&lt;diff.cols; i++) {
          if(diff.at&lt;cv::Vec3b&gt;(j,i)[0] &gt; 30 || diff.at&lt;cv::Vec3b&gt;(j,i)[1] &gt; 30 || diff.at&lt;cv::Vec3b&gt;(j,i)[2] &gt; 30)
              mask.at&lt;uchar&gt;(j,i) = 255;
      }
  }
  </code></pre>
  
  <p>I dont know if I am doing this right? </p>