This project uses OpenCV and YOLOv8 to detect and track vehicles in a video feed, estimate their speed, and count the number of vehicles moving in different directions. The system processes frames from a video, identifies vehicles, tracks their movement across predefined lines, and calculates speed based on the time taken to cross a fixed distance.
To set up and run the project, follow these steps:
Ensure you have Python 3.8+ installed. You also need to install the required dependencies.
# Clone this repository
git clone https://github.com/yourusername/vehicle-detection-opencv.git
cd vehicle-detection-opencv
# Install dependencies
pip install -r requirements.txt
# Download YOLOv8 model weights
wget https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt
Run the main script to process the input video:
python main.py
Ensure that the video file (highway.mp4) is placed in the project directory. You can modify the script to use a different video file.
vehicle-detection-opencv/
│── detected_frames/ # Stores processed frames with detections
│── output.avi # Processed output video
│── tracker.py # Custom object tracking module
│── main.py # Main script for vehicle detection & tracking
│── README.md # Project documentation
│── requirements.txt # List of dependencies
│── yolov8s.pt # YOLO model weights
The output will be displayed in real-time and saved as a processed video (output.avi). Frames with detected vehicles will be stored in the detected_frames/ directory.
This project requires the following Python libraries:
opencv-python
pandas
ultralytics
Install dependencies using:
pip install -r requirements.txt
This project is licensed under the License. See LICENSE for details.
For any questions or issues, feel free to open an issue or contact me at 210886@kit.ac.in.
Author: Aditya Kumar GitHub: yourusername