title: How can I remove background from an (video)image using OpenCV and Java?
body: <p>I just started learning <strong>OpneCV</strong> and started my project in Java. As Java wrapper of <strong>OpenCV</strong> is released recently, there isn't much documentation available. </p>
  
  <p>I am trying to separate the background and foreground from video captured through webcam. I tried using the <strong><code>BackgroundSubtractorMog</code></strong> class in java but failed to get the desired output. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>VideoCapture capture = new VideoCapture(0);
    Mat camImage = new Mat();
  
      if (capture.isOpened()) {
          while (true) {
              capture.read(camImage);
  
              BackgroundSubtractorMOG backgroundSubtractorMOG=new BackgroundSubtractorMOG();
              Mat fgMask=new Mat();
              backgroundSubtractorMOG.apply(camImage, fgMask,0.1);
  
              Mat output=new Mat();
              camImage.copyTo(output,fgMask);
  
              displayImageOnScreen(output);
             }
          }
  </code></pre>
  
  <p>This code just gives a blackscreen output. </p>