ive got this big/easy problem that i need to solve but i cant..
What im trying to do is to count cars on a highway, and i actually can detect the moving cars and put bounding boxes on them… but when i try to count them, i simply cant. I tried making a variable (nCars) and increment everytime the program creates a bounding box, but that seems to increment to many times..
The question is: Whats the best way to count moving cars/objects?
PS: I Dont know if this is a silly question but im going nutts…. Thanks for everything (:
And im new here but i know this website for some time (: Its great!
I guess you are detecting the cars in each frame and creating a new bounding box each time a car is detected. This would explain the many increments of your variable.
You have to find a way to figure out if the car detected in one frame is the same car from the frame before (if you had a car detected in the previous frame). You might be able to achieve this by simply comparing the bounding box distances between two frames; if the distance is less than a threshold value, you can say that it’s the same car from the previous frame. This way you can track the cars.
You could increment the counter variable when the detected car leaves the camera’s field of view (exits the frame).
The tracking procedure I proposed here is very simple, try searching for “object tracking” to see what else you can use (maybe have a look at OpenCV’s KLT tracking).