How to Build a Traffic Counter with Python and OpenCV | Computer Vision Project

preview_player
Показать описание
Here I share one of my first computer vision projects with Python and OpenCV to perform traffic counting. Learn how you can do it yourself by following the guide.

Please consider liking the video and subscribing to the channel.

My script does not use fancy machine learning techniques to detect cars. Rather, it uses the method of a running average of the background and background subtraction to detect motion, but it does not have an internal representation for a vehicle.

I included a nice animation explaining my workaround to a proper object-tracking method. The reason for this is that I originally intended to use my script with a Raspberry Pi so I needed to keep computational costs down to the minimum.

As I mentioned in the description, the link to the GitHub repository with the code is down below:

I will also be occasionally writing Python related posts in my blog here:

CREDITS
- The background music was obtained from the YouTube Audio Library.

OTHER VIDEOS YOU MIGHT LIKE

MY GEAR:

CHECK MY OTHER CHANNELS:

º My new animation and artsy-type channel:

DISCLAIMER: Links included in this description might be affiliate links. If you purchase a product or service with the links I'm providing I may receive a small commission. This is at no additional cost to you! Thank you for supporting my channel this way.

TIMESTAMPS
00:00 - Channel intro
01:00 - Background Subtraction
02:01 - Object Tracking
02:30 - Object Tracking Animation
04:11 - Code Explained
05:52 - Running Script
06:50 - Command Line Arguments

#andresberejnoi #computervision #opencv
Рекомендации по теме
Комментарии
Автор

This is informative and very well done! Thank you for making videos like this. The fact that you did this project as a sophomore and with minimal supervision is very impressive.

Jnile
Автор

This is an impressive result.
I guess the calculating the average for the refernce image works much better in a downwards camera angle, because you see more road surface between the vehicles. In the video at 2:04 there are regions of the road that are constantly covered by vehicles.
Did you experiment with optical flow algorithms? Usually it should be relativliy simple to seperate objectes based on an optical flow image. With optical flow you might get rid of the problem to define a reference image.

michaegi
Автор

Thanks man, you helped me very much !

陳翰儒-dm
Автор

Hi Andres. I am an absolute beginner with arduino. I bought a beginner kit because I want to be able to build exactly this kind of thing, a counter that will count the vehicles that go by my house. It would be cool if it could measure the speed and dimensions of vehicles so that it could distinguish cars, trucks, motorcycles, pedestrians, etc., but importantly in both directions and keeping track of how many go each way.

camofrog
Автор

Thank you for this video, it’s super cool and the great documentation is very appreciated! If you don’t mind, I had a couple questions:

1. I am running into an issue where the centroid of a bounding box seems to jump around rapidly at the counter line, leading to 3-4 counts for 1 car. Do you have any recommendations for fixing this?

2. Whenever I change the min_area argument, it does not really seem to affect the bounding boxes that are created. A higher min_area should mean that bounding boxes smaller (in pixels) than that min_area shouldn’t be formed, right?

Thanks again!

troyvicsik
Автор

Hi Andrés, love your work. I have been expanding on your project.
I am trying to apply your script to a cross-intersection and log vehicle movements e.g. Left turn, Right turn, Straight through. For this i need to change the Label ID's.
I am also trying to identify Heavy vehicles and Light vehicles by looking at the contour size.
Do you have any suggestions on how I can achieve this?
Thank you!

leananddeadly
Автор

Hey Andrés, thank you for your project, the documentation is fenomenal!
Do you think, I could use to count fishes passing in a channel, in real time using a webcam in a laptop?

hierotetsu
Автор

Hi Andrés this project is so cool! How many cars do you think it´s able to count? It works for motorcycles? I have a video of a highway with a bunch of motorcycles. Some people says that it has 300.000, some people say it is about 15.000. Do you believe your software can count it? It´s about 15 minutes vídeo. The image was take from a drone.

analisedevideos
Автор

How are you detecting and eliminating the possibilities of a pedestrian walking through the video?

haseebsiddiqui
Автор

Bro Can we classify vehicles based on their size. Plz help me

gsunil
Автор

Bro, the video is zooming to the corner when I upload video i recorded .plz help

gsunil
join shbcf.ru