# How I can count bounding boxes in each frame?

Hello, I need to know how I can count for bounding boxes in each frame?

I need to know the total bounding boxes, so I know when I need to add new object to be tracking, when total bounding boxes in current frame > total bounding boxes in previous frame

I already try with store centroid coordinate (cx,cy) into a list:

import cv2
import numpy as np

bgsMOG    = cv2.BackgroundSubtractorMOG(50,3,0.8)
cap       = cv2.VideoCapture("d:\\MOV_5702.avi")
a         = []

if cap:
while True:
if ret:
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 > 20 and h > 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=[]