title: How I can count bounding boxes in each frame?
body: <p>I need to know how I can count for bounding boxes in each frame?</p>
  <p>I need to know the total bounding boxes, so I know when I need to add new object to be tracking, when <code>total bounding boxes in current frame &gt; total bounding boxes in previous frame</code></p>
  <p>I already try with store centroid coordinate (cx,cy) into a list:</p>
  <pre><code>import cv2
  import numpy as np
  
  bgsMOG    = cv2.BackgroundSubtractorMOG(50,3,0.8)
  cap       = cv2.VideoCapture(&quot;d:\\MOV_5702.avi&quot;)
  a         = []
  
  
  if cap:
      while True:
          ret, frame = cap.read()
          if ret:
              fgmask              = bgsMOG.apply(frame, None, 0.99)
              contours, hierarchy = cv2.findContours(fgmask, cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
              cv2.drawContours(frame,contours,-1,(0,255,0),cv2.cv.CV_FILLED,32)
              try: hierarchy = hierarchy[0]
              except: hierarchy = []
              for contour, hier in zip(contours, hierarchy):
                  (x,y,w,h) = cv2.boundingRect(contour)
                  
                  if w &gt; 20 and h &gt; 20:
                      cv2.rectangle(frame, (x,y), (x+w,y+h), (180,0,0), 1)
                      (x,y,w,h) = cv2.boundingRect(contour)
                         
                      x1=w/2
                      y1=h/2
                      cx=x+x1
                      cy=y+y1
                      a.append([cx,cy])
                      print(len(a))
                      a=[]
                              
              cv2.imshow('BGS', fgmask)
              cv2.imshow('Ori+Bounding Box',frame)
              key = cv2.waitKey(100)
              if key == ord('q'):
                  break
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  <p>But the result always 1..</p>
  <p><img src="https://i.stack.imgur.com/P0izB.jpg" alt="enter image description here" />
  <img src="https://i.stack.imgur.com/NIxCv.jpg" alt="enter image description here" /></p>