title: OpenCV detecting the whole video frame as an object
body: <p>I'm trying to make  a program that detects objects using my laptops(win 10) webcam.For that I'm using python 3.7 and openCV 3.4 . This is my code:</p>
  
  <pre><code>import cv2
  first_frame = None
  video = cv2.VideoCapture(0)
  
  while True:
  
      check, frame = video.read()
      status = 0
  
      gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      gray = cv2.GaussianBlur(gray, (21, 21), 0)
  
      if first_frame is None:
          first_frame = gray
          continue
  
      delta_frame = cv2.absdiff(first_frame, gray)
  
      thresh_frame = cv2.threshold(delta_frame, 40, 255, cv2.THRESH_BINARY)[1]
  
      thresh_frame = cv2.dilate(thresh_frame, None, iterations=2)
  
      (_, cnts, _) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
      for contour in cnts:
          if cv2.contourArea(contour) &lt; 10000:
              continue
  
          status = 1
          (x, y, w, h) = cv2.boundingRect(contour)
          cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
  
      cv2.imshow("Gray Frame", gray)
      cv2.imshow("Delta Frame", delta_frame)
      cv2.imshow("Threshold Frame", thresh_frame)
      cv2.imshow("Color Frame", frame)
  
      key = cv2.waitKey(1)
  
      if key == ord("q"):
          break
  
      print(status, end=" ")
  cv2.destroyAllWindows()
  video.release()
  </code></pre>
  
  <p>It should draw a red rectangle around the objects that move or just entered the frame.I'm using it somewhere that is not much movement so it could work fine when something is movieng .First it takes a picture as the first frame and compares it with rest of the frames and so on. The problems is that whenever I run the script it detects the whole video frame that appears in the window as an object( a big red rectangle covers  all the edges and corners of the display window) . The room(to be more precise, the static background ) is not dark.To test that whether or not it is detecting the background as object I added a <code>status</code> which initially is zero and whenever and object has entered the frame or moved it should change to one, status is printed in the console.Even when nothing enters the frame <code>1</code> is  printed, showing that something is wrong. When the script runs the threshold windows is all white,I believe that if it was black the problem would be solved. Also how can I improve my code so that it could detect faster and better?</p>