Effortlessly count cars in videos using YOLOv8-powered computer vision program for streamlined traffic monitoring.
This Python script uses computer vision techniques to count vehicles in a traffic cam video. The implementation is based on the YOLO (You Only Look Once) object detection model, integrated with a SORT (Simple Online and Realtime Tracking) algorithm for tracking.
-
Object Detection: Utilizes the YOLO model to detect vehicles in the video.
-
Tracking: Implements the SORT algorithm for real-time tracking of detected vehicles.
-
Counting: Tracks and counts vehicles crossing predefined lines in the video.
-
Visualization: Displays the output with graphical overlays indicating the total count and count in specific directions.
Make sure you have the following dependencies installed:
-
OpenCV (
cv2) -
cvzone -
SORT(Simple Online and Realtime Tracking)
-
Clone the repository:
git clone https://github.com/serialdotai/car-counter.git cd car-counter -
Install the required packages:
pip install -r requirements.txt
-
Download the YOLO weights file
yolov8l.ptand place it in a yolo weights directory. -
Run the script:
python main.py
Adjust the following parameters in the script as needed:
lineUpandlineDown: Define the lines for counting vehicles in the video.mask: Set the mask image for region of interest.
The processed video will be saved as result.mp4 in the same directory.
- Ultralytics YOLO
SORT