A simple application that counts the number of cars crossing a red line.
Cars are detected using YOLOv8 nano version and tracked using SORT algorithm. When a car with a unique tracking id crosses the red line, the line color momentarily changes to green and the count value is increased accordingly.
If you want to reuse this code for your own projects then these are the values that you need to change.
- Enter a class name/s you want to detect.
CLASSES = ['car', 'bus']
- Define limits of a detection line using (x1, y1) and (x2, y2) coordinate system.
LIMITS = [915, 1575, 2800, 1575]
Additionally, you will need to create a new mask.png for your project.
Here is a quick demo of the application.
The cars are only detected inside a specified region due to an image mask which was created using canva.