Vehicle counting - python -
Hello im working in a little vehicle counting program. Now my code is able to:
Detect movement
Apply moments function to each frame to get the centroid of the moving cars.
But now when I have the centroid and the line where I want to count up, y dont know how to create that counter. Could someone help me?. Thankyou so much in advice. Piece of code.
frameBck = cv2.createBackgroundSubtractorMOG2(detectShadows=True)
while True:
ret, frame1 = cap.read()
if (type(frame1) == type(None)):
break
fgMask = frameBck.apply(frame1)
contornosimg = fgMask.copy()
im, contornos, hierarchy = cv2.findContours(contornosimg, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in contornos:
if cv2.contourArea(c) < 200:
continue
if area>area2:
m=cv2.moments(c)
cx=int(m['m10']/m['m00'])
cy=int(m['m01']/m['m00'])
(x, y, w, h) = cv2.boundingRect(c)
Thats what I have now.
you may want to take a look at the opencv tracking api.