Vehicle counting - python -

asked 2018-11-21 10:18:11 -0500

WoFFeN88 gravatar image

updated 2018-11-21 10:18:39 -0500

Hello im working in a little vehicle counting program. Now my code is able to:

  1. Detect movement

  2. 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.

image description

edit retag flag offensive close merge delete

Comments

you may want to take a look at the opencv tracking api.

holger gravatar imageholger ( 2018-11-22 03:50:47 -0500 )edit

@WoFFeN88 . Here is tutorial that will teach you how to count peoples/vehicles. This tutorial will work. I have done with my owned project using my owned video. Counting vehicles

supra56 gravatar imagesupra56 ( 2018-11-22 07:15:09 -0500 )edit