How to Read License Plates using IronOCR
When managing a large volume of vehicle images, manually reading license plates is time-consuming and prone to human error. Automating this process with a tool like IronOCR provides a more efficient, accurate solution. IronOCR's ReadLicensePlate
method can programmatically extract license plate numbers from images, saving considerable time while improving data accuracy.
In this guide, we’ll demonstrate how to use IronOCR for license plate recognition, walking through examples and customizable configurations that make the process seamless. By leveraging these methods, developers can automate license plate reading, making tasks like parking management, toll collection, or security surveillance more efficient.
How to Read License Plates using IronOCR
- Download the C# library for reading license plates
- Import the license plate image for processing
- Ensure the document contains only the license plate image, without headers or footers
- Use the
ReadLicensePlate
method to extract data from the image - Access the OcrLicensePlateResult property to view and manipulate the extracted license data
Start using IronOCR in your project today with a free trial.
To use this function, you must also install the IronOcr.Extension.AdvancedScan package.
Read License Plate Example
To read a license plate in IronOCR, we have to apply the following steps:
- We utilize the
ReadLicensePlate
method, which takes anOcrInpput
as a parameter for the input. This method is more optimized for license plates precisely than the library's standardRead
counterpart. - Optional : We can configure IronOCR to whitelist the specific characters only that can exist in a license plate, to speed up the license plate number processing.
Please note
- The method currently only works for English, Chinese, Japanese, Korean, and LatinAlphabet.
- Using advanced scan on .NET Framework requires the project to run on x64 architecture.
License Plate
Code
:path=/static-assets/ocr/content-code-examples/how-to/read-license-plate-read-license-plate.cs
using IronOcr;
using System;
var ocr = new IronTesseract();
ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("plate.jpeg");
// Read license plate
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate number and confidence value
string output = $"{result.Text}\nResult Confidence: {result.Confidence}";
Console.WriteLine(output);
Imports Microsoft.VisualBasic
Imports IronOcr
Imports System
Private ocr = New IronTesseract()
ocr.Configuration.WhiteListCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
Dim inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("plate.jpeg")
' Read license plate
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate number and confidence value
Dim output As String = $"{result.Text}" & vbLf & "Result Confidence: {result.Confidence}"
Console.WriteLine(output)
Output
Note that we must first import the image as an OcrInput
to pass the parameter on the ReadLicensePlate
method correctly.
As you can see from the console output, the extracted text matches the license plate and state shown in the input image.
Text: The extraced Text from OCR Input.
Confidence: A "double" property that indicates the statistical accuracy confidence of an average of every character, with one being the highest and 0 being the lowest.
License Plate From a Car Image
The method also works well with single images that contain a car with a license plate. The code is the exact same as the one above, with the input image changed. You can also extract the pixel co-ordinates of the area where the license plate is situated in the image.
Example Input:
:path=/static-assets/ocr/content-code-examples/how-to/read-license-plate-read-from-car.cs
using IronOcr;
using IronSoftware.Drawing;
using System;
var ocr = new IronTesseract();
using var inputLicensePlate = new OcrInput();
inputLicensePlate.LoadImage("car_license.jpg");
// Read license plate
OcrLicensePlateResult result = ocr.ReadLicensePlate(inputLicensePlate);
// Retrieve license plate coordinates
RectangleF rectangle = result.Licenseplate;
// Write license plate value and coordinates in a string
string output = $"License Plate Number:\n{result.Text}\n\n"
+ $"License Plate Area_\n"
+ $"Starting X: {rectangle.X}\n"
+ $"Starting Y: {rectangle.Y}\n"
+ $"Width: {rectangle.Width}\n"
+ $"Height: {rectangle.Height}";
Console.WriteLine(output);
Imports Microsoft.VisualBasic
Imports IronOcr
Imports IronSoftware.Drawing
Imports System
Private ocr = New IronTesseract()
Private inputLicensePlate = New OcrInput()
inputLicensePlate.LoadImage("car_license.jpg")
' Read license plate
Dim result As OcrLicensePlateResult = ocr.ReadLicensePlate(inputLicensePlate)
' Retrieve license plate coordinates
Dim rectangle As RectangleF = result.Licenseplate
' Write license plate value and coordinates in a string
Dim output As String = $"License Plate Number:" & vbLf & "{result.Text}" & vbLf & vbLf & $"License Plate Area_" & vbLf & $"Starting X: {rectangle.X}" & vbLf & $"Starting Y: {rectangle.Y}" & vbLf & $"Width: {rectangle.Width}" & vbLf & $"Height: {rectangle.Height}"
Console.WriteLine(output)
Output
As you can see, the output matches the license plate shown above and the exact rectangular area of the license plate in the image is also extracted correctly.
This method is optimized to find single license plates only and is capable of searching for them in stock images.