How anuragaryanyt/number_plate_detection works
Project type and purpose
• This is a full-stack, monolithic web application whose purpose is real-time number-plate detection and recognition. It combines a video-processing pipeline (OpenCV + Tesseract OCR) with a Flask-based backend, a MongoDB database, and a small frontend (HTML/CSS templates).
File structure
Top-level:
• myapp.py – the Flask application entry point, holds routes, video-processing thread, and system logic.
• requirements.txt – lists Python dependencies.
• static/ – CSS assets (login, record and result page styles).
• templates/ – Jinja2 HTML templates (login, index/dashboard, recognized_plates, records).
• README.md – project overview, architecture, workflow, and code details.
README for additional insights
• Core libraries: OpenCV (cascade detection), pytesseract, Flask, PyMongo.
• Workflow: load vehicle DB, spin up a video-capture loop (process_video), detect plates, OCR, lookup/insert in MongoDB, annotate and stream frames.
• Flask routes: /login, /index (dashboard—last 24h), /records (all vehicles), /recognized_plates (current session list), /video_feed (multipart JPEG stream), /add_vehicle (POST).
• Authentication: basic session-based admin credentials.
• Concurrent design: video processing runs in a separate thread within the same Flask app context.
Main components & interactions (
A. Camera / Video Source
B. Video-Processing Service
• OpenCV CascadeClassifier (haarcascade_russian_plate_number.xml)
• Image pre-processing (grayscale, ROI extraction, contour tracing)
• Tesseract OCR engine (external executable)
• Plate detection & recognition logic
C. Flask Backend
• REST / HTML endpoints (routes)
• Video feed generator (multipart streaming)
• Session/auth module
• Vehicle management module (add_vehicle)
• Dashboard module (/index, /records, /recognized_plates)
D. Database
• MongoDB Atlas (vehicles and history collections)
E. Web Frontend
• Browser client
• HTML templates + CSS (static assets)
• JavaScript (if any for video display)
F. Admin User
• Interacts via browser (login, add vehicle, view data)
Data flows & relationships
1. Browser → Flask (HTTP GET/POST for login, pages, add_vehicle)
2. Flask → MongoDB (queries: load all vehicles into in-memory dict; writes: new vehicle, history insert)
3. Camera → Video-Processing thread → Flask (stream frames to /video_feed)
4. Video Processing → MongoDB (history inserts), → in-memory dict (lookup)
5. Flask → Browser (streamed MJPEG, rendered templates populated with DB query results)
Architectural patterns & design principles
• Single-process, multi-threaded monolith
• MVC-like division:
• Model = MongoDB collections + in-memory vehicle_database
• View = Jinja2 templates + video stream
• Controller = Flask routes + process_video function
• Separation of concerns:
• Video/vision logic isolated in process_video()
• HTTP logic in Flask routes
• DB logic centralized in load_vehicle_database() and route handlers
• Real-time streaming via generator pattern and multipart responses
Final checklist
• Clear component labels (Camera, Video Processor, Flask App, MongoDB, Browser Admin)
• External dependencies (Tesseract executable path, Haar cascade file)