This project demonstrates a vehicle speed detection system using a YOLO object detection model and OpenCV. The system captures video footage of vehicles passing through a frame and calculates their speeds based on the time taken to cross two predefined lines.
- Real-time vehicle detection: Utilizes the YOLO object detection model to detect vehicles in each frame.
- Speed calculation: Computes vehicle speed based on the time taken to cross two predefined lines.
- Bounding boxes: Draws bounding boxes around detected vehicles with ID and speed annotation.
- Frame saving: Saves processed frames for further analysis.
- Video output: Outputs a video file with annotated vehicle speeds.
- Clone the repository:
git clone https://github.com/yourusername/speed-detection-project.git cd speed-detection-project
- Install required libraries:
pip install -r requirements.txt
- Download the YOLO model weights: Download the yolov8s.pt model file from the official YOLO repository and place it in the project directory.
Ensure you have a video file named Input.mp4
in the project directory or update the code to reflect the path to your video file.
```bash
python speed_detection.py
The processed video with annotated vehicle speeds will be saved as Output
in the project directory.
- Object Detection: The YOLO model is used to detect vehicles in each frame of the input video.
- Tracking: The center points of detected vehicles are tracked to determine when they cross predefined lines.
- Speed Calculation: The speed of each vehicle is calculated based on the time it takes to travel between the two lines.
- Annotation: The calculated speed and vehicle ID are annotated on the output video frames.
You can view a sample output video demonstrating the speed detection capabilities of the system here: Output
The speed detection accuracy improves with more powerful GPUs, as they enable faster and more precise frame processing.