Building a number plate recognition system with ESP32-CAM is an affordable approach to automatic number plate recognition (ANPR) for Indian parking lots, housing society gates, and toll plazas. Indian number plates follow a specific format (state code, district code, series, number) that can be parsed after OCR extraction. This project guide walks you through building a working ANPR system that captures vehicle plates, extracts text, and logs entries using the low-cost ESP32-CAM module.
Table of Contents
- ANPR Applications in India
- System Architecture Overview
- ESP32-CAM Hardware Setup
- Image Capture and Preprocessing
- OCR Processing for Indian Plates
- Parking Management Integration
- Frequently Asked Questions
- Conclusion
ANPR Applications in India
ANPR systems are increasingly deployed across India for:
- Housing society gates: Automatic visitor logging and resident verification
- Parking management: Entry/exit time tracking for fee calculation
- Toll plazas: FASTag-linked verification and violation detection
- Industrial premises: Vehicle movement logging for security
- Traffic enforcement: Red light violation and speed detection cameras
Commercial ANPR systems cost ₹50,000-2,00,000. A DIY ESP32-CAM system costs under ₹2,000 and handles the basic use case of plate capture and logging.
System Architecture Overview
The system has two stages: the ESP32-CAM captures images and sends them via WiFi to a server (Raspberry Pi or cloud), which runs the heavier OCR processing. This split architecture avoids overloading the ESP32’s limited processing power while keeping the camera node cheap and replaceable.
- ESP32-CAM detects motion (PIR trigger or software motion detection)
- Captures a high-resolution image (1600×1200 UXGA)
- Sends the image to a local Raspberry Pi server via HTTP POST
- Server runs OpenCV to isolate the plate region
- Tesseract OCR extracts text from the plate
- Result is logged to a database with timestamp
ESP32-CAM Hardware Setup
// ESP32-CAM (AI-Thinker) Pin Connections for Programming
// FTDI TX → ESP32 U0R (GPIO3)
// FTDI RX → ESP32 U0T (GPIO1)
// FTDI GND → ESP32 GND
// GPIO0 → GND (for programming mode, disconnect after upload)
// 5V → 5V (use external 5V supply, NOT FTDI 3.3V)
// PIR Trigger (optional)
// PIR OUT → GPIO13 (available pin on ESP32-CAM)
Mount the ESP32-CAM at approximately 1-1.5 metres height, angled downward at 15-20 degrees towards the vehicle approach area. This angle provides the best view of Indian front number plates. Use an IR illuminator array for night operation.
Image Capture and Preprocessing
// Arduino code for ESP32-CAM capture and upload
#include "esp_camera.h"
#include <WiFi.h>
#include <HTTPClient.h>
// AI-Thinker camera model pin definitions
#define PWDN_GPIO_NUM 32
#define RESET_GPIO_NUM -1
#define XCLK_GPIO_NUM 0
#define SIOD_GPIO_NUM 26
#define SIOC_GPIO_NUM 27
#define Y9_GPIO_NUM 35
#define Y8_GPIO_NUM 34
#define Y7_GPIO_NUM 39
#define Y6_GPIO_NUM 36
#define Y5_GPIO_NUM 21
#define Y4_GPIO_NUM 19
#define Y3_GPIO_NUM 18
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 25
#define HREF_GPIO_NUM 23
#define PCLK_GPIO_NUM 22
void captureAndSend() {
camera_fb_t *fb = esp_camera_fb_get();
if (!fb) return;
HTTPClient http;
http.begin("http://192.168.1.100:5000/upload");
http.addHeader("Content-Type", "image/jpeg");
int code = http.POST(fb->buf, fb->len);
String response = http.getString();
Serial.println("Response: " + response);
http.end();
esp_camera_fb_return(fb);
}
OCR Processing for Indian Plates
Indian number plates follow the format: XX-00-XX-0000 (e.g., MH-12-AB-1234). The server-side Python script uses OpenCV for plate detection and Tesseract for OCR:
import cv2
import pytesseract
import re
def process_plate(image_path):
img = cv2.imread(image_path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Bilateral filter preserves edges while removing noise
filtered = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(filtered, 30, 200)
# Find contours and look for rectangular shapes
contours, _ = cv2.findContours(edged.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
plate_contour = None
for c in contours:
peri = cv2.arcLength(c, True)
approx = cv2.approxPolyDP(c, 0.018 * peri, True)
if len(approx) == 4:
plate_contour = approx
break
if plate_contour is not None:
mask = np.zeros(gray.shape, np.uint8)
cv2.drawContours(mask, [plate_contour], 0, 255, -1)
plate = cv2.bitwise_and(img, img, mask=mask)
text = pytesseract.image_to_string(plate, config='--psm 8')
# Validate Indian plate format
pattern = r'[A-Z]{2}s?d{1,2}s?[A-Z]{1,3}s?d{1,4}'
match = re.search(pattern, text.upper())
if match:
return match.group().replace(' ', '')
return None
Parking Management Integration
Store plate readings in a SQLite database with entry and exit timestamps. Calculate parking duration and fees automatically. For housing societies, maintain a whitelist of resident vehicles for automatic gate opening. Unknown plates trigger an intercom call to the resident being visited.
Frequently Asked Questions
How accurate is ESP32-CAM based ANPR?
Under controlled conditions (proper lighting, vehicle speed below 20 km/h, clean plates), accuracy is 70-85%. Commercial systems achieve 95%+ because they use higher-resolution cameras, IR illumination, and trained deep learning models. The ESP32-CAM system is suitable for parking and society gates, not highway-speed applications.
Does it work at night?
The ESP32-CAM has a built-in LED flash, but it is too weak for reliable plate capture beyond 2 metres. Add an external 850nm IR LED array (invisible to human eyes) with a matching IR-pass filter on the camera for 24/7 operation.
Can it read High Security Registration Plates (HSRP)?
Yes. India’s new HSRP plates use a standardised font (Charles Wright) and reflective background that actually improves OCR accuracy. The IND hologram and Ashoka Chakra do not interfere with text recognition.
What about two-line plates (commercial vehicles)?
Indian commercial vehicles often have two-line plates with the state code on the first line and numbers on the second. Adjust the Tesseract PSM (page segmentation mode) to handle multi-line text (–psm 6 or –psm 4).
Conclusion
Building an ANPR system with ESP32-CAM is a practical and educational project that addresses a real need in Indian housing societies, parking lots, and commercial premises. While not as accurate as commercial systems, the sub-₹2,000 cost makes it accessible for DIY implementation and prototyping. Explore ESP32-CAM modules and accessories at Zbotic to start your ANPR project.
Add comment