Automatic Number Plate Recognition System
Real-Time ANPR for Chiang Mai Provincial Office
location_on Chiang Mai Provincial Office
This project is an AI-powered system for real-time vehicle license plate recognition, developed for Chiang Mai Provincial Office. The system accepts simultaneous feeds from multiple cameras, detects vehicles, reads license plates, stores records, and streams live results to a web dashboard — all running on-premises with no external cloud dependency.
The system is specifically designed for Thai license plates, covering all 77 provinces including special plate formats such as taxi plates, with an intelligent OCR correction engine that understands the unique characteristics of Thai characters and digits that are commonly confused.
Multi-Camera Real-Time
Supports multiple simultaneous cameras — RTSP, USB, Screen Capture — with Auto-Reconnect.
Two-Stage AI Detection
YOLOv8m detects vehicles → YOLOv8m locates the license plate, accelerated with NVIDIA CUDA.
Two-Zone OCR
Splits each plate into 2 zones: letters + digits (top) and province (bottom), with Multi-Pass Preprocessing.
Thai Plate Validator
Regex + Fuzzy Matching for all 77 provinces + 8-rule character correction table.
Vehicle Color Detection
Detects 9 vehicle colors using OpenCV HSV Histogram Analysis.
Smart Deduplication
TTLCache with 500 entries prevents the same plate from being recorded twice within 30 seconds.
Discord Webhook
Instant alerts with image attachments on every detection, sent via Async HTTP.
Auto Data Retention
APScheduler automatically purges old records every night at 02:00 (configurable).
10-Step Detection Pipeline
- 1 Detect vehicles using YOLO (Vehicle Model — COCO)
- 2 Detect vehicle color via HSV Histogram Analysis
- 3 Detect license plate within the vehicle bounding box
- 4 Crop the license plate region from the frame
- 5 Read characters with EasyOCR Two-Zone + Multi-Pass preprocessing
- 6 Validate and correct result with Thai Plate Validator
- 7 Check Deduplication Cache
- 8 Save plate crop image and full frame snapshot
- 9 Write record to SQLite Database
- 10 Broadcast via WebSocket + send Discord Webhook
Threading Model
The system uses a Producer-Consumer Multi-Threading model: one Camera Thread per camera → Frame Queue → Frame Router → Shared Detection Queue → Detection Workers × 2 → FastAPI Async Event Loop (DB + WebSocket Broadcast)
| Parameter | Default Value | Unit |
|---|---|---|
| OCR Confidence | 60 | % |
| Plate Confidence | 50 | % |
| Frame Skip | 5 | frames |
| Dedup TTL | 30 | seconds |
| Data Retention | 30 | days |
| Detection Workers | 2 | threads |
| Province Database | 77 | provinces |