Below is a high-level overview of how our Automated Number Plate Recognition (ANPR) system operates. We use a FastAPI server to process videos, detect and validate license plates, optionally extract metadata from an LLM, and return the final results (annotated images, performance metrics, etc.) back to the client.
-
Client
- Uploads a video (e.g.,
video.mp4) through the frontend (HTML page) or via a direct API call (cURL, Postman, etc.). - Receives the final detection results, including:
- Valid/invalid plates
- Annotated frames (if any)
- Optional metadata from the LLM
- Performance metrics (latency, detection confidence, etc.)
- Uploads a video (e.g.,
-
FastAPI Server
- Exposes an
/uploadendpoint that accepts the video file (and parameters likeframe_interval). - Coordinates the entire ANPR pipeline:
- Reads the video and splits it into frames at the specified interval.
- Passes each frame to the ANPR model for plate detection and OCR-based recognition.
- Validates recognized plates against regex and Indian state codes.
- Annotates frames for new valid plate detections and saves them.
- (Optionally) sends detected images to an LLM to obtain metadata.
- Aggregates and returns JSON output with the final results.
- Exposes an
-
ANPR Model
- Receives frames from the server for plate detection (using YOLOv8 or a similar object detection backbone).
- Uses OCR (via PaddleOCR or equivalent) to recognize the text in the detected bounding box.
- Returns detection coordinates, detection confidence, recognized text, and recognition confidence.
-
LLM (Optional)
- Can receive annotated images from the server.
- Attempts to extract additional metadata, such as:
- Car color
- Car type (sedan, hatchback, SUV, etc.)
- Number plate type (private, taxi, commercial)
- Any other relevant textual description
- Sends this metadata back to the server, which merges it into the final JSON response.
-
Upload & Extraction
- The client uploads a video (MP4 or another supported format).
- The server stores it temporarily and reads frames at every nᵗʰ interval (
frame_interval).
-
Conversion & Detection
- Each selected frame is converted from BGR to RGB.
- Sent to FastANPR for:
- Detection: Locating the plate’s bounding box.
- OCR Recognition: Extracting the plate text.
-
Validation & Annotation
- The recognized plate text is validated with:
- A regex check (e.g.,
^[A-Z]{2}[0-9]{2}[A-Z]{1,2}[0-9]{4}$). - A state code check for the first two letters (e.g.,
KA,DL, etc.).
- A regex check (e.g.,
- Only newly detected valid plates are annotated on the frame with bounding boxes and text overlays.
- Annotated frames are saved in the
resultsfolder.
- The recognized plate text is validated with:
-
Metadata Extraction (Optional)
- Each annotated frame can be passed to an LLM for additional insights.
- If it fails or is turned off, the process continues without the metadata.
-
Response Construction
- The server collects:
- Valid plate texts
- Invalid plate texts
- Annotated image URLs
- Optional LLM metadata
- Performance metrics (latency, detection/recognition confidence)
- Returns this data as JSON for the client to render.
- The server collects:
-
Regex Validation
- Ensures the plate format follows common Indian license plate conventions (e.g., two letters, two digits, one or two letters, four digits).
-
State Code Validation
- Checks if the first two letters belong to a valid Indian state/territory code (e.g.,
KAfor Karnataka,DLfor Delhi).
- Checks if the first two letters belong to a valid Indian state/territory code (e.g.,
Plates failing either check are considered invalid and stored in a separate array.
-
Detection
- Built on a YOLOv8 backbone through fastanpr. Locates the plate region in the image.
-
Recognition
- An OCR module (PaddleOCR or equivalent) extracts the plate text with a confidence score.
-
(Optional) LLM Metadata
- The system can send the cropped/annotated image to an LLM (GPT-like model) to infer additional details about the car.
- If the LLM call fails, the pipeline continues without metadata.
For every processed frame that results in new valid plates:
- Latency: Time taken to run the detection and recognition for that frame.
- Detection Confidence: Score from the object detection (YOLOv8).
- Recognition Confidence: Score from the OCR text recognition.
These metrics are captured per frame (and per plate) and returned as part of the JSON response.
Below is a sample cURL command to upload a video to the /upload endpoint, specifying a frame interval of 30:
curl -X POST "http://127.0.0.1:8000/upload" \
-F "file=@/path/to/your/video.mp4" \
-F "frame_interval=30"uvicorn main:app --reload