title: Threshold image using image subtraction using opencv python
body: <p>Can you anyone tell me how to get threshold image using frame differencing
  I have an idea about various background subtraction method but i donot want to use them. </p>
  
  <p>cv2.substract(img1,img2) gives this image</p>
  
  <p><a href="https://i.stack.imgur.com/b9gyA.jpg" rel="nofollow noreferrer">substract:</a>
  <a href="https://i.stack.imgur.com/b9gyA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b9gyA.jpg" alt="Screenshot"></a></p>
  
  <p>but i want this result <a href="https://i.stack.imgur.com/7GTD3.jpg" rel="nofollow noreferrer">threshold</a>
  Can anyone tell me how to do that</p>
  
  <p>i donot want to use cv2.createBackgroundSubtractorMOG2() or such kind function
  here is my </p>
  
  <pre><code>import cv2
  import numpy as np
  t=0.01
  background=cv2.imread('background2.png')
  cap = cv2.VideoCapture('car.mp4')
  ret,img=cap.read()
  
  avg_img = np.float32(img)
  while 1:
      ret,img=cap.read() 
      cv2.accumulateWeighted(img,avg_img,0.1)
      res1 = cv2.convertScaleAbs(avg_img)
      sub_img=cv2.subtract(res1,img)
      cv2.imshow('sub_img',sub_img)
      cv2.imshow('sub_img',sub_img)
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  
  
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>My opencv version 3.0.0 python 2.7</p>