Production-Grade Automatic Number Plate Recognition System
Features β’ Quick Start β’ Documentation β’ API β’ Demo
A complete, production-ready ANPR (Automatic Number Plate Recognition) system built from scratch for 24/7 deployment. Designed for CPU-only processing with real-time performance, supporting multiple RTSP camera streams simultaneously.
- β CPU-Only Processing - No GPU required, optimized for Intel/AMD CPUs
- β Real-Time Performance - 3-10 FPS per camera with efficient processing
- β Multi-Camera Support - Handle 5-15 cameras simultaneously
- β Built From Scratch - No pre-packaged ANPR/ALPR libraries
- β Production-Ready - Auto-recovery, health monitoring, supervision
- β REST API + SSE - Complete API with real-time event streaming
- β Web Admin Panel - Beautiful HTML5 admin interface
- β Indian Formats - Complete support for all Indian plate formats
- β Extensible - Easy to add new countries and customizations
- Features
- System Requirements
- Quick Start
- Installation
- Configuration
- Usage
- API Reference
- Architecture
- Performance
- Deployment
- Troubleshooting
- Contributing
- License
- Multi-Camera RTSP Processing - Process multiple IP camera streams
- Vehicle Detection - ONNX-based vehicle detection (cars, bikes, trucks, buses)
- Plate Detection - Hybrid classical CV + ML approach
- Custom OCR Engine - Built from scratch with character segmentation
- Multi-Format Support - Indian formats: Standard, BH Series, Army, Diplomatic, Temporary, Rental
- Temporal Aggregation - Multi-frame voting for accuracy
- Real-Time Validation - Format and rule-based validation
- REST API - Full CRUD operations for cameras, results, configuration
- Server-Sent Events (SSE) - Real-time plate detection events
- Image Upload API - POST image, get detection results
- Web Admin Panel - Beautiful HTML5 interface
- Prometheus Metrics - Performance monitoring export
- Auto-Reconnection - Cameras auto-reconnect on failure
- Process Supervision - Auto-restart with failure limits
- Health Monitoring - System health checks every 30s
- Adaptive Performance - Dynamic frame skipping based on CPU
- Database Storage - SQLite for configuration and results
- Structured Logging - Comprehensive logging with rotation
| Component | Specification |
|---|---|
| CPU | Intel Core i5 (6th gen) / AMD Ryzen 5 |
| RAM | 4GB |
| Storage | 10GB available space |
| OS | Ubuntu 20.04+ / Debian 11+ |
| Python | 3.11+ |
| Component | Specification |
|---|---|
| CPU | Intel Core i7 (8th gen) / AMD Ryzen 7 |
| RAM | 8GB |
| Storage | 20GB SSD |
| OS | Ubuntu 22.04 LTS |
| Python | 3.11 |
| CPU | Cameras | FPS | CPU Usage | RAM |
|---|---|---|---|---|
| i5-9400 | 2-3 | 3-5 | ~70% | ~1.5GB |
| i7-10700 | 5-8 | 5 | ~80% | ~2.5GB |
| i9-11900K | 10-15 | 5-7 | ~75% | ~4GB |
git clone https://github.com/masterdeepak15/anpr-system.git
cd anpr-system# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install requirements
pip install -r requirements.txt# Place your ONNX models in models/ directory
# Required files:
# - models/vehicle_detector.onnx
# - models/plate_detector.onnx
# - models/char_classifier.onnx
# Or run download script
./scripts/download_models.shpython scripts/init_db.py# Copy example environment
cp .env.example .env
# Edit config.json with your settings
nano config.json# Start the system
python main.py
# With custom config
python main.py --config config.json --log-level INFO
# Access admin panel
open http://localhost:5000/ # or visit in browser# 1. System dependencies
sudo apt-get update
sudo apt-get install -y python3.11 python3-pip python3-dev build-essential
# 2. Clone repository
git clone https://github.com/yourusername/anpr-system.git
cd anpr-system
# 3. Python environment
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
# 4. Initialize
python scripts/init_db.py
# 5. Configure cameras
python scripts/add_cameras.pycd deployment/docker
docker-compose up -d
# View logs
docker-compose logs -f anpr-system
# Stop
docker-compose downcd deployment/systemd
sudo ./install.sh
# Start service
sudo systemctl start anpr
sudo systemctl status anpr
# View logs
sudo journalctl -u anpr -f{
"frame_width": 640,
"frame_height": 480,
"vehicle_model_path": "models/vehicle_detector.onnx",
"plate_model_path": "models/plate_detector.onnx",
"ocr_model_path": "models/char_classifier.onnx",
"country_code": "IN",
"api_host": "0.0.0.0",
"api_port": 5000,
"target_fps": 5.0,
"max_cpu_percent": 80.0,
"aggregation_window": 5,
"min_occurrences": 3,
"vehicle_confidence": 0.5,
"use_plate_ml": true,
"_comment_tracking": "Vehicle Tracking Configuration",
"enable_tracking": true,
"tracking_max_disappeared": 30,
"tracking_iou_threshold": 0.3,
"_comment_incidents": "Incident Detection Configuration",
"enable_incident_detection": true,
"enable_helmet_detection": true,
"enable_seatbelt_detection": true,
"enable_wrong_way_detection": true,
"enable_triple_riding_detection": true,
"helmet_model_path": "models/helmet_detector.onnx",
"seatbelt_model_path": "models/seatbelt_detector.onnx",
"_comment_video_buffer": "Video Buffer Configuration",
"video_buffer_seconds": 10,
"incident_video_before_seconds": 5,
"incident_video_after_seconds": 5,
"incident_output_dir": "incidents"
}ANPR_ENV=production
LOG_LEVEL=INFO
API_PORT=5000
API_KEY=your-secure-api-key
DB_PATH=data/anpr_system.db
MAX_WORKERS=4Via API:
curl -X POST http://localhost:5000/api/v1/cameras \
-H "Content-Type: application/json" \
-d '{
"camera_id": "cam_entrance_01",
"name": "Main Entrance",
"rtsp_url": "rtsp://admin:password@192.168.1.100:554/stream1",
"location": "Building A - Entrance",
"frame_skip": 2
}'Via Web UI:
- Open http://localhost:5000
- Click "Add Camera"
- Fill in details
- Submit
# Basic start
python main.py
# With custom settings
python main.py --config config.json --log-level DEBUG --log-file logs/anpr.log
# Production mode
python main.py --log-level INFO --log-file /var/log/anpr/anpr.log- Open browser:
http://localhost:5000 - View real-time statistics
- Manage cameras
- Upload images for detection
- Monitor live detections
Get System Status:
curl http://localhost:5000/api/v1/statusQuery Recent Results:
curl "http://localhost:5000/api/v1/results?limit=10"Search for Plate:
curl "http://localhost:5000/api/v1/results/search?plate=MH12"Upload Image for Detection:
curl -X POST http://localhost:5000/api/v1/detect/image \
-F "image=@car_image.jpg"Real-Time Events (SSE):
curl -N http://localhost:5000/api/v1/events/streamGET /health- Health checkGET /api/v1/status- System status and stats
GET /api/v1/cameras- List all camerasGET /api/v1/cameras/{id}- Get camera detailsPOST /api/v1/cameras- Add new cameraPUT /api/v1/cameras/{id}- Update cameraDELETE /api/v1/cameras/{id}- Delete camera
GET /api/v1/results- Query results- Query params:
camera_id,start_time,end_time,limit
- Query params:
GET /api/v1/results/search?plate={text}- Search by plateGET /api/v1/results/stats?hours=24- Get statistics
POST /api/v1/detect/image- Upload image for detection- Body:
multipart/form-datawithimagefile - Returns: Vehicle and plate detections with coordinates
- Body:
GET /api/v1/events/stream- Real-time event stream
POST /api/v1/pipeline/start- Start pipelinePOST /api/v1/pipeline/stop- Stop pipelinePOST /api/v1/pipeline/restart- Restart pipeline
Detection Result:
{
"timestamp": 1706543210.123,
"image_shape": [1080, 1920, 3],
"vehicles": [
{
"bbox": [100, 200, 400, 500],
"confidence": 0.95,
"class_name": "car",
"plate": {
"text": "MH12AB1234",
"confidence": 0.92,
"bbox": [150, 350, 250, 380],
"character_confidences": [0.98, 0.96, 0.95, ...],
"valid": true
}
}
]
}βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ANPR System Architecture β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β RTSP ββββββΆβ Frame ββββββΆβ Detection β β
β β Cameras β β Buffers β β Pipeline β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β β
β β βΌ β
β β ββββββββββββββββ β
β β β OCR β β
β β β Engine β β
β β ββββββββββββββββ β
β β β β
β β βΌ β
β β ββββββββββββββββ β
β βββββββββββββββββββββββββββββββββββΆβ Validation & β β
β β Aggregation β β
β ββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β SQLite βββββββ Results βββββββ Storage β β
β β Database β β Manager β β Layer β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β β
β β β
β ββββββββΌββββββββ ββββββββββββββββ ββββββββββββββββ β
β β REST API ββββββΆβ Web UI β β SSE β β
β β Server β β (HTML5) β β Events β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
See ARCHITECTURE.md for detailed documentation.
| Operation | Time | Throughput |
|---|---|---|
| Vehicle Detection | 80-120ms | 8-12 FPS |
| Plate Detection | 20-30ms | 33-50 FPS |
| OCR Processing | 50-80ms | 12-20 FPS |
| Full Pipeline | 150-230ms | 4-6 FPS |
- Reduce Frame Skip: Increase
frame_skipto 3-5 for lower CPU usage - Lower Resolution: Set
frame_widthto 480 for faster processing - Disable ML Refinement: Set
use_plate_mltofalse - Adjust Workers: Tune
max_workersbased on CPU cores
- Hardware meets requirements
- Network configured, cameras accessible
- Firewall rules configured
- SSL certificates obtained
- Models downloaded and verified
- Database initialized
- Cameras added and tested
- Monitoring enabled (Prometheus/Grafana)
- Backups automated
- Team trained
Prometheus + Grafana:
# Start monitoring stack
cd monitoring
docker-compose up -d
# Access Grafana
open http://localhost:3000Logs:
# View logs
tail -f logs/anpr.log
# Search for errors
grep ERROR logs/anpr.log
# Systemd logs
sudo journalctl -u anpr -fCamera Won't Connect
# Test RTSP URL
ffplay rtsp://camera-ip:554/stream1
# Check network
ping camera-ip
# Verify credentials in RTSP URLHigh CPU Usage
- Increase
frame_skipto 3-5 - Reduce
target_fps - Lower
frame_widthandframe_height
Low Detection Rate
- Check camera angle and lighting
- Verify model files exist
- Review confidence thresholds
- Check plate formats in validation
Database Locked
- Check file permissions
- Ensure only one instance running
- Consider PostgreSQL for multi-instance
See TROUBLESHOOTING.md for detailed guide.
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
# Clone repository
git clone https://github.com/yourusername/anpr-system.git
cd anpr-system
# Create development environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Run tests
pytest tests/
# Run with coverage
pytest --cov=src tests/This project is licensed under the MIT License - see LICENSE file for details.
- ONNX Runtime - CPU-optimized inference
- OpenCV - Image processing
- Flask - API framework
- SQLite - Database
- Documentation: Full Docs
- Issues: GitHub Issues
- Email: support@example.com
- GPU Support (CUDA)
- Multi-country support (US, EU, UK)
- Vehicle make/model recognition
- Cloud deployment templates
- Mobile app
- Advanced analytics dashboard
Made with β€οΈ by ANPR Team