Gate Automation — ANPR System
An edge AI system for real-time automatic license plate recognition (ANPR), engineered for automated barrier control, high security, and parking management with sub-100ms response times.
Across varied conditions — daylight, headlight glare, rain, shadow.
Frame capture → OCR → whitelist check → servo barrier trigger.
ESP32 + servo replaces expensive industrial PLCs easily.
Gate defaults to locked on power or network failure.
The Problem & Context
Manual gate security relies heavily on physical passes, paper entry logs, and human vigilance, leading to security bottlenecks during peak hours, human clerical errors, and unauthorized access vulnerabilities.
This project automated the complete access loop: from camera vehicle detection to real-time optical plate parsing, whitelist database matching, and servo barrier activation — all running on affordable, localized compute hardware.
System Architecture Pipeline
Data flows through six discrete stages, each independently replaceable:
Key System Capabilities
Real-Time YOLOv8 Detection
Runs a quantized YOLOv8 nano model achieving 30 FPS inference on mini-PC hardware with robust localization in sun glare, shadows, and low-light.
CLAHE Contrast Equalization
Contrast-Limited Adaptive Histogram Equalization normalizes 8×8 pixel tiles before OCR, eliminating wash-out from headlight glare and night-time shadows.
Instant Whitelist Authorization
SQLite database stores authorized plate numbers with vehicle owner metadata. Exact-match query completes in <2ms; rejects unauthorized vehicles automatically.
ESP32 • Servo Barrier Actuation
Vision server sends a lightweight HTTP trigger to an ESP32 microcontroller that drives a PWM servo motor to raise and lower the physical barrier safely.
Blynk Remote Dashboard
ESP32 syncs with the Blynk mobile app for real-time gate status monitoring and manual override from any smartphone.
Hardware Fail-Safe
Watchdog timer resets ESP32 on hang. Gate defaults to locked on any network or power failure — zero unguarded states.
Technical Deep-Dive: CLAHE Preprocessing
The single biggest accuracy killer was uneven illumination. Instead of global histogram equalization (which washes out shadows), a per-tile CLAHE approach normalizes local contrast before the plate is segmented:
import cv2
import numpy as np
def preprocess(frame):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# CLAHE on 8x8 tiles with clip limit of 2.0
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
equalized = clahe.apply(gray)
# Adaptive threshold keeps edges sharp in glare and shadow
binary = cv2.adaptiveThreshold(
equalized, 255,
cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
cv2.THRESH_BINARY,
blockSize=15, C=4
)
return binary
Engineering Challenges & Solutions
Challenge 1: Severe Glare and Night Reflection
Headlights and direct sun reflect off acrylic license plates, blowing out text. Solved by combining CLAHE with adaptive Gaussian thresholding, boosting character contrast by 40% over standard greyscale thresholding.
Challenge 2: Low-Latency Inference on Constrained Hardware
Heavy models caused frame drops on mini-PCs. Switching from TensorFlow to a YOLOv8 nano quantized model cut inference from ~300ms to under 80ms while maintaining 98%+ detection precision.
Challenge 3: Plate String Noise & OCR Errors
EasyOCR occasionally misread similar characters (0/O, 1/I, B/8). A fuzzy matching layer using Levenshtein distance against whitelist entries tolerates 1–2 character errors without compromising security.
Design Decisions & Trade-offs
ESP32 Over Industrial PLC
Why: A $15 ESP32 with servo runs the gate relay and Blynk dashboard. Trade-off: No industrial certifications — not suitable for safety-critical factory gates.
YOLOv8 + EasyOCR Pipeline
Why: Splitting detection and recognition lets me swap either model independently. Trade-off: Two model passes = ~160ms total vs a single end-to-end ANPR model.
WiFi-Connected Vision Server
Why: A mini-PC running the vision stack is far more flexible than embedding the model on the ESP32. Trade-off: Network dependency mitigated by fail-safe firmware.
What I'd Do Differently
I'd replace EasyOCR with PaddleOCR's plate-specific model — it handles embossed and reflective plates far better. I'd also add a proper REST API for whitelist management so facility staff could manage authorized vehicles from a phone without touching the database directly.
Lessons Learned & Outcomes
This project highlighted how much computer vision systems depend on their preprocessing pipeline. The CLAHE normalization step was the single most impactful change — without it, accuracy dropped sharply in challenging lighting. Hardware safety proved just as important as model accuracy; a vision system that fails closed is far safer than one that fails open.
The final system achieved 98%+ plate recognition accuracy with sub-100ms inference on affordable mini-PC hardware, making automated gate access viable for small-scale deployments without expensive enterprise infrastructure.