title: How to subtract the background from an image - python , opencv
body: <p>How to subtract the background in a still image? IF the issue is with videos then we can use <code>cv2.createBackgroundSubtractorMOG()</code>. I tried to manipulate the function, but I got <code>AttributeError</code> </p>
  
  <p>This is what i have tried:</p>
  
  <pre><code>img = cv2.imread('lena.png')
  fgbg = cv2.createBackgroundSubtractorMOG2()
  fgmask = fgbg.apply(img)
  cv2.imwrite('{0:d}.jpg'.format(i),fgmask)
  </code></pre>
  
  <p>But I got this error:</p>
  
  <pre><code>AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2'
  </code></pre>
  
  <p>Any suggestion are welcome!</p>