I'm trying to count how many red color bar from this video
and this is my function to count the object by count the center of the object
def count(frame):
frame = imutils.resize(frame,640,480)
hsv=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
mask=cv2.inRange(hsv, lower, upper)
contours,_ = cv2.findContours(mask.copy(), cv2.RETR_CCOMP,cv2.CHAIN_APPROX_TC89_L1)
center=[]
for i in range(len(contours)):
c = max(contours, key=cv2.contourArea)
((x, y), radius) = cv2.minEnclosingCircle(c)
M = cv2.moments(c)
if M["m00"]==0:
M["m00"]=0.6
cx=int (M["m10"]/M["m00"])
cy=int(M["m01"] / M["m00"])
print "center",len(center)
center.append((cx,cy))
cv2.circle(frame, center[-1],3,(0,0,0),-1)
but the problem is len(center) appear more than 300. can anyone help to count how many the red bar. any solution will be helpful.



