This project implements a robust system for detecting vehicles and extracting license plate information from video files. It uses advanced object detection models and OCR (Optical Character Recognition) to process video frames, identify vehicles, locate license plates, and recognize license numbers.
The idea behind this project is to automate the detection and recognition of vehicle license plates in video footage. This is useful in applications such as:
- Traffic monitoring and law enforcement
- Automated toll collection systems
- Parking management
- Vehicle tracking and security
- Vehicle Detection: Use a YOLO (You Only Look Once) model to identify and localize vehicles in video frames.
- License Plate Detection: Employ a custom-trained YOLO model to detect license plates on vehicles.
- License Plate Recognition: Use OCR to extract text from detected license plates.
- Object Tracking: Apply the SORT algorithm to maintain consistent identification of vehicles across video frames.
- Result Compilation: Save the processed data (e.g., license plate numbers, bounding boxes) to a CSV file for analysis or reporting.
- Vehicle Detection: Identifies vehicles such as cars, trucks, and buses in video frames using YOLOv8.
- License Plate Detection: Locates license plates on detected vehicles using a custom-trained YOLO model.
- OCR: Reads and interprets text from license plates using EasyOCR.
- Tracking: Tracks vehicles across frames using the SORT algorithm.
- Results Export: Saves processed data, including bounding boxes and license numbers, to a CSV file.
Number Plate Detection/
├── add_missing_data.py # Handles data preprocessing (if applicable)
├── license_plate_detector.pt # Pre-trained YOLO model for license plate detection
├── main.py # Main script to run the detection system
├── test.csv # Sample dataset
├── test_interpolated.csv # Preprocessed dataset
├── util.py # Utility functions for OCR and CSV writing
├── visualize.py # Visualization functions for detected objects
├── yolov8n.pt # Pre-trained YOLOv8 model for vehicle detection
├── sort/ # SORT algorithm implementation
└── sample.mp4 # Sample video file for testing (if included)
- Python 3.8+
- Required Python packages:
ultralyticsopencv-pythonnumpyeasyocrcsv
The Sample Input video - Input.mp4
The Sample Output video - Output.mp4
Ensure the following files are in the project directory:
yolov8n.pt: Pre-trained YOLOv8 model for vehicle detection.license_plate_detector.pt: Custom-trained YOLO model for license plate detection.
Run the main.py script:
python main.pyThis script processes the video file, detects vehicles and license plates, and exports results to a CSV file.
The processed data is saved in results.csv, containing:
- Frame number
- Vehicle ID
- Bounding box coordinates for vehicles and license plates
- License plate text and confidence scores
- Loads YOLO models for vehicle and license plate detection.
- Processes video frames to detect and track vehicles.
- Extracts license plate text using OCR.
- Implements OCR functionality using EasyOCR.
- Provides a
write_csvfunction to save results.
- Contains helper functions to visualize detection results on video frames.
- Implements the SORT algorithm for real-time object tracking.
-
Vehicle Detection:
- YOLOv8 model is used to detect vehicles in each video frame.
- Vehicles of interest (cars, trucks, buses) are filtered based on their class IDs.
-
License Plate Detection:
- A custom YOLO model detects license plates on the detected vehicles.
- Bounding boxes for license plates are extracted for further processing.
-
OCR for License Plate Recognition:
- EasyOCR processes the license plate regions to extract text.
- The text is cleaned and corrected using character mapping to handle common OCR errors.
-
Tracking with SORT:
- SORT (Simple Online and Realtime Tracking) assigns consistent IDs to vehicles across frames.
- Ensures that license plate data is associated with the correct vehicle.
-
Output Results:
- Results are saved to a CSV file containing detailed information for each vehicle and license plate.
- Includes frame number, bounding boxes, and extracted text with confidence scores.
- Training Custom Models: Replace
license_plate_detector.ptwith a retrained YOLO model for different license plate styles or regions. - Dataset: Update
test.csvor use your own dataset for testing.
This project is licensed under the Apache License 2.0. See LICENSE for details.