
The Vehicle Detection and Counting System is a real-time traffic monitoring solution built using Python, OpenCV, and YOLOv4. It is capable of identifying, tracking, and counting vehicles from a video feed or image sequence. It also features a voice interface using pyttsx3 for audible alerts. This project addresses the growing need for intelligent traffic systems, helping to automate vehicle monitoring, enhance traffic flow analysis, and improve smart city infrastructure.
Manual vehicle counting is time-consuming, error-prone, and not scalable for high-traffic areas. Our system aims to solve this by providing a fully automated, accurate, and scalable solution using computer vision and deep learning.
This Python script is designed for real-time vehicle detection and counting using YOLOv4, OpenCV, pyttsx3, and a custom object detection module. The system identifies vehicles in a video stream, assigns unique IDs for tracking, and provides a voice-guided interface.
- Eliminate manual traffic counting.
- Provide real-time vehicle monitoring and alerts.
- Enable smart city infrastructure and intelligent traffic systems.
- Collect accurate traffic data for analytics and prediction.
- Real-time vehicle detection in videos.
- Counting vehicles with unique IDs using tracking.
- Voice interaction for detected vehicle counts.
- Can be integrated with traffic lights, CCTV, or smart surveillance systems.
Python is the preferred language for computer vision applications due to:
- Easy syntax and rapid prototyping
- Seamless integration with OpenCV
- Support for deep learning frameworks like YOLO, TensorFlow, etc.
- Libraries like
pyttsx3
make voice interaction easy


Library | Purpose |
---|---|
cv2 (OpenCV) |
Video capture, image processing, bounding boxes |
math |
Distance calculations between object centers |
numpy |
Frame matrix manipulation and array processing |
pyttsx3 |
Text-to-speech output for vehicle counts |
art |
Generates ASCII art title screen for CLI |
textblob |
Optional NLP tasks like text analysis |









You have to download the latest version of python.
Make sure you have Python installed. You can download it from python.org.
Once python is installed then open the command window and run these commands.
pip install opencv-python
pip install numpy
pip install art
pip install pyttsx3
pip install textblob
pip install colorama
Download the YOLOv4 weights files and give the address of that files in object_detection.py.
Place the weights and cfg files in the object_detection directory .


-
Open the script in a code editor.
-
Customize the image/video file path according to your path:
video = cv2.VideoCapture("C:\\Users\\DELL\\OneDrive\\Desktop\\Project\\Highway.mp4")
-
Modify the YOLOv4 weights path:
od = ObjectDetection(weights_path="path/to/yolov4.weights")
-
Run the script:
python vehicle_detection.py
Firstly you to download the libraries by using the above commands and then you have to save all the images and video files where your main.py file is located. When you will run the code then you have to answer some questions. When program ask for image processing then you have to put the name of that file only e.g 1 It depens on your image name and extension of image should be .png. For video processing repeat the same process and extension of video file should be .mp4
It can detect cars in smog also.
It can detect and count cars at night also.
The Vehicle Detection and Counting System provides a reliable, real-time solution for identifying and tracking vehicles using Python, OpenCV, and YOLOv4. It automates traffic monitoring with accurate detection and voice-based interaction, making it suitable for smart city and surveillance applications. This project lays the groundwork for future enhancements in intelligent transportation systems.
