This article was contributed to the Roboflow blog by Abirami Vina.
What if traffic flowed smoothly, parking was a breeze, and tracking a car thief was as easy as snapping a photo? That’s the reality of automatic number plate recognition, also known as ANPR. We can use cameras and computer vision to capture and read vehicle license plate numbers automatically. Initially developed for law enforcement, ANPR has found its way into many areas like traffic control, security, and business. It is becoming increasingly common as ANPR cameras are seen on highways, city streets, and private property.
This article walks through ANPR in detail. We will look at how it works and where it can be used. We will also guide you step by step through how to build an ANPR system using Roboflow and discuss what the future might hold for this technology. Let’s dive right in!
How Does ANPR Work?
The Police Scientific Development Branch (PSDB) in the UK invented ANPR in 1976. Since then, technology has improved vastly. Advances in computer vision, machine learning, and OCR have made ANPR more accurate and efficient than ever before. It is used worldwide for traffic management, law enforcement, and surveillance.
Here’s how it works.
ANPR systems have three main parts: cameras, software, and databases. Cameras are placed in key locations like roads, parking lots, and entry points to take high-quality images or videos of license plates. These images are then cleaned up, and any noise is removed.
Object detection is used to locate the number plate in the image. Then, OCR can be used to read the image and convert the characters on the plate into text. The detected text can be compared with a database to check for data like stolen vehicles, registration status, or parking access.
Where are ANPR systems used?
ANPR systems can be used in various areas, such as law enforcement, traffic management, commercial applications, and smart city projects. Let’s take a closer look at where they are being used.
Law Enforcement and Security
ANPR can help law enforcement track vehicle movement. By tracking vehicle movement, police can seamlessly conduct investigations and gather evidence. ANPR systems can also provide information to check license plates against hotlists of vehicles linked to suspects. Another good example is using ANPR systems at borders to monitor vehicles, increase security, and prevent illegal activities. Aside from real-time applications, data collected using ANPR can provide insights to identify patterns and trends in criminal activities.
Traffic Management and Optimization
ANPR makes it possible to automate toll collection and parking management tasks. It optimizes toll traffic by using ANPR data to manage real-time traffic signals, reducing stop-and-go traffic and making traffic flow smoother. Roads with ANPR can also adjust lane use based on traffic volume, reducing congestion and making better use of road space. ANPR can monitor available spaces and detect parking violations in parking lots and garages, making parking management and enforcement more effective.
ANPR in Fleet Management
Businesses are relying on ANPR to make their operations more efficient and secure. This is especially true when it comes to supply chains. In fleet management, ANPR can be used to track vehicles and plan routes to save money and make deliveries faster. It can also used for access control. ANPR only allows authorized vehicles into restricted areas. For example, when a vehicle makes a delivery to a warehouse, it will only be allowed in if it’s an authorized vehicle for security purposes.
Build an ANPR System with Roboflow
Now that we’ve learned about ANPR and its applications, let’s build our own ANPR system with Roboflow. Roboflow is a powerful platform for computer vision projects. It provides tools for managing datasets, annotating images, and training models. With its user-friendly interface and APIs, Roboflow makes it easier to build and deploy machine learning models.
We’ll train an object detection model to detect a license plate and then use OCR to read the license plate number. Let’s dive into how you can build and deploy an ANPR System using Roboflow.
Step 1: Preparing a Dataset
First, we need to gather relevant data: images of vehicle license plates. An object detection model’s performance depends on the quality and variety of the data it is trained on, so it’s essential to collect high-quality data.
Roboflow offers tools like Roboflow Collect and Roboflow Universe to help with this step. Roboflow Collect automates data collection using a webcam, while Roboflow Universe provides access to an extensive repository of over 200,000 computer vision datasets. We will use the "License Plate Recognition Computer Vision Project" dataset from the Roboflow Universe for this tutorial. This dataset contains over 10,000 annotated images of license plates, making it perfect for training a license plate detection model.
To get this dataset, you can visit the project page on Roboflow Universe, click "Download this Dataset," and select the checkbox to download the dataset as a ZIP file. Extract the contents of this file for the following steps.
Upload Data to Roboflow
Once the dataset is ready, the next step is to upload it to Roboflow. Create a Roboflow account, and click "Create New Project" on your dashboard.
You can drag and drop all the images and corresponding annotations into the project. Since our chosen dataset already includes annotations, we can skip the annotation step. However, if your dataset lacks annotations, follow the instructions below to annotate your data.
Annotate Data with Roboflow
Roboflow Annotate provides an easy-to-use web interface for annotating images. Navigate to the "Annotate" section in your project's sidebar on the Roboflow dashboard, then select an image to start annotating.
To annotate an image, use the bounding box tool located in the right sidebar. Draw boxes around each license plate and assign the appropriate class to each annotation. Press the Enter key to save the annotations.
An exciting feature that is part of the annotation tool is the Smart Polygon feature. It can simplify the annotation process by making polygon-based annotations more straightforward. You can activate Smart Polygon by clicking the magic wand icon in the right sidebar and following the instructions. This feature intelligently suggests annotations, saving you lots of time and effort. For detailed guidance on using Smart Polygon, refer to the Roboflow Annotate documentation.
Create a Dataset Version
After annotating your images, the next step is to create a dataset version. To do that, click "Generate" in the Roboflow sidebar. For the initial version, avoid setting pre-processing or augmentation steps to assess the performance of your annotated data accurately. Click the "Generate" button to create the dataset version.
Depending on the dataset size, generating the version may take a few minutes. Once it is generated, you can train your license plate detection model!
Step 2: Train Your ANPR Model
Thanks to Roboflow Train, training computer vision models with Roboflow is straightforward. After creating your dataset version, you can click on "Train a Model" to initiate the training process.
You will be prompted to select a training option. Choose the "Fast" training option to proceed. In the subsequent pop-up window, select the "Train from Public Checkpoint" option and ensure "MS COCO" is chosen as the checkpoint. Training from the MS COCO checkpoint is a good option for the initial version of your model because of its comprehensive pre-trained features.
Follow the on-screen instructions to complete the setup. Roboflow will then allocate a cloud-hosted computer to handle the model training. The training duration will depend on the number of images in your dataset. During training, a graph will dynamically update and show you the model's performance metrics at each training step.
Once the training is complete, you will receive an email notification letting you know that your model is ready for use.
Step 3: Deploy Your Model
We can now deploy your trained object detection model to detect license plates and use the Roboflow OCR endpoint to recognize the characters on the plates. You can build a comprehensive system for ANPR by integrating these two powerful components.
Roboflow allows deployment on the cloud, locally, or on edge devices. We’ll explore how to deploy using Roboflow Inference. Roboflow Inference is a cloud-hosted service that allows you to deploy, run, and scale your machine-learning models for real-time inference.
First, ensure you have the Roboflow Inference SDK installed.
pip install inference_sdk
Next, import the necessary libraries:
from PIL import Image
from inference_sdk import InferenceHTTPClient
Replace “YOUR_API_KEY_HERE” with your actual Roboflow API key and initialize the inference clients:
API_KEY = "YOUR_API_KEY_HERE"
INFER_CLIENT = InferenceHTTPClient(
api_url="https://infer.roboflow.com",
api_key=API_KEY
)
DETECT_CLIENT = InferenceHTTPClient(
api_url="https://detect.roboflow.com",
api_key=API_KEY
)
Load the image you want to run an inference on:
image = Image.open("path/to/your/image.jpg")
Use the detection client to detect license plates in the image. Replace “your_model_id” with your trained model's ID:
bounding_boxes = DETECT_CLIENT.infer("path/to/your/image.jpg", model_id="your_model_id")
Iterate through each detected bounding box, crop the image to the region containing the license plate, and then perform OCR to extract the license plate number. Finally, print the OCR results, showing the recognized license plate information.
for prediction in bounding_boxes["predictions"]:
cx, cy, width, height = prediction["x"], prediction["y"], prediction["width"], prediction["height"]
x0 = cx - (width / 2)
x1 = cx + (width / 2)
y0 = cy - (height / 2)
y1 = cy + (height / 2)
# Crop the image to the bounding box region
cropped_image = image.crop((x0, y0, x1, y1))
# Perform OCR on the cropped image
result = INFER_CLIENT.ocr_image(inference_input=cropped_image)
# Print the OCR results
print(result)
Here is a sample input image:
And this is the corresponding output:
{'result': 'MH 13 AZ 9456', 'time': 1.0524576239999988, 'parent_id': None}
Challenges and Limitations
When building ANPR systems, there are a few challenges and limitations to be aware of. Technically, ANPR systems can struggle to read license plates accurately in conditions like low lighting, dirt, or bad weather. Yes, high-definition cameras can solve most of these problems, but there are unavoidable situations where capturing clear images won’t be possible. A fallback may be required for your application. For example, a toll gate may include a lane that manually reads license plates and collects payments.
There are also legal and ethical concerns about the widespread use of ANPR. For example, balancing security needs with privacy rights can be challenging. Adhering to rules and regulations is essential.
Conclusion
Automatic Number Plate Recognition (ANPR) systems are transforming how we manage traffic, strengthen security, and optimize various commercial applications. In the past, law enforcement mainly used ANPR, but it is now common in many areas like traffic control and fleet management.
Building an ANPR system involves capturing and processing images of license plates, using object detection to locate them, and applying OCR to read the characters.
With platforms like Roboflow, creating and deploying an ANPR model has become more accessible. As ANPR systems continue to improve, it’s likely that we will see more fascinating applications across different industries.
Cite this Post
Use the following entry to cite this post in your research:
Contributing Writer. (Jun 14, 2024). How To Train and Deploy an ANPR System. Roboflow Blog: https://blog.roboflow.com/anpr-system/
Discuss this Post
If you have any questions about this blog post, start a discussion on the Roboflow Forum.